Search in sources :

Example 11 with SendSmsRequest

use of com.tencentcloudapi.sms.v20210111.models.SendSmsRequest in project heifer by galaxy-sea.

the class AliyunSmsServer method sendCaptcha.

@Override
public void sendCaptcha(String phoneNumbers, String captcha) {
    SendSmsRequest sendSmsRequest = new SendSmsRequest().setPhoneNumbers(phoneNumbers).setSignName(this.aliyunSmsProperties.getSignName()).setTemplateCode(TemplateCode.SMS_185520034.toString()).setTemplateParam("{\"code\":\"" + captcha + "\"}");
    SendSmsResponse sendSmsResponse;
    try {
        sendSmsResponse = this.client.sendSms(sendSmsRequest);
    } catch (Exception e) {
        throw new ResultException(ResultStatusEnum.SMS_NETWORK_EXCEPTION);
    }
    SendSmsResponseBody body = sendSmsResponse.getBody();
    if (!OK.equals(body.getCode())) {
        throw new ResultException(ResultStatusEnum.SMS_SEND_FAIL, body.getMessage());
    }
}
Also used : SendSmsRequest(com.aliyun.dysmsapi20170525.models.SendSmsRequest) SendSmsResponseBody(com.aliyun.dysmsapi20170525.models.SendSmsResponseBody) ResultException(plus.wcj.heifer.boot.common.exception.ResultException) SendSmsResponse(com.aliyun.dysmsapi20170525.models.SendSmsResponse) ResultException(plus.wcj.heifer.boot.common.exception.ResultException)

Example 12 with SendSmsRequest

use of com.tencentcloudapi.sms.v20210111.models.SendSmsRequest 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

SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)5 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)4 Credential (com.tencentcloudapi.common.Credential)4 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)4 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)4 SendSmsRequest (com.tencentcloudapi.sms.v20210111.models.SendSmsRequest)4 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)3 SmsClient (com.tencentcloudapi.sms.v20190711.SmsClient)3 SendSmsRequest (com.tencentcloudapi.sms.v20190711.models.SendSmsRequest)3 SendSmsResponse (com.tencentcloudapi.sms.v20190711.models.SendSmsResponse)3 SmsClient (com.tencentcloudapi.sms.v20210111.SmsClient)3 Client (com.aliyun.dysmsapi20170525.Client)2 SendSmsResponseBody (com.aliyun.dysmsapi20170525.models.SendSmsResponseBody)2 SendSmsResponse (com.tencentcloudapi.sms.v20210111.models.SendSmsResponse)2 SneakyThrows (lombok.SneakyThrows)2 CollUtil (cn.hutool.core.collection.CollUtil)1 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 Config (com.aliyun.teaopenapi.models.Config)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TencentSmsParam (com.java3y.austin.handler.domain.TencentSmsParam)1