19 changed files with 285 additions and 74 deletions
@ -0,0 +1,74 @@ |
|||
package com.qs.serve.modules.base; |
|||
|
|||
import com.tencentcloudapi.common.Credential; |
|||
import com.tencentcloudapi.common.exception.TencentCloudSDKException; |
|||
import com.tencentcloudapi.common.profile.ClientProfile; |
|||
import com.tencentcloudapi.common.profile.HttpProfile; |
|||
import com.tencentcloudapi.sms.v20210111.SmsClient; |
|||
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; |
|||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2022/9/20 |
|||
*/ |
|||
//@Service
|
|||
public class TencentYunSmsService { |
|||
|
|||
@Value("${tencent.sms.secret-id}") |
|||
private String secretId; |
|||
|
|||
@Value("${tencent.sms.secret-key}") |
|||
private String secretKey; |
|||
|
|||
@Value("${tencent.sms.sdkAppId}") |
|||
private String sdkAppId; |
|||
|
|||
@Value("${tencent.sms.signName}") |
|||
private String signName; |
|||
|
|||
@Value("${tencent.sms.templateId}") |
|||
private String templateId; |
|||
|
|||
public void send(String phone,String code) { |
|||
Credential cred = new Credential(secretId, secretKey); |
|||
HttpProfile httpProfile = new HttpProfile(); |
|||
httpProfile.setReqMethod("POST"); |
|||
httpProfile.setConnTimeout(60); |
|||
/* 指定接入地域域名,默认就近地域接入域名为 sms.tencentcloudapi.com ,也支持指定地域域名访问,例如广州地域的域名为 sms.ap-guangzhou.tencentcloudapi.com */ |
|||
httpProfile.setEndpoint("sms.ap-guangzhou.tencentcloudapi.com"); |
|||
|
|||
ClientProfile clientProfile = new ClientProfile(); |
|||
clientProfile.setSignMethod("HmacSHA256"); |
|||
clientProfile.setHttpProfile(httpProfile); |
|||
SmsClient client = new SmsClient(cred, "ap-guangzhou",clientProfile); |
|||
SendSmsRequest req = new SendSmsRequest(); |
|||
|
|||
req.setSmsSdkAppId(sdkAppId); |
|||
|
|||
req.setSignName(signName); |
|||
|
|||
req.setTemplateId(templateId); |
|||
|
|||
//todo 调整短信模板
|
|||
String[] templateParamSet = {code,code,code}; |
|||
req.setTemplateParamSet(templateParamSet); |
|||
|
|||
String[] phoneNumberSet = {"+86"+phone}; |
|||
req.setPhoneNumberSet(phoneNumberSet); |
|||
|
|||
SendSmsResponse res = null; |
|||
try { |
|||
res = client.SendSms(req); |
|||
// 输出json格式的字符串回包
|
|||
System.out.println(SendSmsResponse.toJsonString(res)); |
|||
} catch (TencentCloudSDKException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.qs.serve.modules.wx.entity.dto.sms; |
|||
|
|||
import com.qs.serve.modules.wx.common.model.WxSmsProp; |
|||
import com.qs.serve.modules.wx.entity.dto.SmsBaseDto; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2022/9/21 |
|||
*/ |
|||
@Data |
|||
public class WxSmsNewForm extends SmsBaseDto { |
|||
|
|||
@WxSmsProp(keyword = "first") |
|||
private String title; |
|||
@WxSmsProp(keyword = "keyword1") |
|||
private String param1; |
|||
@WxSmsProp(keyword = "keyword2") |
|||
private String param2; |
|||
@WxSmsProp(keyword = "keyword3") |
|||
private String param3; |
|||
@WxSmsProp(keyword = "keyword4") |
|||
private String param4; |
|||
@WxSmsProp(keyword = "keyword5") |
|||
private String param5; |
|||
@WxSmsProp(keyword = "remark") |
|||
private String remark; |
|||
} |
Loading…
Reference in new issue