use of com.tencentcloudapi.sms.v20210111.models.SendStatus in project austin by ZhongFuCheng3y.
the class TencentSmsScript method assembleSmsRecord.
private List<SmsRecord> assembleSmsRecord(SmsParam smsParam, SendSmsResponse response, TencentSmsParam tencentSmsParam) {
if (response == null || ArrayUtil.isEmpty(response.getSendStatusSet())) {
return null;
}
List<SmsRecord> smsRecordList = new ArrayList<>();
for (SendStatus sendStatus : response.getSendStatusSet()) {
// 腾讯返回的电话号有前缀,这里取巧直接翻转获取手机号
String phone = new StringBuilder(new StringBuilder(sendStatus.getPhoneNumber()).reverse().substring(0, PHONE_NUM)).reverse().toString();
SmsRecord smsRecord = SmsRecord.builder().sendDate(Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN))).messageTemplateId(smsParam.getMessageTemplateId()).phone(Long.valueOf(phone)).supplierId(tencentSmsParam.getSupplierId()).supplierName(tencentSmsParam.getSupplierName()).msgContent(smsParam.getContent()).seriesId(sendStatus.getSerialNo()).chargingNum(Math.toIntExact(sendStatus.getFee())).status(SmsStatus.SEND_SUCCESS.getCode()).reportContent(sendStatus.getCode()).created(Math.toIntExact(DateUtil.currentSeconds())).updated(Math.toIntExact(DateUtil.currentSeconds())).build();
smsRecordList.add(smsRecord);
}
return smsRecordList;
}
use of com.tencentcloudapi.sms.v20210111.models.SendStatus in project RuoYi-Cloud-Plus by JavaLionLi.
the class TencentSmsTemplate method send.
public SmsResult send(String phones, String templateId, Map<String, String> param) {
if (StringUtils.isBlank(phones)) {
throw new SmsException("手机号不能为空");
}
if (StringUtils.isBlank(templateId)) {
throw new SmsException("模板ID不能为空");
}
SendSmsRequest req = new SendSmsRequest();
Set<String> set = Arrays.stream(phones.split(",")).map(p -> "+86" + p).collect(Collectors.toSet());
req.setPhoneNumberSet(ArrayUtil.toArray(set, String.class));
if (CollUtil.isNotEmpty(param)) {
req.setTemplateParamSet(ArrayUtil.toArray(param.values(), String.class));
}
req.setTemplateID(templateId);
req.setSign(properties.getSignName());
req.setSmsSdkAppid(properties.getSdkAppId());
try {
SendSmsResponse resp = client.SendSms(req);
SmsResult.SmsResultBuilder builder = SmsResult.builder().isSuccess(true).message("send success").response(resp);
for (SendStatus sendStatus : resp.getSendStatusSet()) {
if (!"Ok".equals(sendStatus.getCode())) {
builder.isSuccess(false).message(sendStatus.getMessage());
break;
}
}
return builder.build();
} catch (Exception e) {
throw new SmsException(e.getMessage());
}
}
Aggregations