Search in sources :

Example 1 with SendSmsResponseBody

use of com.aliyun.dysmsapi20170525.models.SendSmsResponseBody in project cloud-sdk by mizhousoft.

the class AliyunSendSmsClient method send.

/**
 * {@inheritDoc}
 */
@Override
public void send(String phoneNumber, Map<String, String> paramMap, CloudSmsTemplate smsTemplate) throws CloudSDKException {
    if (null == smsTemplate) {
        throw new CloudSDKException("Sms template is null.");
    }
    String signName = smsTemplate.getSignName();
    String templateId = smsTemplate.getTemplateId().toString();
    SendSmsRequest request = new SendSmsRequest();
    request.setPhoneNumbers(phoneNumber);
    request.setSignName(signName);
    request.setTemplateCode(templateId);
    try {
        if (null != paramMap) {
            String templateParam = JSONUtils.toJSONString(paramMap);
            request.setTemplateParam(templateParam);
        }
        SendSmsResponse result = this.client.sendSms(request);
        SendSmsResponseBody body = result.getBody();
        if (null == body || !"ok".equalsIgnoreCase(body.getCode())) {
            throw new CloudSDKException("Send sms failed, code is " + body.code + ", message is " + body.getMessage() + ", request id is " + body.getRequestId() + ", bizId is " + body.getBizId() + '.');
        }
    } catch (Exception e) {
        throw new CloudSDKException("Send sms failed.", e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) SendSmsRequest(com.aliyun.dysmsapi20170525.models.SendSmsRequest) SendSmsResponseBody(com.aliyun.dysmsapi20170525.models.SendSmsResponseBody) SendSmsResponse(com.aliyun.dysmsapi20170525.models.SendSmsResponse) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException)

Example 2 with SendSmsResponseBody

use of com.aliyun.dysmsapi20170525.models.SendSmsResponseBody 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)

Aggregations

SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)2 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)2 SendSmsResponseBody (com.aliyun.dysmsapi20170525.models.SendSmsResponseBody)2 CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)1 ResultException (plus.wcj.heifer.boot.common.exception.ResultException)1