|
@@ -1,114 +1,114 @@
|
|
|
-//package com.doc.common.utils;
|
|
|
-//
|
|
|
-//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;
|
|
|
-//
|
|
|
-///**
|
|
|
-// * 腾讯云短信接口
|
|
|
-// *
|
|
|
-// * @author wukai
|
|
|
-// * @date 2022-12-19
|
|
|
-// */
|
|
|
-//public class TencentSmsUtils {
|
|
|
-// 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(TencentSmsUtils.class);
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 发送验证码
|
|
|
-// * 您的当前验证码为:{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 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);
|
|
|
-// }
|
|
|
-//
|
|
|
-// 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());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// public static void main(String[] args) throws Exception {
|
|
|
-//// {"SendStatusSet":[{"SerialNo":"4249:221093732417050495444017078","PhoneNumber":"+8617760370787","Fee":1,"SessionContext":"","Code":"Ok","Message":"send success","IsoCode":"CN"}],"RequestId":"2ed7bbc6-5934-4853-aaa4-a89d0a63ae30"}
|
|
|
-// String phone = "17760370787";
|
|
|
-// TencentSmsUtils.send(TencentSmsUtils.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%");
|
|
|
-// }
|
|
|
-//}
|
|
|
+package com.doc.common.utils;
|
|
|
+
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 腾讯云短信接口
|
|
|
+ *
|
|
|
+ * @author wukai
|
|
|
+ * @date 2022-12-19
|
|
|
+ */
|
|
|
+public class TencentSmsUtils {
|
|
|
+ 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(TencentSmsUtils.class);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送验证码
|
|
|
+ * 您的当前验证码为:{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 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+// {"SendStatusSet":[{"SerialNo":"4249:221093732417050495444017078","PhoneNumber":"+8617760370787","Fee":1,"SessionContext":"","Code":"Ok","Message":"send success","IsoCode":"CN"}],"RequestId":"2ed7bbc6-5934-4853-aaa4-a89d0a63ae30"}
|
|
|
+ String phone = "17760370787";
|
|
|
+ TencentSmsUtils.send(TencentSmsUtils.ALARM_ILLEGAL, phone, DateUtils.getTime(), "127-0-0-1", "多次非法访问");
|
|
|
+// 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%");
|
|
|
+ }
|
|
|
+}
|