报错内容:
com.aliyuncs.exceptions.ClientException: SignatureDoesNotMatch : Specified signature is not matched with our calculation. server string to sign is:POST&%2F&AccessKeyId%3********************%26Action%3DSendSms%26Format%3DJSON%26PhoneNumbers%3D***********%26RegionId%3Dcn-hangzhou%26SignName%3D%25E4%25B9%25****5C%2598%25E5%2595%2586%25E5%259F%258E%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3Da4b04-d25f-4c2d-9766-a543f63e2ca9%26SignatureVersion%3D1.0%26TemplateCode%3DSMS_19****605%26TemplateParam%3D%257B%25**code%2522%253A%2522123456%2522%257D%26Timestamp%3D2020-11-27T03%253A30%253A13Z%26Version%3D2017-05-25
RequestId : 40A383BD-0C85-467A-BA00-0619****9BD4
我最后调试出的问题是secret错误,没有更新。
调试步骤
一、用官方Api调试测试签名、模板是否可用
二、把代码复制到本地,测试 accessKeyId、secret是否可用
package com.zyark.beautiful.shop.modules.generator.common;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "************************", "***************************");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setMethod(MethodType.POST);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("RegionId", "cn-hangzhou");
request.putQueryParameter("PhoneNumbers", "*******************");
request.putQueryParameter("SignName", "********");
request.putQueryParameter("TemplateCode", "*****************");
request.putQueryParameter("TemplateParam", "{\"code\":\"123456\"}");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}