diff --git a/austin-common/src/main/java/com/java3y/austin/common/enums/RespStatusEnum.java b/austin-common/src/main/java/com/java3y/austin/common/enums/RespStatusEnum.java index 40985c7..26f61f5 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/enums/RespStatusEnum.java +++ b/austin-common/src/main/java/com/java3y/austin/common/enums/RespStatusEnum.java @@ -26,6 +26,7 @@ public enum RespStatusEnum { */ CLIENT_BAD_PARAMETERS("A0001", "客户端参数错误"), TEMPLATE_NOT_FOUND("A0002", "找不到模板或模板已被删除"), + TOO_MANY_RECEIVER("A0003", "传入的接收者大于100个"), /** * 系统 diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/TencentSmsReceipt.java b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/TencentSmsReceipt.java new file mode 100644 index 0000000..20c77fd --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/TencentSmsReceipt.java @@ -0,0 +1,115 @@ +package com.java3y.austin.handler.receipt; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.google.common.base.Throwables; +import com.java3y.austin.common.constant.SendAccountConstant; +import com.java3y.austin.common.dto.account.TencentSmsAccount; +import com.java3y.austin.common.enums.SmsStatus; +import com.java3y.austin.support.config.SupportThreadPoolConfig; +import com.java3y.austin.support.dao.SmsRecordDao; +import com.java3y.austin.support.domain.SmsRecord; +import com.java3y.austin.support.utils.AccountUtils; +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.*; +import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +/** + * 拉取短信回执信息 + * + * @author 3y + */ +@Component +@Slf4j +public class TencentSmsReceipt { + + + @Autowired + private AccountUtils accountUtils; + + @Autowired + private SmsRecordDao smsRecordDao; + + @PostConstruct + private void init() { + + // 获取腾讯云账号信息 + TencentSmsAccount account = accountUtils.getAccount(10, SendAccountConstant.SMS_ACCOUNT_KEY, SendAccountConstant.SMS_PREFIX, TencentSmsAccount.class); + + SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> { + + while (true) { + try { + SmsClient client = getSmsClient(account); + + // 每次拉取10条 + PullSmsSendStatusRequest req = new PullSmsSendStatusRequest(); + req.setLimit(10L); + req.setSmsSdkAppId(account.getSmsSdkAppId()); + + PullSmsSendStatusResponse resp = client.PullSmsSendStatus(req); + List smsRecordList = new ArrayList<>(); + if (resp != null && resp.getPullSmsSendStatusSet() != null && resp.getPullSmsSendStatusSet().length > 0) { + log.debug("receipt sms:{}", JSON.toJSONString(resp.getPullSmsSendStatusSet())); + for (PullSmsSendStatus pullSmsSendStatus : resp.getPullSmsSendStatusSet()) { + SmsRecord smsRecord = SmsRecord.builder() + .sendDate(Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN))) + .messageTemplateId(0L) + .phone(Long.valueOf(pullSmsSendStatus.getSubscriberNumber())) + .supplierId(account.getSupplierId()) + .supplierName(account.getSupplierName()) + .msgContent("") + .seriesId(pullSmsSendStatus.getSerialNo()) + .chargingNum(0) + .status("SUCCESS".equals(pullSmsSendStatus.getReportStatus()) ? SmsStatus.RECEIVE_SUCCESS.getCode() : SmsStatus.RECEIVE_FAIL.getCode()) + .reportContent(pullSmsSendStatus.getDescription()) + .created(Math.toIntExact(pullSmsSendStatus.getUserReceiveTime())) + .updated(Math.toIntExact(DateUtil.currentSeconds())) + .build(); + smsRecordList.add(smsRecord); + } + } + if (!CollUtil.isEmpty(smsRecordList)) { + smsRecordDao.saveAll(smsRecordList); + } + Thread.sleep(200); + } catch (Exception e) { + log.error("TencentSmsReceipt#init fail!{}", Throwables.getStackTraceAsString(e)); + } + } + + }); + + } + + /** + * 构造smsClient + * @param account + * @return + */ + private SmsClient getSmsClient(TencentSmsAccount account) { + Credential cred = new Credential(account.getSecretId(), account.getSecretKey()); + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint(account.getUrl()); + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + return new SmsClient(cred, account.getRegion(), clientProfile); + } + + +} diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/DataController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/DataController.java index 12503b7..801e4ad 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/DataController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/DataController.java @@ -46,10 +46,11 @@ public class DataController { return new BasicResultVO<>(RespStatusEnum.SUCCESS, echartsVo); } - public static void main(String[] args) { - EchartsVo.TitleVO titleVO = EchartsVo.TitleVO.builder().text("销售情况").build(); - EchartsVo echartsVo = EchartsVo.builder().title(titleVO).build(); - - System.out.println(JSON.toJSONString(echartsVo)); + @PostMapping("/sms") + @ApiOperation("/获取短信下发数据") + public BasicResultVO getSmsData(@RequestBody DataParam dataParam) { + EchartsVo echartsVo = EchartsVo.builder().build(); + return null; } + } diff --git a/austin-web/src/main/java/com/java3y/austin/web/vo/DataParam.java b/austin-web/src/main/java/com/java3y/austin/web/vo/DataParam.java index 1f3da93..9368baf 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/vo/DataParam.java +++ b/austin-web/src/main/java/com/java3y/austin/web/vo/DataParam.java @@ -16,8 +16,9 @@ import lombok.NoArgsConstructor; @AllArgsConstructor @NoArgsConstructor public class DataParam { + /** - * 传入userId查看用户的链路信息 + * 查看用户的链路信息 */ private String receiver; @@ -30,4 +31,11 @@ public class DataParam { private String businessId; + /** + * 日期时间(检索短信的条件使用) + */ + private String dateTime; + + + } diff --git a/pom.xml b/pom.xml index 68c2ffa..7b500bd 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ com.tencentcloudapi tencentcloud-sdk-java - 3.1.390 + 3.1.510