public static void sendSms(String phoneNumber,boolean flag,int number){
DefaultProfile profile = DefaultProfile.getProfile("default", " LTAILFF......... ", "wRtLpGpqa4Ih2y................ ");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
//request.setProtocol(ProtocolType.HTTPS);
request.setMethod(MethodType.POST);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("PhoneNumbers",phoneNumber);
request.putQueryParameter("SignName","闲淘");
request.putQueryParameter("TemplateCode","SMS_000000000");
request.putQueryParameter("TemplateParam","{\"code\":"+number+"}");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
哈哈,上面的代码有没有发现什么错误?
代码是按照阿里官网的demo复制过来以后进行了稍微的改动,只要运行一直报下面异常,找了半天错误,最终发现是AccessKey ID 和Access Key Secret复制到idea中时自动填充了空格,真是坑爹了…
com.aliyuncs.exceptions.ClientException: SignatureDoesNotMatch : Specified signature is not matched with our calculation