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);
}
}
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());
}
}
Aggregations