亚马逊卖家中心 MWS ListOrders GET 请求失败 "The request signature we calculated does not match the signature you provided."

Amazon Seller Central MWS ListOrders GET request fails with "The request signature we calculated does not match the signature you provided."

我正在尝试进行 GET 调用以从 Amazon 拉取订单,但我一直收到相同的签名错误。我用谷歌搜索了一下,发现很多人似乎都遇到了这个错误,但是 none 他们的解决方案似乎解决了我的问题。有什么想法吗?

我的请求码:

$MWS_Timestamp=GetUTCFormattedDateTime(Date(Now_()),'UTC',false);   // 2018-10-22T13:51:32Z
$MWS_AccessKey='AKIA****************';
$MWS_ClientSecret='ChOqu*************************';
$MWS_DeveloperID=798*********;
$MWS_SellerID='A3DL**********';
$MWS_MarketPlaceID='ATVP*********';
$MWS_AuthToken='amzn.mws.********-****-****-****-************';

$MWS_Action='ListOrders';
$MWS_RequestString="";
$MWS_RequestString+="AWSAccessKeyId="+UrlEncode($MWS_AccessKey,0);
$MWS_RequestString+="&Action="+UrlEncode("ListOrders",0);
$MWS_RequestString+="&LastUpdatedAfter="+UrlEncode('2018-10-21T00:00:00Z',0);
$MWS_RequestString+="&MarketplaceId.Id.1="+UrlEncode($MWS_MarketPlaceID,0);
$MWS_RequestString+="&SellerId="+UrlEncode($MWS_SellerID,0);
$MWS_RequestString+="&SignatureVersion="+UrlEncode("2",0);
$MWS_RequestString+="&SignatureMethod="+UrlEncode("HmacSHA1",0);
$MWS_RequestString+="&Timestamp="+UrlEncode($MWS_Timestamp,0);
$MWS_RequestString+="&Version=2013-09-01";
$MWS_SignatureString=$MWS_RequestString;

$signature='';
/* Creating signature with CryptoJS
var hmacsha1Data=CryptoJS.HmacSHA1($MWS_SignatureString,$MWS_ClientSecret);  //Also tried $MWS_AccessKey with the same results
var base64EncodeData=CryptoJS.enc.Base64.stringify(hmacsha1Data);
$signature=encodeURIComponent(base64EncodeData);
*/
RunScript("<TAG>Scripts/JS-CryptoJS_v3.12</TAG>");

$signature=Replace($signature,"+","%2B");
$signature=Replace($signature,"/","%2F");
$signature=Replace($signature,"=","%3D");

$MWS_Request=$MWS_RequestString+"&Signature="+$signature;

$MWS_URL='https://mws.amazonservices.com/Orders/2013-09-01?'+$MWS_Request;

回应:

<ErrorResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
  <Error>
    <Type>Sender</Type>
    <Code>SignatureDoesNotMatch</Code>
    <Message>
      The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
    </Message>
  </Error>
  <RequestID>54d6059b-9aa8-4d4f-a0b8-beb663599b25</RequestID>
</ErrorResponse>

我不知道哪一部分是错的。我仔细检查了凭据,但一切看起来都很好。

这些参数必须全部按词法顺序附加。

这是一个并非如此的例子。

$MWS_RequestString+="&SellerId="+UrlEncode($MWS_SellerID,0);
$MWS_RequestString+="&LastUpdatedAfter="+UrlEncode('2018-10-21T00:00:00Z',0);

实际 URL 中的顺序无关紧要,但如果您不按此顺序构建它们,那么您将无法计算出正确的签名——因为服务会在计算之前对它们进行排序它希望您发送的签名。

另外,你的签名编码有误

$signature=Replace($signature,"+","%20")

除了A-Z a-z 0-9应该只有3种可能:

+ becomes %2B
/ becomes %2F
= becomes %3D