|
@@ -0,0 +1,108 @@
|
|
|
+package com.boman.web.core.utils;
|
|
|
+
|
|
|
+import com.aliyuncs.DefaultAcsClient;
|
|
|
+import com.aliyuncs.IAcsClient;
|
|
|
+import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest;
|
|
|
+import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
|
|
|
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
|
|
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
|
|
+import com.aliyuncs.exceptions.ClientException;
|
|
|
+import com.aliyuncs.profile.DefaultProfile;
|
|
|
+import com.aliyuncs.profile.IClientProfile;
|
|
|
+import com.boman.common.core.utils.DateUtils;
|
|
|
+
|
|
|
+
|
|
|
+ * @author tjf
|
|
|
+ * @Date: 2021/07/15/10:21
|
|
|
+ */
|
|
|
+public class SendSmsUtils {
|
|
|
+
|
|
|
+ * 产品名称:云通信短信API产品,开发者无需替换
|
|
|
+ */
|
|
|
+ static final String PRODUCT = "Dysmsapi";
|
|
|
+
|
|
|
+ * 产品域名,开发者无需替换
|
|
|
+ */
|
|
|
+ static final String DOMAIN = "dysmsapi.aliyuncs.com";
|
|
|
+
|
|
|
+
|
|
|
+ * TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
|
|
|
+ */
|
|
|
+ static final String ACCESS_KEY_ID = "LTAI5tNA2fcBJH6EWRH6Pxr6";
|
|
|
+ static final String ACCESS_KEY_SECRET = "5WdaPEOvC3u9LC7pwy2DQ9pgmJvgUr";
|
|
|
+
|
|
|
+
|
|
|
+ * 发送短信接口
|
|
|
+ * @param phone
|
|
|
+ * @return
|
|
|
+ * @throws ClientException
|
|
|
+ */
|
|
|
+ public static SendSmsResponse sendSms(String phone,String nikeName,String accessKeyId,String accessKeySecret,String signName,String templateCode ) throws ClientException {
|
|
|
+
|
|
|
+ System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
|
|
|
+ System.setProperty("sun.net.client.defaultReadTimeout", "10000");
|
|
|
+
|
|
|
+
|
|
|
+ IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
|
|
|
+ DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", PRODUCT, DOMAIN);
|
|
|
+ IAcsClient acsClient = new DefaultAcsClient(profile);
|
|
|
+
|
|
|
+
|
|
|
+ SendSmsRequest request = new SendSmsRequest();
|
|
|
+
|
|
|
+ request.setPhoneNumbers(phone);
|
|
|
+
|
|
|
+ request.setSignName(signName);
|
|
|
+
|
|
|
+ request.setTemplateCode(templateCode);
|
|
|
+
|
|
|
+ request.setTemplateParam("{\"name\":\"" + nikeName + "\"}");
|
|
|
+
|
|
|
+ request.setOutId("jiaoyuju");
|
|
|
+
|
|
|
+ return acsClient.getAcsResponse(request);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 短信查验接口
|
|
|
+ * @param bizId
|
|
|
+ * @param phone
|
|
|
+ * @return
|
|
|
+ * @throws ClientException
|
|
|
+ */
|
|
|
+ public static QuerySendDetailsResponse querySendDetails(String bizId, String phone) throws ClientException {
|
|
|
+
|
|
|
+
|
|
|
+ System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
|
|
|
+ System.setProperty("sun.net.client.defaultReadTimeout", "10000");
|
|
|
+
|
|
|
+
|
|
|
+ IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
|
|
+ DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", PRODUCT, DOMAIN);
|
|
|
+ IAcsClient acsClient = new DefaultAcsClient(profile);
|
|
|
+
|
|
|
+
|
|
|
+ QuerySendDetailsRequest request = new QuerySendDetailsRequest();
|
|
|
+
|
|
|
+ request.setPhoneNumber(phone);
|
|
|
+
|
|
|
+ request.setBizId(bizId);
|
|
|
+
|
|
|
+ request.setSendDate(DateUtils.getDateNow());
|
|
|
+
|
|
|
+ request.setPageSize(10L);
|
|
|
+
|
|
|
+ request.setCurrentPage(1L);
|
|
|
+
|
|
|
+
|
|
|
+ QuerySendDetailsResponse querySendDetailsResponse = null;
|
|
|
+ try {
|
|
|
+ querySendDetailsResponse = acsClient.getAcsResponse(request);
|
|
|
+ } catch (ClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return querySendDetailsResponse;
|
|
|
+ }
|
|
|
+}
|