|
@@ -1,22 +1,25 @@
|
|
package com.backendsys.modules.tencent.service.impl;
|
|
package com.backendsys.modules.tencent.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.backendsys.exception.CustException;
|
|
import com.backendsys.exception.CustException;
|
|
import com.backendsys.modules.common.config.redis.utils.RedisUtil;
|
|
import com.backendsys.modules.common.config.redis.utils.RedisUtil;
|
|
|
|
+import com.backendsys.modules.tencent.entity.SmsCallbackStatis;
|
|
|
|
+import com.backendsys.modules.tencent.entity.SmsStatis;
|
|
import com.backendsys.modules.tencent.service.TencentSmsService;
|
|
import com.backendsys.modules.tencent.service.TencentSmsService;
|
|
|
|
+import com.backendsys.utils.MapUtil;
|
|
import com.tencentcloudapi.common.Credential;
|
|
import com.tencentcloudapi.common.Credential;
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
|
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
|
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.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@@ -32,7 +35,18 @@ public class TencentSmsServiceImpl implements TencentSmsService {
|
|
@Value("${tencent.sms.sign-name}")
|
|
@Value("${tencent.sms.sign-name}")
|
|
private String SIGN_NAME;
|
|
private String SIGN_NAME;
|
|
|
|
|
|
- // [腾讯云] 发送短信 { 模板ID, 模板参数, 下发手机号码 }
|
|
|
|
|
|
+ // [腾讯云] 生成 SmsClient
|
|
|
|
+ private SmsClient getSmsClient() {
|
|
|
|
+ Credential cred = new Credential(SECRET_ID, SECRET_KEY);
|
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
|
+ SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
|
|
|
+ return client;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * [腾讯云] 发送短信 { 模板ID, 模板参数, 下发手机号码 }
|
|
|
|
+ * https://cloud.tencent.com/document/product/382/55981
|
|
|
|
+ */
|
|
@Override
|
|
@Override
|
|
public SendSmsResponse send(String template_id, String[] templateParamSet, String[] phoneNumberSet) throws TencentCloudSDKException {
|
|
public SendSmsResponse send(String template_id, String[] templateParamSet, String[] phoneNumberSet) throws TencentCloudSDKException {
|
|
|
|
|
|
@@ -44,14 +58,83 @@ public class TencentSmsServiceImpl implements TencentSmsService {
|
|
req.setPhoneNumberSet(phoneNumberSet);
|
|
req.setPhoneNumberSet(phoneNumberSet);
|
|
|
|
|
|
// [SDK] 发送短信
|
|
// [SDK] 发送短信
|
|
- Credential cred = new Credential(SECRET_ID, SECRET_KEY);
|
|
|
|
- ClientProfile clientProfile = new ClientProfile();
|
|
|
|
- SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
|
|
|
-
|
|
|
|
// 通过 client 对象调用 SendSms 方法发起请求。注意请求方法名与请求对象是对应的
|
|
// 通过 client 对象调用 SendSms 方法发起请求。注意请求方法名与请求对象是对应的
|
|
// 返回的 res 是一个 SendSmsResponse 类的实例,与请求对象对应
|
|
// 返回的 res 是一个 SendSmsResponse 类的实例,与请求对象对应
|
|
- SendSmsResponse res = client.SendSms(req);
|
|
|
|
- return res;
|
|
|
|
|
|
+ SmsClient client = getSmsClient();
|
|
|
|
+ SendSmsResponse response = client.SendSms(req);
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * [腾讯云] 获得统计短信发送数据
|
|
|
|
+ * https://cloud.tencent.com/document/product/382/55965
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public SmsStatis getSMSStatistics(String beginTime, String endTime) throws TencentCloudSDKException {
|
|
|
|
+
|
|
|
|
+ if (StrUtil.isEmpty(beginTime)) throw new CustException("beginTime 不能为空");
|
|
|
|
+ if (StrUtil.isEmpty(endTime)) throw new CustException("endTime 不能为空");
|
|
|
|
+
|
|
|
|
+ SendStatusStatisticsRequest req = new SendStatusStatisticsRequest();
|
|
|
|
+ req.setSmsSdkAppId(SDK_APP_ID);
|
|
|
|
+ req.setLimit(0L); // 最大上限 (注:目前固定设置为0)
|
|
|
|
+ req.setOffset(0L); // 偏移量 (注:目前固定设置为0
|
|
|
|
+ req.setBeginTime(beginTime);
|
|
|
|
+ req.setEndTime(endTime);
|
|
|
|
+
|
|
|
|
+ // [SDK] 统计短信发送数据
|
|
|
|
+ // 通过 client 对象调用 SendStatusStatistics 方法发起请求。注意请求方法名与请求对象是对应的
|
|
|
|
+ // 返回的 res 是一个 SendStatusStatisticsResponse 类的实例,与请求对象对应
|
|
|
|
+ SmsClient client = getSmsClient();
|
|
|
|
+ SendStatusStatisticsResponse response = client.SendStatusStatistics(req);
|
|
|
|
+ SendStatusStatistics statis = response.getSendStatusStatistics();
|
|
|
|
+
|
|
|
|
+ // String resStr = SendStatusStatisticsResponse.toJsonString(response);
|
|
|
|
+
|
|
|
|
+ SmsStatis smsStatis = new SmsStatis();
|
|
|
|
+ smsStatis.setFee_count(statis.getFeeCount());
|
|
|
|
+ smsStatis.setRequest_count(statis.getRequestCount());
|
|
|
|
+ smsStatis.setRequest_success_count(statis.getRequestSuccessCount());
|
|
|
|
+ return smsStatis;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * [腾讯云] 获得回执数据统计
|
|
|
|
+ * https://cloud.tencent.com/document/product/382/55966
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public SmsCallbackStatis getSMSCallbackStatistics(String beginTime, String endTime) throws TencentCloudSDKException {
|
|
|
|
+
|
|
|
|
+ if (StrUtil.isEmpty(beginTime)) throw new CustException("beginTime 不能为空");
|
|
|
|
+ if (StrUtil.isEmpty(endTime)) throw new CustException("endTime 不能为空");
|
|
|
|
+
|
|
|
|
+ CallbackStatusStatisticsRequest req = new CallbackStatusStatisticsRequest();
|
|
|
|
+ req.setSmsSdkAppId(SDK_APP_ID);
|
|
|
|
+ req.setLimit(0L);
|
|
|
|
+ req.setOffset(0L);
|
|
|
|
+ req.setBeginTime(beginTime);
|
|
|
|
+ req.setEndTime(endTime);
|
|
|
|
+
|
|
|
|
+ SmsClient client = getSmsClient();
|
|
|
|
+ CallbackStatusStatisticsResponse response = client.CallbackStatusStatistics(req);
|
|
|
|
+ CallbackStatusStatistics statis = response.getCallbackStatusStatistics();
|
|
|
|
+
|
|
|
|
+ // String resStr = SendStatusStatisticsResponse.toJsonString(response);
|
|
|
|
+
|
|
|
|
+ SmsCallbackStatis smsCallbackStatis = new SmsCallbackStatis();
|
|
|
|
+ smsCallbackStatis.setCallback_count(statis.getCallbackCount());
|
|
|
|
+ smsCallbackStatis.setRequest_success_count(statis.getRequestSuccessCount());
|
|
|
|
+ smsCallbackStatis.setCallback_fail_count(statis.getCallbackFailCount());
|
|
|
|
+ smsCallbackStatis.setCallback_success_count(statis.getCallbackSuccessCount());
|
|
|
|
+ smsCallbackStatis.setInternal_error_count(statis.getInternalErrorCount());
|
|
|
|
+ smsCallbackStatis.setInvalid_number_count(statis.getInvalidNumberCount());
|
|
|
|
+ smsCallbackStatis.setShutdown_error_count(statis.getShutdownErrorCount());
|
|
|
|
+ smsCallbackStatis.setBlack_list_count(statis.getBlackListCount());
|
|
|
|
+ smsCallbackStatis.setFrequency_limit_count(statis.getFrequencyLimitCount());
|
|
|
|
+ return smsCallbackStatis;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|