我是Java的新手,为了让我的应用程序“发布”对亚马逊MWS API的HTTP请求,已经停留了几天。我一直收到“ SignatureDoesNotMatch”响应,但我不知道为什么。我已经广泛使用了亚马逊的MWS暂存器,使用它我没有任何麻烦可以成功获得响应,因此我的钥匙等还可以。暂存器生成的内容参数和base64签名与我的应用程序生成的内容匹配,因此我确信我的应用程序正确地编译了参数和签名。当我将暂存器生成的内容参数硬编码到应用程序中时,会收到“ SignatureDoesNotMatch”错误响应。我将非常感谢经验丰富的Java开发人员或开发了像我的应用程序那样在亚马逊MWS上工作的任何人提供的指导。

我的代码的相关部分是:

/*
 * get amazon timestamp
 */
GetAmazonTimestamp timestampObj = new GetAmazonTimestamp();
String amazonTimestamp = null;
try {
    amazonTimestamp = timestampObj.getTimestamp();
    amazonTimestamp.replace(".000Z", "Z");
} catch (IOException e) {
    e.printStackTrace();
}

/*
 *  create http parameters and initialise the signature value
 */
String URLendpoint =  "https://mws.amazonservices.co.uk/orders/2011-01-01";

String param1 = "AWSAccessKeyId";       String value1 = "AKIAIZXBKLVSGBBQQL2A";
String param2 = "Action";               String value2 = "ListOrders";
String param3 = "LastUpdatedAfter";     String value3 = "2013-02-01T00:00:00Z";
String param4 = "MarketplaceId.Id.1";   String value4 = "A1F83G8C2ARO7P";
String param5 = "SellerId";             String value5 = "A3A2272JFHXROO";
String param6 = "SignatureMethod";      String value6 = "HmacSHA256";
String param7 = "SignatureVersion";     String value7 = "2";
String param8 = "Timestamp";            String value8 = amazonTimestamp;
String param9 = "Version";              String value9 = "2011-01-01";
String param10 = "Signature";           String value10 = null;

/*
 *  build sections of URL components for signature
 */
String URLforSignature = "POST\n" + "mws.amazonservices.co.uk\n" + "/Orders/2011-01-01\n" +
    URLEncoder.encode(param1,"UTF-8") + "=" +
    URLEncoder.encode(value1,"UTF-8") + "&" +
    URLEncoder.encode(param2,"UTF-8") + "=" +
    URLEncoder.encode(value2,"UTF-8") + "&" +
    URLEncoder.encode(param3,"UTF-8") + "=" +
    URLEncoder.encode(value3,"UTF-8") + "&" +
    URLEncoder.encode(param4,"UTF-8") + "=" +
    URLEncoder.encode(value4,"UTF-8") + "&" +
    URLEncoder.encode(param5,"UTF-8") + "=" +
    URLEncoder.encode(value5,"UTF-8") + "&" +
    URLEncoder.encode(param6,"UTF-8") + "=" +
    URLEncoder.encode(value6,"UTF-8") + "&" +
    URLEncoder.encode(param7,"UTF-8") + "=" +
    URLEncoder.encode(value7,"UTF-8") + "&" +
    URLEncoder.encode(param8,"UTF-8") + "=" +
    URLEncoder.encode(value8,"UTF-8") + "&" +
    URLEncoder.encode(param9,"UTF-8") + "=" +
    URLEncoder.encode(value9,"UTF-8");

/*
 * hash and base64 encode the signature using the URLforSignature
 */
GetAmazonSignature signatureObj = new GetAmazonSignature();
value10 = signatureObj.getSignature(URLforSignature);

/*
 * create the http post
 */
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(URLendpoint);

String line = null;

try {
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    post.addHeader("Content-Type", "application/x-www-form-urlencoded");
    nameValuePairs.add(new BasicNameValuePair(param1, value1));
    nameValuePairs.add(new BasicNameValuePair(param2, value2));
    nameValuePairs.add(new BasicNameValuePair(param3, value3));
    nameValuePairs.add(new BasicNameValuePair(param4, value4));
    nameValuePairs.add(new BasicNameValuePair(param5, value5));
    nameValuePairs.add(new BasicNameValuePair(param6, value6));
    nameValuePairs.add(new BasicNameValuePair(param7, value7));
    nameValuePairs.add(new BasicNameValuePair(param8, value8));
    nameValuePairs.add(new BasicNameValuePair(param9, value9));
    nameValuePairs.add(new BasicNameValuePair(param10, value10));

    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));

    HttpResponse response = client.execute(post);
    BufferedReader rd = new BufferedReader(new InputStreamReader(
            response.getEntity().getContent()));
    line = "";

    while ((line = rd.readLine()) != null) {
        System.out.println(line);
    }
}


谢谢你的帮助。

最佳答案

感谢那些为我提供帮助的人,但是我最终得出结论,“ https://mws.amazonservices.co.uk/orders/2011-01-01”在订单中需要大写的“ O”。亚马逊的开发支持人员同意,在这种情况下,“ SignatureDoesNotMatch”错误消息不是很有帮助,并表示会进行调查。

再次感谢

关于java - 计算的Amazon MWS签名不匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14818860/

10-11 16:49