Commit a8abcac7 by liyanlin

腾讯云短信配置

parent 5b21ca59
package com.gogirl.application.common;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gogirl.domain.common.SmsConfig;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in 2021-05-13
* @Modified by:
*/
public interface ISmsConfigService extends IService<SmsConfig> {
}
package com.gogirl.application.common.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gogirl.application.common.IAgentUserLogService;
import com.gogirl.application.common.ISmsConfigService;
import com.gogirl.domain.common.AgentUserLog;
import com.gogirl.domain.common.SmsConfig;
import com.gogirl.infrastructure.mapper.common.AgentUserLogMapper;
import com.gogirl.infrastructure.mapper.common.SmsConfigMapper;
import org.springframework.stereotype.Service;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in 2021-05-13
* @Modified by:
*/
@Service
public class SmsConfigServiceImpl extends ServiceImpl<SmsConfigMapper, SmsConfig> implements ISmsConfigService {
}
...@@ -45,7 +45,7 @@ public interface GogirlTokenService { ...@@ -45,7 +45,7 @@ public interface GogirlTokenService {
* @param phone * @param phone
* @return * @return
*/ */
String getBindCode(String phone); String getBindCode(String phone,Integer brandId);
/** /**
* 小程序用户根据验证码绑定手机号码和称呼 * 小程序用户根据验证码绑定手机号码和称呼
......
...@@ -58,13 +58,13 @@ public class GogirlTokenServiceImpl implements GogirlTokenService { ...@@ -58,13 +58,13 @@ public class GogirlTokenServiceImpl implements GogirlTokenService {
} }
@Override @Override
public String getBindCode(String phone) { public String getBindCode(String phone, Integer brandId) {
if (!StringUtils.isPhone(phone)) { if (!StringUtils.isPhone(phone)) {
throw new RRException("用户号码格式不正确"); throw new RRException("用户号码格式不正确");
} }
String code = getNewCode(); String code = getNewCode();
SmsSingleSenderResult result = smsService.sendBindSmsCode(phone, code); SmsSingleSenderResult result = smsService.sendBindSmsCode(phone, code, brandId);
if (result == null) { if (result == null) {
throw new RRException("验证码发送失败,请重试"); throw new RRException("验证码发送失败,请重试");
......
package com.gogirl.domain.common;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in 2021-05-13
* @Modified by:
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="腾讯云短信配置", description="")
public class SmsConfig {
// 短信应用SDK AppID
@ApiModelProperty(value = "短信应用SDK AppID")
private Integer appId;
// 短信应用SDK AppKey
@ApiModelProperty(value = "短信应用SDK AppKey")
private String appKey;
// 短信模板ID,需要在短信应用中申请
@ApiModelProperty(value = "短信模板ID,需要在短信应用中申请")
private Integer bindTemplateId;
// 腾讯云短信签名
@ApiModelProperty(value = "腾讯云短信签名")
private String smsSign;
//验证码有效时间
@ApiModelProperty(value = "验证码有效时间")
private String activeTime;
@ApiModelProperty(value = "品牌id")
private Integer brandId;
private LocalDateTime createTime;
private LocalDateTime lastUpdateTime;
}
package com.gogirl.infrastructure.mapper.common;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gogirl.domain.common.SmsConfig;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in 2021-05-13
* @Modified by:
*/
public interface SmsConfigMapper extends BaseMapper<SmsConfig> {
}
...@@ -11,7 +11,7 @@ public interface SmsService { ...@@ -11,7 +11,7 @@ public interface SmsService {
* @param code * @param code
* @return * @return
*/ */
SmsSingleSenderResult sendBindSmsCode(String phoneNumber, String code); SmsSingleSenderResult sendBindSmsCode(String phoneNumber, String code, Integer brandId);
/** /**
* 验证短信 * 验证短信
......
package com.gogirl.infrastructure.service.sms.impl; package com.gogirl.infrastructure.service.sms.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.qcloudsms.SmsSingleSender; import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult; import com.github.qcloudsms.SmsSingleSenderResult;
import com.gogirl.application.common.ISmsConfigService;
import com.gogirl.domain.common.SmsConfig;
import com.gogirl.infrastructure.service.sms.SmsService; import com.gogirl.infrastructure.service.sms.SmsService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.json.JSONException; import org.json.JSONException;
...@@ -21,17 +24,21 @@ public class QCloudSmsServiceImpl implements SmsService { ...@@ -21,17 +24,21 @@ public class QCloudSmsServiceImpl implements SmsService {
@Resource @Resource
StringRedisTemplate stringRedisTemplate; StringRedisTemplate stringRedisTemplate;
@Resource
ISmsConfigService smsConfigService;
@Override @Override
public SmsSingleSenderResult sendBindSmsCode(String phoneNumber, String code) { public SmsSingleSenderResult sendBindSmsCode(String phoneNumber, String code, Integer brandId) {
// //
String smsSign = SmsConstant.smsSign; SmsConfig smsConfig = smsConfigService.getOne(new LambdaQueryWrapper<SmsConfig>().eq(SmsConfig::getBrandId, brandId));
int templateId = SmsConstant.bindTemplateId; String smsSign = smsConfig.getSmsSign();
String[] params = {code, SmsConstant.activeTime}; int templateId = smsConfig.getBindTemplateId();
String[] params = {code, smsConfig.getActiveTime()};
SmsSingleSenderResult result = new SmsSingleSenderResult(); SmsSingleSenderResult result = new SmsSingleSenderResult();
try { try {
SmsSingleSender sender = new SmsSingleSender(SmsConstant.appid, SmsConstant.appkey); SmsSingleSender sender = new SmsSingleSender(smsConfig.getAppId(), smsConfig.getAppKey());
result = sender.sendWithParam("86", phoneNumber, templateId, params, smsSign, "", ""); result = sender.sendWithParam("86", phoneNumber, templateId, params, smsSign, "", "");
stringRedisTemplate.opsForValue().set(phoneNumber, code); stringRedisTemplate.opsForValue().set(phoneNumber, code);
......
...@@ -129,8 +129,8 @@ public class CustomerController { ...@@ -129,8 +129,8 @@ public class CustomerController {
@ApiOperation(value = "获取验证码,用于绑定手机号码") @ApiOperation(value = "获取验证码,用于绑定手机号码")
@PostMapping("/customer/phone/getBindCode") @PostMapping("/customer/phone/getBindCode")
public JsonResult<String> getBindCode(@RequestParam String phone) { public JsonResult<String> getBindCode(@RequestParam String phone,@RequestHeader("brandId") Integer brandId) {
String code = gogirlTokenService.getBindCode(phone); String code = gogirlTokenService.getBindCode(phone, brandId);
return JsonResult.success(code); return JsonResult.success(code);
} }
...@@ -209,8 +209,8 @@ public class CustomerController { ...@@ -209,8 +209,8 @@ public class CustomerController {
@AuthIgnore @AuthIgnore
@ApiOperation(value = "获取验证码,用于绑定手机号码") @ApiOperation(value = "获取验证码,用于绑定手机号码")
@PostMapping("/technician//phone/getBindCode") @PostMapping("/technician//phone/getBindCode")
public JsonResult<String> techGetBindCode(@RequestParam String phone) { public JsonResult<String> techGetBindCode(@RequestParam String phone,@RequestHeader("brandId") Integer brandId) {
String code = gogirlTokenService.getBindCode(phone); String code = gogirlTokenService.getBindCode(phone,brandId);
return JsonResult.success(code); return JsonResult.success(code);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment