package com.ruoyi.web.controller.tool;
|
|
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
import com.aliyun.tea.TeaException;
|
import com.aliyun.teaopenapi.models.Config;
|
import com.aliyun.teautil.models.RuntimeOptions;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
|
@Component
|
@Slf4j
|
public class MsgUtils {
|
|
|
|
/**
|
* 使用AK&SK初始化账号Client
|
* @param accessKeyId
|
* @param accessKeySecret
|
* @return Client
|
* @throws Exception
|
*/
|
public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
|
Config config = new Config()
|
// 您的 AccessKey ID
|
.setAccessKeyId(accessKeyId)
|
// 您的 AccessKey Secret
|
.setAccessKeySecret(accessKeySecret);
|
// 访问的域名
|
config.endpoint = "dysmsapi.aliyuncs.com";
|
return new com.aliyun.dysmsapi20170525.Client(config);
|
}
|
|
// 任务审核结果通知
|
public void sendMsg1(String phone,String point,String result) throws Exception {
|
com.aliyun.dysmsapi20170525.Client client = MsgUtils.createClient("LTAI5t6SvJEZ9Wv28ranrfLV","hL9wbTdM3rPOLMj0DAhCn90URVzvvw");
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
.setSignName("沿海市政")
|
.setTemplateCode("SMS_490460059")
|
.setPhoneNumbers(phone)
|
.setTemplateParam("{\"point\":\""+point+"\",\"result\":\""+result+"\"}");
|
RuntimeOptions runtime = new RuntimeOptions();
|
try {
|
// 复制代码运行请自行打印 API 的返回值
|
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
log.info("任务审核结果通知短信发送成功:{},{}",sendSmsResponse.getBody().getMessage(),sendSmsResponse.getStatusCode());
|
} catch (TeaException error) {
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("任务审核结果通知短信发送失败:{}",error.message);
|
} catch (Exception _error) {
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("任务审核结果通知短信发送失败:{}",error.message);
|
}
|
}
|
// 今日任务未完成
|
public void sendMsg2(String phone,String count) throws Exception {
|
com.aliyun.dysmsapi20170525.Client client = MsgUtils.createClient("LTAI5t6SvJEZ9Wv28ranrfLV","hL9wbTdM3rPOLMj0DAhCn90URVzvvw");
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
.setSignName("沿海市政")
|
.setTemplateCode("SMS_490450039")
|
.setPhoneNumbers(phone)
|
.setTemplateParam("{\"count\":\""+count+"\"}");
|
RuntimeOptions runtime = new RuntimeOptions();
|
try {
|
// 复制代码运行请自行打印 API 的返回值
|
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
log.info("今日任务未完成短信发送成功:{},{}",sendSmsResponse.getBody().getMessage(),sendSmsResponse.getStatusCode());
|
} catch (TeaException error) {
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("今日任务未完成短信发送失败:{}",error.message);
|
} catch (Exception _error) {
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("今日任务未完成短信发送失败:{}",error.message);
|
}
|
}
|
// 申诉结果通知通知
|
public void sendMsg3(String phone,String point,String result) throws Exception {
|
com.aliyun.dysmsapi20170525.Client client = MsgUtils.createClient("LTAI5t6SvJEZ9Wv28ranrfLV","hL9wbTdM3rPOLMj0DAhCn90URVzvvw");
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
.setSignName("沿海市政")
|
.setTemplateCode("SMS_490535047")
|
.setPhoneNumbers(phone)
|
.setTemplateParam("{\"point\":\""+point+"\",\"result\":\""+result+"\"}");
|
RuntimeOptions runtime = new RuntimeOptions();
|
try {
|
// 复制代码运行请自行打印 API 的返回值
|
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
log.info("申诉结果通知短信发送成功:{},{}",sendSmsResponse.getBody().getMessage(),sendSmsResponse.getStatusCode());
|
} catch (TeaException error) {
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("申诉结果通知短信发送失败:{}",error.message);
|
} catch (Exception _error) {
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("申诉结果通知短信发送失败:{}",error.message);
|
}
|
}
|
// 请假待审核提醒
|
public void sendMsg4(String phone) throws Exception {
|
com.aliyun.dysmsapi20170525.Client client = MsgUtils.createClient("LTAI5t6SvJEZ9Wv28ranrfLV","hL9wbTdM3rPOLMj0DAhCn90URVzvvw");
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
.setSignName("沿海市政")
|
.setTemplateCode("SMS_490305062")
|
.setPhoneNumbers(phone);
|
RuntimeOptions runtime = new RuntimeOptions();
|
try {
|
// 复制代码运行请自行打印 API 的返回值
|
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
log.info("请假待审核提醒短信发送成功:{},{}",sendSmsResponse.getBody().getMessage(),sendSmsResponse.getStatusCode());
|
} catch (TeaException error) {
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("请假待审核提醒短信发送失败:{}",error.message);
|
} catch (Exception _error) {
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("请假待审核提醒短信发送失败:{}",error.message);
|
}
|
}
|
// 请假结果抄送
|
public void sendMsg5(String phone,String name,String date) throws Exception {
|
com.aliyun.dysmsapi20170525.Client client = MsgUtils.createClient("LTAI5t6SvJEZ9Wv28ranrfLV","hL9wbTdM3rPOLMj0DAhCn90URVzvvw");
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
.setSignName("沿海市政")
|
.setTemplateCode("SMS_490325051")
|
.setPhoneNumbers(phone)
|
.setTemplateParam("{\"name\":\""+name+"\",\"date\":\""+date+"\"}");
|
RuntimeOptions runtime = new RuntimeOptions();
|
try {
|
// 复制代码运行请自行打印 API 的返回值
|
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
log.info("请假结果抄送短信发送成功:{},{}",sendSmsResponse.getBody().getMessage(),sendSmsResponse.getStatusCode());
|
} catch (TeaException error) {
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("请假结果抄送短信发送失败:{}",error.message);
|
} catch (Exception _error) {
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("请假结果抄送短信发送失败:{}",error.message);
|
}
|
}
|
// 督察任务整改通知
|
public void sendMsg6(String phone,String point) throws Exception {
|
com.aliyun.dysmsapi20170525.Client client = MsgUtils.createClient("LTAI5t6SvJEZ9Wv28ranrfLV","hL9wbTdM3rPOLMj0DAhCn90URVzvvw");
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
.setSignName("沿海市政")
|
.setTemplateCode("SMS_490375046")
|
.setPhoneNumbers(phone)
|
.setTemplateParam("{\"point\":\""+point+"\"}");
|
RuntimeOptions runtime = new RuntimeOptions();
|
try {
|
// 复制代码运行请自行打印 API 的返回值
|
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
log.info("督察任务整改通知短信发送成功:{},{}",sendSmsResponse.getBody().getMessage(),sendSmsResponse.getStatusCode());
|
} catch (TeaException error) {
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("督察任务整改通知短信发送失败:{}",error.message);
|
} catch (Exception _error) {
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
// 如有需要,请打印 error
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
log.info("督察任务整改通知短信发送失败:{}",error.message);
|
}
|
}
|
}
|