Search in sources :

Example 1 with SendStatus

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;
}
Also used : SmsRecord(com.java3y.austin.support.domain.SmsRecord) ArrayList(java.util.ArrayList) SendStatus(com.tencentcloudapi.sms.v20210111.models.SendStatus) Date(java.util.Date)

Example 2 with SendStatus

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());
    }
}
Also used : SmsProperties(com.ruoyi.common.sms.config.properties.SmsProperties) Arrays(java.util.Arrays) SneakyThrows(lombok.SneakyThrows) Set(java.util.Set) SendStatus(com.tencentcloudapi.sms.v20190711.models.SendStatus) SendSmsRequest(com.tencentcloudapi.sms.v20190711.models.SendSmsRequest) StringUtils(com.ruoyi.common.core.utils.StringUtils) SmsResult(com.ruoyi.common.sms.entity.SmsResult) Collectors(java.util.stream.Collectors) SmsClient(com.tencentcloudapi.sms.v20190711.SmsClient) CollUtil(cn.hutool.core.collection.CollUtil) SmsException(com.ruoyi.common.sms.exception.SmsException) SendSmsResponse(com.tencentcloudapi.sms.v20190711.models.SendSmsResponse) Map(java.util.Map) ArrayUtil(cn.hutool.core.util.ArrayUtil) Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) SendSmsRequest(com.tencentcloudapi.sms.v20190711.models.SendSmsRequest) SendStatus(com.tencentcloudapi.sms.v20190711.models.SendStatus) SmsResult(com.ruoyi.common.sms.entity.SmsResult) SendSmsResponse(com.tencentcloudapi.sms.v20190711.models.SendSmsResponse) SmsException(com.ruoyi.common.sms.exception.SmsException) SmsException(com.ruoyi.common.sms.exception.SmsException)

Aggregations

CollUtil (cn.hutool.core.collection.CollUtil)1 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 SmsRecord (com.java3y.austin.support.domain.SmsRecord)1 StringUtils (com.ruoyi.common.core.utils.StringUtils)1 SmsProperties (com.ruoyi.common.sms.config.properties.SmsProperties)1 SmsResult (com.ruoyi.common.sms.entity.SmsResult)1 SmsException (com.ruoyi.common.sms.exception.SmsException)1 Credential (com.tencentcloudapi.common.Credential)1 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)1 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)1 SmsClient (com.tencentcloudapi.sms.v20190711.SmsClient)1 SendSmsRequest (com.tencentcloudapi.sms.v20190711.models.SendSmsRequest)1 SendSmsResponse (com.tencentcloudapi.sms.v20190711.models.SendSmsResponse)1 SendStatus (com.tencentcloudapi.sms.v20190711.models.SendStatus)1 SendStatus (com.tencentcloudapi.sms.v20210111.models.SendStatus)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 Map (java.util.Map)1 Set (java.util.Set)1