|
@@ -1,199 +1,199 @@
|
|
|
-package com.doc.system.service;
|
|
|
-
|
|
|
-import com.doc.common.utils.DateUtils;
|
|
|
-import com.tencentcloudapi.common.Credential;
|
|
|
-import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
-import com.tencentcloudapi.common.profile.HttpProfile;
|
|
|
-import com.tencentcloudapi.sms.v20210111.SmsClient;
|
|
|
-import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
|
|
-import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
-
|
|
|
-/**
|
|
|
- * 腾讯云短信接口
|
|
|
- *
|
|
|
- * @author wukai
|
|
|
- * @date 2022-12-19
|
|
|
- */
|
|
|
-public class TencentSmsService {
|
|
|
- private static final String SECRET_ID = "AKIDKTMzLQErDJ8gxwe5F8j36sMZWCbjaBUW";
|
|
|
- private static final String SECRET_KEY = "mHVR6UbRzGGzRbU6RUGlzwc2A1astgIi";
|
|
|
- private static final String APPID = "1400871556";
|
|
|
- private static final String SIGN_NAME = "四川聚聚通科技有限公司";
|
|
|
- private static final Logger log = LoggerFactory.getLogger(TencentSmsService.class);
|
|
|
-
|
|
|
- private static SendSmsResponse sendSms(String phone, String templateId, String[] templateParamSet) throws Exception {
|
|
|
- // 实例化一个认证对象cred,入参需要传入腾讯云账户密钥 secretId,secretKey, 前往 API 密钥管理 页面,即可进行获取密钥。此处还需注意密钥对的保密。
|
|
|
- Credential cred = new Credential(SECRET_ID, SECRET_KEY);
|
|
|
- // 从3.1.16版本开始, 单独设置 HTTP 代理
|
|
|
- HttpProfile httpProfile = new HttpProfile();
|
|
|
- // get请求(默认为post请求)
|
|
|
- httpProfile.setReqMethod("POST");
|
|
|
- // 请求连接超时时间,单位为秒(默认60秒)
|
|
|
- httpProfile.setConnTimeout(60);
|
|
|
- // 指定接入地域域名(默认就近接入)
|
|
|
- httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
|
|
- ClientProfile clientProfile = new ClientProfile();
|
|
|
- // 指定签名算法(默认为HmacSHA256)
|
|
|
- clientProfile.setSignMethod("HmacSHA256");
|
|
|
- // 自3.1.80版本开始,SDK 支持打印日志。
|
|
|
- clientProfile.setHttpProfile(httpProfile);
|
|
|
- clientProfile.setDebug(true);
|
|
|
- //实例化要请求产品的client对象。
|
|
|
- SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
|
|
- SendSmsRequest req = new SendSmsRequest();
|
|
|
-
|
|
|
- req.setSmsSdkAppId(APPID);
|
|
|
- req.setSignName(SIGN_NAME);
|
|
|
- req.setTemplateId(templateId);
|
|
|
- req.setTemplateParamSet(templateParamSet);
|
|
|
-
|
|
|
- String preStr = "+86";
|
|
|
- String[] phoneNumberSet = new String[]{preStr + phone};
|
|
|
- req.setPhoneNumberSet(phoneNumberSet);
|
|
|
- String sessionContext = "";
|
|
|
- req.setSessionContext(sessionContext);
|
|
|
- String extendCode = "";
|
|
|
- req.setExtendCode(extendCode);
|
|
|
- String senderId = "";
|
|
|
- req.setSenderId(senderId);
|
|
|
- return client.SendSms(req);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送验证码
|
|
|
- *
|
|
|
- * @param phone 电话
|
|
|
- * @param code 验证码
|
|
|
- */
|
|
|
- @Async("threadPoolTaskExecutor")
|
|
|
- public void verificationCode(String phone, String code) {
|
|
|
- try {
|
|
|
- String templateId = "1647196";
|
|
|
- String[] templateParamSet = new String[]{code};
|
|
|
- SendSmsResponse res = sendSms(phone, templateId, templateParamSet);
|
|
|
- log.info(SendSmsResponse.toJsonString(res));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("passSms:{}", e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 业务信息告警
|
|
|
- *
|
|
|
- * @param phone 电话
|
|
|
- * @param time 时间
|
|
|
- * @param account 账号
|
|
|
- * @param msg ip
|
|
|
- */
|
|
|
- @Async("threadPoolTaskExecutor")
|
|
|
- public void alarmIllegal(String phone, String time, String account, String msg) {
|
|
|
- try {
|
|
|
- String templateId = "1999844";
|
|
|
- String[] templateParamSet = new String[]{time, account, msg};
|
|
|
- SendSmsResponse res = sendSms(phone, templateId, templateParamSet);
|
|
|
- log.info(SendSmsResponse.toJsonString(res));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("passSms:{}", e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 性能监控
|
|
|
- *
|
|
|
- * @param phone 电话
|
|
|
- * @param ip 服务器IP
|
|
|
- * @param type 类型 CPU 内存 硬盘
|
|
|
- * @param data 百分比
|
|
|
- */
|
|
|
- @Async("threadPoolTaskExecutor")
|
|
|
- public void performanceMonitoring(String phone, String ip, String type, String data) {
|
|
|
- try {
|
|
|
- String templateId = "1454381";
|
|
|
- String[] templateParamSet = new String[]{ip, type, data};
|
|
|
- SendSmsResponse res = sendSms(phone, templateId, templateParamSet);
|
|
|
- log.info(SendSmsResponse.toJsonString(res));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("passSms:{}", e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+//package com.doc.system.service;
|
|
|
+//
|
|
|
+//import com.doc.common.utils.DateUtils;
|
|
|
+//import com.tencentcloudapi.common.Credential;
|
|
|
+//import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
+//import com.tencentcloudapi.common.profile.HttpProfile;
|
|
|
+//import com.tencentcloudapi.sms.v20210111.SmsClient;
|
|
|
+//import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
|
|
+//import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
|
|
+//import org.slf4j.Logger;
|
|
|
+//import org.slf4j.LoggerFactory;
|
|
|
+//import org.springframework.scheduling.annotation.Async;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 腾讯云短信接口
|
|
|
+// *
|
|
|
+// * @author wukai
|
|
|
+// * @date 2022-12-19
|
|
|
+// */
|
|
|
+//public class TencentSmsService {
|
|
|
+// private static final String SECRET_ID = "AKIDKTMzLQErDJ8gxwe5F8j36sMZWCbjaBUW";
|
|
|
+// private static final String SECRET_KEY = "mHVR6UbRzGGzRbU6RUGlzwc2A1astgIi";
|
|
|
+// private static final String APPID = "1400871556";
|
|
|
+// private static final String SIGN_NAME = "四川聚聚通科技有限公司";
|
|
|
+// private static final Logger log = LoggerFactory.getLogger(TencentSmsService.class);
|
|
|
+//
|
|
|
+// private static SendSmsResponse sendSms(String phone, String templateId, String[] templateParamSet) throws Exception {
|
|
|
+// // 实例化一个认证对象cred,入参需要传入腾讯云账户密钥 secretId,secretKey, 前往 API 密钥管理 页面,即可进行获取密钥。此处还需注意密钥对的保密。
|
|
|
+// Credential cred = new Credential(SECRET_ID, SECRET_KEY);
|
|
|
+// // 从3.1.16版本开始, 单独设置 HTTP 代理
|
|
|
+// HttpProfile httpProfile = new HttpProfile();
|
|
|
+// // get请求(默认为post请求)
|
|
|
+// httpProfile.setReqMethod("POST");
|
|
|
+// // 请求连接超时时间,单位为秒(默认60秒)
|
|
|
+// httpProfile.setConnTimeout(60);
|
|
|
+// // 指定接入地域域名(默认就近接入)
|
|
|
+// httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
|
|
+// ClientProfile clientProfile = new ClientProfile();
|
|
|
+// // 指定签名算法(默认为HmacSHA256)
|
|
|
+// clientProfile.setSignMethod("HmacSHA256");
|
|
|
+// // 自3.1.80版本开始,SDK 支持打印日志。
|
|
|
+// clientProfile.setHttpProfile(httpProfile);
|
|
|
+// clientProfile.setDebug(true);
|
|
|
+// //实例化要请求产品的client对象。
|
|
|
+// SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
|
|
+// SendSmsRequest req = new SendSmsRequest();
|
|
|
+//
|
|
|
+// req.setSmsSdkAppId(APPID);
|
|
|
+// req.setSignName(SIGN_NAME);
|
|
|
+// req.setTemplateId(templateId);
|
|
|
+// req.setTemplateParamSet(templateParamSet);
|
|
|
+//
|
|
|
+// String preStr = "+86";
|
|
|
+// String[] phoneNumberSet = new String[]{preStr + phone};
|
|
|
+// req.setPhoneNumberSet(phoneNumberSet);
|
|
|
+// String sessionContext = "";
|
|
|
+// req.setSessionContext(sessionContext);
|
|
|
+// String extendCode = "";
|
|
|
+// req.setExtendCode(extendCode);
|
|
|
+// String senderId = "";
|
|
|
+// req.setSenderId(senderId);
|
|
|
+// return client.SendSms(req);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 发送验证码
|
|
|
+// *
|
|
|
+// * @param phone 电话
|
|
|
+// * @param code 验证码
|
|
|
+// */
|
|
|
+// @Async("threadPoolTaskExecutor")
|
|
|
+// public void verificationCode(String phone, String code) {
|
|
|
+// try {
|
|
|
+// String templateId = "1647196";
|
|
|
+// String[] templateParamSet = new String[]{code};
|
|
|
+// SendSmsResponse res = sendSms(phone, templateId, templateParamSet);
|
|
|
+// log.info(SendSmsResponse.toJsonString(res));
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// log.error("passSms:{}", e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
// /**
|
|
|
-// * 扩容申请成功
|
|
|
+// * 业务信息告警
|
|
|
// *
|
|
|
// * @param phone 电话
|
|
|
-// * @param useAble 可用容量
|
|
|
-// * @param type 类型 CPU 内存 硬盘
|
|
|
-// * @param data 百分比
|
|
|
+// * @param time 时间
|
|
|
+// * @param account 账号
|
|
|
+// * @param msg ip
|
|
|
// */
|
|
|
// @Async("threadPoolTaskExecutor")
|
|
|
-// public void capExpandSuccess(String phone, String useAble) {
|
|
|
-//try {
|
|
|
-// String templateId = "2013992";
|
|
|
-// String[] templateParamSet = new String[]{useAble};
|
|
|
-// SendSmsResponse res = sendSms(phone, templateId, templateParamSet);
|
|
|
-// log.info(SendSmsResponse.toJsonString(res));
|
|
|
-//} catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// log.error("passSms:{}", e.getMessage());
|
|
|
-//}
|
|
|
+// public void alarmIllegal(String phone, String time, String account, String msg) {
|
|
|
+// try {
|
|
|
+// String templateId = "1999844";
|
|
|
+// String[] templateParamSet = new String[]{time, account, msg};
|
|
|
+// SendSmsResponse res = sendSms(phone, templateId, templateParamSet);
|
|
|
+// log.info(SendSmsResponse.toJsonString(res));
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// log.error("passSms:{}", e.getMessage());
|
|
|
+// }
|
|
|
// }
|
|
|
-
|
|
|
- public static void send(String templateId, String phone, String... data) {
|
|
|
- try {
|
|
|
- SendSmsResponse res = sendSms(phone, templateId, data);
|
|
|
- log.info(SendSmsResponse.toJsonString(res));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("passSms:{}", e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送验证码
|
|
|
- * 您的当前验证码为:{1},若非本人操作,请勿泄露。
|
|
|
- */
|
|
|
- public static final String VERIFICATION_CODE = "1647196";
|
|
|
- /**
|
|
|
- * 发送系统监控信息
|
|
|
- * 您的服务器{1} {2}使用率{3},请尽快处理!
|
|
|
- */
|
|
|
- public static final String PERFORMANCE_MONITORING = "1454381";
|
|
|
- /**
|
|
|
- * 发送非法操作信息
|
|
|
- * 于北京时间{1}拦截到{2}非法操作:{3}
|
|
|
- */
|
|
|
- public static final String ALARM_ILLEGAL = "1999844";
|
|
|
- /**
|
|
|
- * 你的扩容申请成功,当前可使用容量为{1},快去看看吧!
|
|
|
- */
|
|
|
- public static final String CAP_EXPAND_SUCCESS = "2013992";
|
|
|
- /**
|
|
|
- * 很抱歉!管理员拒绝了您的扩容申请!
|
|
|
- */
|
|
|
- public static final String CAP_EXPAND_FAIL = "2013988";
|
|
|
- /**
|
|
|
- * {1}向您分享了名为"{2}"的文件,请注意查收!
|
|
|
- */
|
|
|
- public static final String FILE_SHARE = "2013984";
|
|
|
- /**
|
|
|
- * {1}向你发起了名为"{2}”的协作文件,请尽快登录系统查看!
|
|
|
- */
|
|
|
- public static final String FILE_ACTOR = "2013987";
|
|
|
-
|
|
|
-
|
|
|
- public static void main(String[] args) throws Exception {
|
|
|
- String phone = "17760370787";
|
|
|
- TencentSmsService.send(TencentSmsService.ALARM_ILLEGAL, phone, DateUtils.getTime(), "192.168.188.88", "非法访问!");
|
|
|
-// TencentSmsService.send("1647196", phone, "1234");
|
|
|
-// TencentSmsService.send("1454381", phone, "192.168.188.11", "CPU", "80%");
|
|
|
- //service.alarmIllegal(phone, DateUtils.dateTime(), "192.168.1.11", "非法访问!");
|
|
|
- //service.performanceMonitoring(phone, "192.168.1.11", "CPU", "80%");
|
|
|
- }
|
|
|
-}
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 性能监控
|
|
|
+// *
|
|
|
+// * @param phone 电话
|
|
|
+// * @param ip 服务器IP
|
|
|
+// * @param type 类型 CPU 内存 硬盘
|
|
|
+// * @param data 百分比
|
|
|
+// */
|
|
|
+// @Async("threadPoolTaskExecutor")
|
|
|
+// public void performanceMonitoring(String phone, String ip, String type, String data) {
|
|
|
+// try {
|
|
|
+// String templateId = "1454381";
|
|
|
+// String[] templateParamSet = new String[]{ip, type, data};
|
|
|
+// SendSmsResponse res = sendSms(phone, templateId, templateParamSet);
|
|
|
+// log.info(SendSmsResponse.toJsonString(res));
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// log.error("passSms:{}", e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//// /**
|
|
|
+//// * 扩容申请成功
|
|
|
+//// *
|
|
|
+//// * @param phone 电话
|
|
|
+//// * @param useAble 可用容量
|
|
|
+//// * @param type 类型 CPU 内存 硬盘
|
|
|
+//// * @param data 百分比
|
|
|
+//// */
|
|
|
+//// @Async("threadPoolTaskExecutor")
|
|
|
+//// public void capExpandSuccess(String phone, String useAble) {
|
|
|
+////try {
|
|
|
+//// String templateId = "2013992";
|
|
|
+//// String[] templateParamSet = new String[]{useAble};
|
|
|
+//// SendSmsResponse res = sendSms(phone, templateId, templateParamSet);
|
|
|
+//// log.info(SendSmsResponse.toJsonString(res));
|
|
|
+////} catch (Exception e) {
|
|
|
+//// e.printStackTrace();
|
|
|
+//// log.error("passSms:{}", e.getMessage());
|
|
|
+////}
|
|
|
+//// }
|
|
|
+//
|
|
|
+// public static void send1(String templateId, String phone, String... data) {
|
|
|
+// try {
|
|
|
+// SendSmsResponse res = sendSms(phone, templateId, data);
|
|
|
+// log.info(SendSmsResponse.toJsonString(res));
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// log.error("passSms:{}", e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 发送验证码
|
|
|
+// * 您的当前验证码为:{1},若非本人操作,请勿泄露。
|
|
|
+// */
|
|
|
+// public static final String VERIFICATION_CODE = "1647196";
|
|
|
+// /**
|
|
|
+// * 发送系统监控信息
|
|
|
+// * 您的服务器{1} {2}使用率{3},请尽快处理!
|
|
|
+// */
|
|
|
+// public static final String PERFORMANCE_MONITORING = "1454381";
|
|
|
+// /**
|
|
|
+// * 发送非法操作信息
|
|
|
+// * 于北京时间{1}拦截到{2}非法操作:{3}
|
|
|
+// */
|
|
|
+// public static final String ALARM_ILLEGAL = "1999844";
|
|
|
+// /**
|
|
|
+// * 你的扩容申请成功,当前可使用容量为{1},快去看看吧!
|
|
|
+// */
|
|
|
+// public static final String CAP_EXPAND_SUCCESS = "2013992";
|
|
|
+// /**
|
|
|
+// * 很抱歉!管理员拒绝了您的扩容申请!
|
|
|
+// */
|
|
|
+// public static final String CAP_EXPAND_FAIL = "2013988";
|
|
|
+// /**
|
|
|
+// * {1}向您分享了名为"{2}"的文件,请注意查收!
|
|
|
+// */
|
|
|
+// public static final String FILE_SHARE = "2013984";
|
|
|
+// /**
|
|
|
+// * {1}向你发起了名为"{2}”的协作文件,请尽快登录系统查看!
|
|
|
+// */
|
|
|
+// public static final String FILE_ACTOR = "2013987";
|
|
|
+//
|
|
|
+//
|
|
|
+// public static void main(String[] args) throws Exception {
|
|
|
+// String phone = "17760370787";
|
|
|
+// TencentSmsService.send(TencentSmsService.ALARM_ILLEGAL, phone, DateUtils.getTime(), "192.168.188.88", "非法访问!");
|
|
|
+//// TencentSmsService.send("1647196", phone, "1234");
|
|
|
+//// TencentSmsService.send("1454381", phone, "192.168.188.11", "CPU", "80%");
|
|
|
+// //service.alarmIllegal(phone, DateUtils.dateTime(), "192.168.1.11", "非法访问!");
|
|
|
+// //service.performanceMonitoring(phone, "192.168.1.11", "CPU", "80%");
|
|
|
+// }
|
|
|
+//}
|