This commit is contained in:
sxu 2023-12-08 17:36:36 +08:00
commit f25b863f38
3 changed files with 14 additions and 11 deletions

View File

@ -26,22 +26,22 @@ import org.springframework.stereotype.Component;
@Slf4j @Slf4j
public class SmsComponent { public class SmsComponent {
@Value("${sms.sdkAppId}") // 注入参数值 @Value("${tencent.sms.smsSdkAppId}") // 注入参数值
private String sdkAppId; private String sdkAppId;
@Value("${sms.secretId}") @Value("${tencent.sms.secretId}")
private String secretId; private String secretId;
@Value("${sms.secretKey}") @Value("${tencent.sms.keysecret}")
private String secretKey; private String secretKey;
@Value("${sms.signName}") @Value("${tencent.sms.signName}")
private String signName; private String signName;
@Value("${sms.templateCodeId}") @Value("${tencent.sms.templateId}")
private String templateCodeId; private String templateCodeId;
@Value("${sms.timeout}") @Value("${tencent.sms.timeout}")
private Integer timeout; private Integer timeout;
/** /**
@ -59,7 +59,7 @@ public class SmsComponent {
ClientProfile clientProfile = new ClientProfile(); ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile); clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的 // 实例化要请求产品的client对象,clientProfile是可选的
return new SmsClient(cred, "ap-beijing", clientProfile); return new SmsClient(cred, "ap-nanjing", clientProfile);
} }
/** /**
@ -77,7 +77,7 @@ public class SmsComponent {
req.setPhoneNumberSet(phoneNumberSet); req.setPhoneNumberSet(phoneNumberSet);
req.setSignName(signName); req.setSignName(signName);
req.setTemplateId(templateId); req.setTemplateId(templateId);
//模板内容的参数有几个就设置几个我这里是两个 // 根据模板所需参数量选择
String[] templateParamSetOne = {code}; String[] templateParamSetOne = {code};
String[] templateParamSetTwo = {code,param2}; String[] templateParamSetTwo = {code,param2};
req.setTemplateParamSet(templateParamSetOne); req.setTemplateParamSet(templateParamSetOne);

View File

@ -4,6 +4,7 @@ import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult; import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.system.service.ISmsService; import com.bonus.zlpt.system.service.ISmsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -22,7 +23,7 @@ public class SmsSendController extends BaseController {
@Autowired @Autowired
private ISmsService smsService; private ISmsService smsService;
@RequestMapping("/send") @PostMapping("send")
public AjaxResult send(@RequestParam("phone") String phone){ public AjaxResult send(@RequestParam("phone") String phone){
try { try {
String msg = smsService.sendCode(phone, 5 * 60 * 1000); String msg = smsService.sendCode(phone, 5 * 60 * 1000);

View File

@ -9,11 +9,13 @@ tencent:
secretId: AKIDbF1pTyU6iHn6EH9uc9O6kJgrrfI2rV04 secretId: AKIDbF1pTyU6iHn6EH9uc9O6kJgrrfI2rV04
keysecret: zGPRJ9z68AGZVMAoHYyDFDAxhR2Xs0Qf keysecret: zGPRJ9z68AGZVMAoHYyDFDAxhR2Xs0Qf
# 短信应用ID # 短信应用ID
smsSdkAppId: 564559 smsSdkAppId: 1400874270
# 短信签名内容 # 短信签名内容
signName: 作业智慧管控系统小程序 signName: 作业智慧管控系统小程序
# 正文模板ID # 正文模板ID
templateId: 2010811 templateId: 2014173
# 超时时间
timeout: 1000
sms: sms:
sdkAppId: sdkAppId: