|
@@ -0,0 +1,112 @@
|
|
|
+package com.jeeplus.sys.utils;
|
|
|
+
|
|
|
+import com.aliyun.dysmsapi20170525.Client;
|
|
|
+import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
|
|
+import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
|
|
+import com.aliyun.tea.TeaException;
|
|
|
+import com.aliyun.teaopenapi.models.Config;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: 徐滕
|
|
|
+ * @version: 2024-09-06 11:20
|
|
|
+ */
|
|
|
+public class ALiYunSmsUtil {
|
|
|
+ private static final String ACCESS_KEY_ID = "LTAI5tMtykpNyYhfHjdneobt";//AccessKey自己账号的
|
|
|
+ private static final String ACCESS_KEY_SECRET = "AHE0Mdv5y5zW1h9xwHvJwzkXoKKrAd";
|
|
|
+ private static final String ENDPOINT = "dysmsapi.aliyuncs.com";//固定死
|
|
|
+ private static final String SIGNNAME = "大屏展示";//签名名称
|
|
|
+ private static final String TCODE = "";//模版的编号
|
|
|
+
|
|
|
+ public static HashMap<String,Object> loginSendSms(String phoneNumbers, String randomCode) throws Exception {
|
|
|
+ HashMap<String,Object> map = new HashMap<>();
|
|
|
+ Config config = new Config()
|
|
|
+ .setAccessKeyId(ACCESS_KEY_ID)
|
|
|
+ .setAccessKeySecret(ACCESS_KEY_SECRET)
|
|
|
+ .setEndpoint(ENDPOINT);
|
|
|
+
|
|
|
+ Client client = new Client(config);
|
|
|
+ SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
|
|
+ .setPhoneNumbers(phoneNumbers)
|
|
|
+ .setSignName(SIGNNAME)
|
|
|
+ .setTemplateCode("SMS_472770050")
|
|
|
+ //此处是设计模版的时候预留的变量${code}就验证码,用下面的随机生成4位数字传入
|
|
|
+ .setTemplateParam(String.format("{\"code\":\"%s\"}", randomCode));
|
|
|
+
|
|
|
+ try {
|
|
|
+ SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
|
|
|
+ System.out.println(sendSmsResponse);
|
|
|
+ map.put("statusCode",sendSmsResponse.getStatusCode());
|
|
|
+ return map;
|
|
|
+ } catch (TeaException error) {
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送通知(巡视通知)
|
|
|
+ * @param phoneNumbers
|
|
|
+ * @param no
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static HashMap<String,Object> tourInformSendSms(String phoneNumbers, String no) throws Exception {
|
|
|
+ HashMap<String,Object> map = new HashMap<>();
|
|
|
+ Config config = new Config()
|
|
|
+ .setAccessKeyId(ACCESS_KEY_ID)
|
|
|
+ .setAccessKeySecret(ACCESS_KEY_SECRET)
|
|
|
+ .setEndpoint(ENDPOINT);
|
|
|
+
|
|
|
+ Client client = new Client(config);
|
|
|
+ SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
|
|
+ .setPhoneNumbers(phoneNumbers)
|
|
|
+ .setSignName(SIGNNAME)
|
|
|
+ .setTemplateCode("SMS_472680059")
|
|
|
+ //此处是设计模版的时候预留的变量${code}就验证码,用下面的随机生成4位数字传入
|
|
|
+ .setTemplateParam(String.format("{\"no\":\"%s\"}", no));
|
|
|
+
|
|
|
+ try {
|
|
|
+ SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
|
|
|
+ System.out.println(sendSmsResponse);
|
|
|
+ map.put("statusCode",sendSmsResponse.getStatusCode());
|
|
|
+ return map;
|
|
|
+ } catch (TeaException error) {
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送通知(转运通知)
|
|
|
+ * @param phoneNumbers
|
|
|
+ * @param no
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static HashMap<String,Object> transferInformSendSms(String phoneNumbers, String no) throws Exception {
|
|
|
+ HashMap<String,Object> map = new HashMap<>();
|
|
|
+ Config config = new Config()
|
|
|
+ .setAccessKeyId(ACCESS_KEY_ID)
|
|
|
+ .setAccessKeySecret(ACCESS_KEY_SECRET)
|
|
|
+ .setEndpoint(ENDPOINT);
|
|
|
+
|
|
|
+ Client client = new Client(config);
|
|
|
+ SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
|
|
+ .setPhoneNumbers(phoneNumbers)
|
|
|
+ .setSignName(SIGNNAME)
|
|
|
+ .setTemplateCode("SMS_472775053")
|
|
|
+ //此处是设计模版的时候预留的变量${code}就验证码,用下面的随机生成4位数字传入
|
|
|
+ .setTemplateParam(String.format("{\"no\":\"%s\"}", no));
|
|
|
+
|
|
|
+ try {
|
|
|
+ SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
|
|
|
+ System.out.println(sendSmsResponse);
|
|
|
+ map.put("statusCode",sendSmsResponse.getStatusCode());
|
|
|
+ return map;
|
|
|
+ } catch (TeaException error) {
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|