调用发短信接口SingleSendSms, 总是返回这个信息,参数反复检验过很多次了,就是不行。{"Message":"Specified signature is not matched with our calculation.","RequestId":"1C2702F8-9890-41AE-B448-268A9DB09A06","HostId":"sms.aliyuncs.com","Code":"SignatureDoesNotMatch"}
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://sms.aliyuncs.com/");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
String signatureNonce = UUID.randomUUID().toString();
// String signatureNonce = "e1b44502-6d13-4433-9493-69eeb068e955";
System.out.println(signatureNonce);
String jsonParams = "{\"code\":\"{code}\"}".replace("{code}", "1234");
System.out.println(jsonParams);
String recNum = "15521282715";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss'Z'");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String timestamp = simpleDateFormat.format(new Date());
log.info("timestamp:"+timestamp);
//该签名方法返回的签名字符串是正确的,因为使用API文档里的参数调用后结果和文档里的一致。
String signature = getSignature(AccessKeyId, jsonParams, recNum, SignName, signatureNonce, TemplateCode, timestamp);
log.info("signature:"+signature);
NameValuePair[] data ={
new NameValuePair("Signature", signature)
,new NameValuePair("AccessKeyId", AccessKeyId)
,new NameValuePair("Action", Action)
,new NameValuePair("Format", Format)
,new NameValuePair("ParamString", jsonParams)
,new NameValuePair("RecNum", recNum)
// ,new NameValuePair("RegionId", RegionId)
,new NameValuePair("SignName", SignName)
,new NameValuePair("SignatureMethod", SignatureMethod)
,new NameValuePair("SignatureNonce", signatureNonce)
,new NameValuePair("SignatureVersion", SignatureVersion)
,new NameValuePair("TemplateCode", TemplateCode)
,new NameValuePair("Timestamp", timestamp)
,new NameValuePair("Version", Version)
};
post.setRequestBody(data);
client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
log.info("statusCode:"+statusCode);
String result = new String(post.getResponseBodyAsString().getBytes("utf-8"));
log.info("result:"+result);
post.releaseConnection();
这两个填写不对会报SignatureDoesNotMatch,我是拷贝过来时左右两边多了两个空格,去掉两边空格就解决了 $accessKeyId = "XXXXXXXXXXXXXXXXXXX"; $accessKeySecret = "XrXXXXXXXX7kzXXXXFXXXXXXXXXXFG"; 以下是我报错的填写 $accessKeySecret = " XrXXXXXXXX7kzXXXXFXXXXXXXXXXFG ";
少了下面这行 真是坑爹 我还是在开发者文档中找到的
//使用post提交
request.setMethod(MethodType.POST);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。