亚马逊MWS SubmitFeed错误:密​​钥可能不包含<

时间:2015-06-09 10:25:09

标签: php curl amazon-web-services amazon amazon-mws

我在向亚马逊MWS提交Feed时遇到问题。我一直收到以下错误:“Invalid query string provided - Keys may not contain <

这是我的代码:

$apicall = $this->build_url($function, $params);
$ch = curl_init($apicall);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
if ($this->xml) {
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, (string)$this->xml);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: text/xml"));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-MD5: " . base64_encode(md5($this->xml))));
}
else {
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
$info = print_r(curl_getinfo($ch), true);
curl_close($ch);

$apicall是即时形成的,其形式为:

https://mws.amazonservices.com/Feeds/2009-01-01?ASINList.ASIN.1=B00C5XBAOA&AWSAccessKeyId=***&Action=SubmitFeed&FeedType=_POST_PRODUCT_PRICING_DATA_&MWSAuthToken=***&SellerId=***&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2015-06-09T09%3A58%3A01.000Z&Version=2009-01-01&Signature=***

(适用于其他对Reports或订单的调用)

$this->xml在MySQL数据库中保留为“TEXT”字段;这是一个示例XML(我添加了一行以使其可读):

<?xml version="1.0"?>
<AmazonEnvelope xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="amzn-envelope.xsd">
    <Header>
        <DocumentVersion>1.01</DocumentVersion>
        <MerchantIdentifier>***</MerchantIdentifier>
    </Header>
    <MessageType>Price</MessageType>
    <Message>
        <MessageID>1</MessageID>
        <OperationType>Update</OperationType>
        <Price>
            <SKU>***</SKU>
            <StandardPrice currency="USD">33.5</StandardPrice>
        </Price>
    </Message>
</AmazonEnvelope>

我似乎在审查互联网上的每一个相关链接,但找不到答案。

也许有人可以给我一个暗示上面代码可能出错的地方?

感谢。

1 个答案:

答案 0 :(得分:0)

自己找到解决方案(在挖掘了一天之后):

1)Content-MD5必须按以下方式计算:

base64_encode(md5($this->xml, **true**));

(感谢这个回答:https://sellercentral.amazon.com/forums/message.jspa?messageID=2767745

2)将头参数传递给cUrl必须是一次性操作,即 - 所有头都必须作为数组传递。