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 {
* @param phone
* @return
*/
String getBindCode(String phone);
String getBindCode(String phone,Integer brandId);
/**
* 小程序用户根据验证码绑定手机号码和称呼
......
......@@ -58,13 +58,13 @@ public class GogirlTokenServiceImpl implements GogirlTokenService {
}
@Override
public String getBindCode(String phone) {
public String getBindCode(String phone, Integer brandId) {
if (!StringUtils.isPhone(phone)) {
throw new RRException("用户号码格式不正确");
}
String code = getNewCode();
SmsSingleSenderResult result = smsService.sendBindSmsCode(phone, code);
SmsSingleSenderResult result = smsService.sendBindSmsCode(phone, code, brandId);
if (result == null) {
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 {
* @param code
* @return
*/
SmsSingleSenderResult sendBindSmsCode(String phoneNumber, String code);
SmsSingleSenderResult sendBindSmsCode(String phoneNumber, String code, Integer brandId);
/**
* 验证短信
......
package com.gogirl.infrastructure.service.sms.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.qcloudsms.SmsSingleSender;
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 lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
......@@ -21,17 +24,21 @@ public class QCloudSmsServiceImpl implements SmsService {
@Resource
StringRedisTemplate stringRedisTemplate;
@Resource
ISmsConfigService smsConfigService;
@Override
public SmsSingleSenderResult sendBindSmsCode(String phoneNumber, String code) {
public SmsSingleSenderResult sendBindSmsCode(String phoneNumber, String code, Integer brandId) {
//
String smsSign = SmsConstant.smsSign;
int templateId = SmsConstant.bindTemplateId;
String[] params = {code, SmsConstant.activeTime};
SmsConfig smsConfig = smsConfigService.getOne(new LambdaQueryWrapper<SmsConfig>().eq(SmsConfig::getBrandId, brandId));
String smsSign = smsConfig.getSmsSign();
int templateId = smsConfig.getBindTemplateId();
String[] params = {code, smsConfig.getActiveTime()};
SmsSingleSenderResult result = new SmsSingleSenderResult();
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, "", "");
stringRedisTemplate.opsForValue().set(phoneNumber, code);
......
......@@ -129,8 +129,8 @@ public class CustomerController {
@ApiOperation(value = "获取验证码,用于绑定手机号码")
@PostMapping("/customer/phone/getBindCode")
public JsonResult<String> getBindCode(@RequestParam String phone) {
String code = gogirlTokenService.getBindCode(phone);
public JsonResult<String> getBindCode(@RequestParam String phone,@RequestHeader("brandId") Integer brandId) {
String code = gogirlTokenService.getBindCode(phone, brandId);
return JsonResult.success(code);
}
......@@ -209,8 +209,8 @@ public class CustomerController {
@AuthIgnore
@ApiOperation(value = "获取验证码,用于绑定手机号码")
@PostMapping("/technician//phone/getBindCode")
public JsonResult<String> techGetBindCode(@RequestParam String phone) {
String code = gogirlTokenService.getBindCode(phone);
public JsonResult<String> techGetBindCode(@RequestParam String phone,@RequestHeader("brandId") Integer brandId) {
String code = gogirlTokenService.getBindCode(phone,brandId);
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