短信回执开发

pull/11/head
3y 3 years ago
parent 3974322516
commit 832c476b29

@ -26,6 +26,7 @@ public enum RespStatusEnum {
*/ */
CLIENT_BAD_PARAMETERS("A0001", "客户端参数错误"), CLIENT_BAD_PARAMETERS("A0001", "客户端参数错误"),
TEMPLATE_NOT_FOUND("A0002", "找不到模板或模板已被删除"), TEMPLATE_NOT_FOUND("A0002", "找不到模板或模板已被删除"),
TOO_MANY_RECEIVER("A0003", "传入的接收者大于100个"),
/** /**
* *

@ -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<SmsRecord> 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);
}
}

@ -46,10 +46,11 @@ public class DataController {
return new BasicResultVO<>(RespStatusEnum.SUCCESS, echartsVo); return new BasicResultVO<>(RespStatusEnum.SUCCESS, echartsVo);
} }
public static void main(String[] args) { @PostMapping("/sms")
EchartsVo.TitleVO titleVO = EchartsVo.TitleVO.builder().text("销售情况").build(); @ApiOperation("/获取短信下发数据")
EchartsVo echartsVo = EchartsVo.builder().title(titleVO).build(); public BasicResultVO getSmsData(@RequestBody DataParam dataParam) {
EchartsVo echartsVo = EchartsVo.builder().build();
System.out.println(JSON.toJSONString(echartsVo)); return null;
} }
} }

@ -16,8 +16,9 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class DataParam { public class DataParam {
/** /**
* userId *
*/ */
private String receiver; private String receiver;
@ -30,4 +31,11 @@ public class DataParam {
private String businessId; private String businessId;
/**
* (使)
*/
private String dateTime;
} }

@ -81,7 +81,7 @@
<dependency> <dependency>
<groupId>com.tencentcloudapi</groupId> <groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId> <artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.390</version> <version>3.1.510</version>
</dependency> </dependency>
<!--apollo--> <!--apollo-->

Loading…
Cancel
Save