截止9.14开发
This commit is contained in:
@@ -2,8 +2,14 @@ package com.ruoyi.common.utils;
|
||||
|
||||
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.cvm.v20170312.CvmClient;
|
||||
import com.tencentcloudapi.cvm.v20170312.models.DescribeRegionsRequest;
|
||||
import com.tencentcloudapi.cvm.v20170312.models.DescribeRegionsResponse;
|
||||
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.var;
|
||||
@@ -12,21 +18,26 @@ import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class SmsUtils {
|
||||
private static final String SDK_APP_ID = "应用id";
|
||||
private static final String SECRET_ID = "API的SecretId";
|
||||
private static final String SECRET_KEY = "API的SecretKey";
|
||||
private static final String SIGN_NAME = "签名内容";
|
||||
//应用id
|
||||
private static final String SDK_APP_ID = "1400854852";
|
||||
//API的SecretId
|
||||
private static final String SECRET_ID = "AKIDeEf2A8uX1HSainvvnXAc3X9ZlhtyvkMp";
|
||||
//API的SecretKey
|
||||
private static final String SECRET_KEY = "QjphKo8zkHZigT8j9PVtFPJyfIvO3d6V";
|
||||
//签名内容
|
||||
private static final String SIGN_NAME = "西安云美电子科技有限公司";
|
||||
|
||||
public static Boolean sendSms(SendSmsRequest request) {
|
||||
Credential cred = new Credential(SECRET_ID,SECRET_KEY);
|
||||
Credential cred = new Credential(SECRET_ID, SECRET_KEY );
|
||||
|
||||
SmsClient client = new SmsClient(cred, "ap-guangzhou");
|
||||
|
||||
final var req = new com.tencentcloudapi.sms.v20210111.models.SendSmsRequest();
|
||||
req.setPhoneNumberSet(new String[]{"+86" + request.getPhone()});
|
||||
req.setSmsSdkAppId(SDK_APP_ID);
|
||||
req.setSmsSdkAppId(SDK_APP_ID );
|
||||
req.setSignName(SIGN_NAME);
|
||||
req.setTemplateId(request.getTemplateId());
|
||||
req.setTemplateParamSet(request.getTemplateParamSet());
|
||||
|
||||
SendSmsResponse res = null;
|
||||
try {
|
||||
res = client.SendSms(req);
|
||||
@@ -34,14 +45,14 @@ public class SmsUtils {
|
||||
log.error("发送短信出错:", e);
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
log.error("发送短信结果:", SendSmsResponse.toJsonString(res));
|
||||
SendStatus sendStatus = res.getSendStatusSet()[0];
|
||||
log.info("发送短信结果:Code={}, Message={}", sendStatus.getCode(), sendStatus.getMessage());
|
||||
|
||||
if (Objects.nonNull(res.getSendStatusSet()) && res.getSendStatusSet().length > 0 && "Ok".equals(res.getSendStatusSet()[0].getCode())){
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数对象
|
||||
*/
|
||||
@@ -63,4 +74,12 @@ public class SmsUtils {
|
||||
private String[] templateParamSet;
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest();
|
||||
sendSmsRequest.setPhone("15029925289");
|
||||
sendSmsRequest.setTemplateId("1927509");
|
||||
sendSmsRequest.setTemplateParamSet(new String[]{"用户"});
|
||||
SmsUtils.sendSms(sendSmsRequest);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user