|
|
@@ -10,7 +10,6 @@ import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
|
/**
|
|
|
* 腾讯云短信接口
|
|
|
@@ -18,16 +17,14 @@ import org.springframework.stereotype.Service;
|
|
|
* @author wukai
|
|
|
* @date 2022-12-19
|
|
|
*/
|
|
|
-@Service
|
|
|
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 SendSmsResponse sendSms(String phone, String templateId, String[] templateParamSet) throws Exception {
|
|
|
+ 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 代理
|
|
|
@@ -127,12 +124,76 @@ public class TencentSmsService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// /**
|
|
|
+// * 扩容申请成功
|
|
|
+// *
|
|
|
+// * @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 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 {
|
|
|
- TencentSmsService service = new TencentSmsService();
|
|
|
- String phone = "";
|
|
|
- service.alarmIllegal(phone, DateUtils.dateTime(), "192.168.1.11", "非法访问!");
|
|
|
- service.performanceMonitoring(phone, "192.168.1.11", "CPU", "80%");
|
|
|
- service.verificationCode(phone, "9527");
|
|
|
+ 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%");
|
|
|
}
|
|
|
}
|