开发者社区> 问答> 正文

短信接口SignatureDoesNotMatch

chenym_hi 2016-11-12 23:23:09 11243
          调用发短信接口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();
编解码 API
分享到
取消 提交回答
全部回答(8)
  • dqwjs
    2019-07-17 20:25:28

    我也遇到这个问题了,一直未解决呢!

    0 0
  • kkk2345
    2019-07-17 20:25:28

    这个问题解决了吗,我也出现了...

    0 0
  • babababa
    2019-07-17 20:25:28

    少了下面这行 真是坑爹 我还是在开发者文档中找到的
    //使用post提交
    request.setMethod(MethodType.POST);

    2 0
  • 830yun
    2019-07-17 20:25:28

    请问这个问题怎么解决的?

    0 0
  • 木易知秋
    2019-07-17 20:25:28

    accessKeyId和secretAccessKey填的不正确

    3 0
滑动查看更多
+ 订阅

了解行业+人工智能最先进的技术和实践,参与行业+人工智能实践项目

推荐文章
相似问题