Search in sources :

Example 1 with SmsException

use of io.picos.sailfish.mfa.sms.exception.SmsException in project sailfish-mfa by picos-io.

the class AliyunSmsSender method sendPasscode.

@Override
public void sendPasscode(String toPhoneNumber, String code) {
    SendSmsRequest request = new SendSmsRequest();
    try {
        request.setMethod(MethodType.POST);
        request.setSignName(signName);
        request.setTemplateCode(passcodeTemplate);
        request.setTemplateParam(String.format(PASSCODE_MESSAGE, code));
        request.setPhoneNumbers(toPhoneNumber);
        SendSmsResponse httpResponse = client.getAcsResponse(request);
    // TODO parse code
    } catch (ServerException e) {
        throw new SmsException(e);
    } catch (ClientException e) {
        throw new SmsException(e);
    }
}
Also used : ServerException(com.aliyuncs.exceptions.ServerException) SendSmsRequest(io.picos.sailfish.mfa.sms.repackage.com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest) ClientException(com.aliyuncs.exceptions.ClientException) SendSmsResponse(io.picos.sailfish.mfa.sms.repackage.com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse) SmsException(io.picos.sailfish.mfa.sms.exception.SmsException)

Example 2 with SmsException

use of io.picos.sailfish.mfa.sms.exception.SmsException in project sailfish-mfa by picos-io.

the class AliyunSmsSender method init.

@PostConstruct
private void init() {
    try {
        IClientProfile profile = DefaultProfile.getProfile(region, accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint(region, region, "Dysmsapi", endpoint);
        client = new DefaultAcsClient(profile);
    } catch (Throwable e) {
        throw new SmsException("Initialize the ALIYUN SMS client failed.", e);
    }
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) IClientProfile(com.aliyuncs.profile.IClientProfile) SmsException(io.picos.sailfish.mfa.sms.exception.SmsException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

SmsException (io.picos.sailfish.mfa.sms.exception.SmsException)2 DefaultAcsClient (com.aliyuncs.DefaultAcsClient)1 ClientException (com.aliyuncs.exceptions.ClientException)1 ServerException (com.aliyuncs.exceptions.ServerException)1 IClientProfile (com.aliyuncs.profile.IClientProfile)1 SendSmsRequest (io.picos.sailfish.mfa.sms.repackage.com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest)1 SendSmsResponse (io.picos.sailfish.mfa.sms.repackage.com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse)1 PostConstruct (javax.annotation.PostConstruct)1