Merge branch 'dev' of http://git.xayunmei.com/SH-Arbitrate/Arbitrate-Backend into qtz
This commit is contained in:
@@ -126,6 +126,19 @@
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 腾讯短信sdk -->
|
||||
<dependency>
|
||||
<groupId>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java</artifactId>
|
||||
<version>3.1.270</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java-ocr</artifactId>
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
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;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class SmsUtils {
|
||||
//应用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 );
|
||||
|
||||
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.setSignName(SIGN_NAME);
|
||||
req.setTemplateId(request.getTemplateId());
|
||||
req.setTemplateParamSet(request.getTemplateParamSet());
|
||||
SendSmsResponse res = null;
|
||||
try {
|
||||
res = client.SendSms(req);
|
||||
} catch (TencentCloudSDKException e) {
|
||||
log.error("发送短信出错:", e);
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* 参数对象
|
||||
*/
|
||||
@Data
|
||||
public static class SendSmsRequest {
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 模板 ID: 必须填写已审核通过的模板 ID
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空
|
||||
*/
|
||||
private String[] templateParamSet;
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest();
|
||||
sendSmsRequest.setPhone("18792613219");
|
||||
sendSmsRequest.setTemplateId("1928003");
|
||||
sendSmsRequest.setTemplateParamSet(new String[]{"xxx","仲裁","编号"});
|
||||
SmsUtils.sendSms(sendSmsRequest);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user