阿里云短信接口的坑

今天接了下阿里云短信接口,想说下真的是坑的一逼。下面上代码

public static void main(String[] args_) throws ClientException {

String product ="Dysmsapi";//固定值


String domain ="Dysmsapi.aliyuncs.com";//固定值


String accessKeyId="XXXX";//固定值


String accessKeySecret="XXXX";//固定值

IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId, accessKeySecret);

try {

DefaultProfile.addEndpoint("cn-hangzhou","cn-hangzhou",product,domain);

} catch (com.aliyuncs.exceptions.ClientException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

IAcsClient acsClient= new DefaultAcsClient(profile);

SendSmsRequest request = new SendSmsRequest();

request.setMethod(MethodType.POST);

request.setPhoneNumbers("12233");//用户手机号

request.setSignName("1222");//签名不能改

request.setTemplateCode("SMS_2433");//模板 不能改

request.setTemplateParam("{\"code\":\"1234\"}");//动态验证码

SendSmsResponse sendSmsResponse;

try {

sendSmsResponse = acsClient.getAcsResponse(request);

if(sendSmsResponse.getCode().equals("ok")) {

//ok表示成功

}

} catch (ServerException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (com.aliyuncs.exceptions.ClientException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

下面划重点,所有的jar包一定要用pom文件下载

com.aliyun

aliyun-java-sdk-core

4.0.6

com.aliyun

aliyun-java-sdk-dysmsapi

1.1.0

com.google.code.gson

gson

2.8.5

发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章