|
@@ -0,0 +1,58 @@
|
|
|
|
+package com.care.common.util;
|
|
|
|
+
|
|
|
|
+import com.tencentcloudapi.common.Credential;
|
|
|
|
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
|
+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 com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author: lilt
|
|
|
|
+ * @Date: 2021/6/5
|
|
|
|
+ * @Desc:
|
|
|
|
+ */
|
|
|
|
+public class SmsUtil {
|
|
|
|
+
|
|
|
|
+ public static SendStatus sendSms(String SecretId,
|
|
|
|
+ String SecretKey,
|
|
|
|
+ String phoneNumber,
|
|
|
|
+ String SmsSdkAppId,
|
|
|
|
+ String signName,
|
|
|
|
+ String templateId,
|
|
|
|
+ String[] templateParam){
|
|
|
|
+ SendStatus sendStatus = null;
|
|
|
|
+ try{
|
|
|
|
+
|
|
|
|
+ Credential cred = new Credential(SecretId, SecretKey);
|
|
|
|
+
|
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
|
+ httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
|
|
|
+
|
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
|
+
|
|
|
|
+ SmsClient client = new SmsClient(cred, "", clientProfile);
|
|
|
|
+
|
|
|
|
+ String[] phoneNumberSet = {phoneNumber};
|
|
|
|
+
|
|
|
|
+ SendSmsRequest req = new SendSmsRequest();
|
|
|
|
+ req.setPhoneNumberSet(phoneNumberSet);
|
|
|
|
+
|
|
|
|
+ req.setSmsSdkAppId(SmsSdkAppId);
|
|
|
|
+ req.setSignName(signName);
|
|
|
|
+ req.setTemplateId(templateId);
|
|
|
|
+
|
|
|
|
+ req.setTemplateParamSet(templateParam);
|
|
|
|
+
|
|
|
|
+ SendSmsResponse resp = client.SendSms(req);
|
|
|
|
+ sendStatus = resp.getSendStatusSet()[0];
|
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
|
+ System.out.println(e.toString());
|
|
|
|
+ }
|
|
|
|
+ return sendStatus;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|