MWS在PHP中提供更新数量
这是几天,我试图通过php中的PHP和亚马逊MWS更新库存量(不使用MWS APIs,因为在我看来已经过时了)
这是我的代码:
$param = array();
$param['AWSAccessKeyId'] = $this->CHIAVE_ACCESSO;
$param['Action'] = 'SubmitFeed';
$param['Merchant'] = $this->SELLER_ID;
$param['FeedType'] = '_POST_INVENTORY_AVAILABILITY_DATA_';
$param['SignatureMethod'] = 'HmacSHA256';
$param['SignatureVersion'] = '2';
$param['Timestamp'] = gmdate("Y-m-dTH:i:s. Z", time());
$param['Version'] = '2009-01-01';
$params['MarketplaceId.Id.1'] = $this->MARCKETPLACE_IT;
$params['MarketplaceId.Id.2'] = $this->MARCKETPLACE_UK;
$params['MarketplaceId.Id.3'] = $this->MARCKETPLACE_ES;
$params['MarketplaceId.Id.4'] = $this->MARCKETPLACE_DE;
$params['MarketplaceId.Id.5'] = $this->MARCKETPLACE_FR;
$param['PurgeAndReplace'] = 'false';
foreach ($param as $key => $val) {
$key = str_replace("%7E", "~", rawurlencode($key));
$val = str_replace("%7E", "~", rawurlencode($val));
$url[] = "{$key}={$val}";
}
$amazon_feed = '<?xml version="1.0" encoding="utf-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>' .$this->SELLER_ID. '</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Inventory>
<SKU>'.$sku.'</SKU>
<Quantity>'.$qty.'</Quantity>
</Inventory>
</Message>
</AmazonEnvelope>';
sort($url);
$arr = implode('&', $url);
$sign = 'POST' . "n";
$sign .= 'mws.amazonservices.it' . "n";
$sign .= '/Feeds/'.$param['Version'].'' . "n";
$sign .= $arr;
$signature = hash_hmac("sha256", $sign, $this->secretKey, true);
$httpHeader = array();
$httpHeader[] = 'Transfer-Encoding: chunked';
$httpHeader[] = 'Content-Type: application/xml';
$httpHeader[] = 'Content-MD5: ' . base64_encode(md5($amazon_feed, true));
//$httpHeader[] = 'x-amazon-user-agent: MyScriptName/1.0';
$httpHeader[] = 'Expect:';
$httpHeader[] = 'Accept:';
$signature = urlencode(base64_encode($signature));
$link = "https://mws.amazonservices.it/Feeds/".$param['Version']."?";
$link .= $arr . "&Signature=" . $signature;
echo $link;
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$errors=curl_error($ch);
curl_close($ch);
echo '<pre>';
print_r($response); //xml response
答案是
50691017150_POST_INVENTORY_AVAILABILITY_DATA_2016-12-15T10:00:09 + 00:00_SUBMITTED_47843855-c5fb-4db9-bc3c-1ccd0aff4169
但是当我进入亚马逊库存时,我看不到任何更改。 我也试过等待几天,但没有任何变化。 我做错了什么?
预先感谢您的帮助!
使用MWS Scratchpad我遇到的错误如下
<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.02</DocumentVersion>
<MerchantIdentifier>A2PDC8GCZHAL2D</MerchantIdentifier>
</Header>
<MessageType>ProcessingReport</MessageType>
<Message>
<MessageID>1</MessageID>
<ProcessingReport>
<DocumentTransactionID>50691017150</DocumentTransactionID>
<StatusCode>Complete</StatusCode>
<ProcessingSummary>
<MessagesProcessed>1</MessagesProcessed>
<MessagesSuccessful>0</MessagesSuccessful>
<MessagesWithError>1</MessagesWithError>
<MessagesWithWarning>0</MessagesWithWarning>
</ProcessingSummary>
<Result>
<MessageID>1</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>13013</ResultMessageCode>
<ResultDescription>This SKU does not exist in the Amazon.com catalog. Your inventory data was not processed. For reasons why, and help fixing this, see http://sellercentral.amazon.it/gp/errorcode/13013</ResultDescription>
<AdditionalInfo>
<SKU>887235757035</SKU>
</AdditionalInfo>
</Result>
</ProcessingReport>
</Message>
但是这个sku存在于我的目录中
实际的响应总是来自MWS的XML,您可以在其中看到50691017150实际上是您的FeedSubmissionId 。
当您提交饲料时,MWS会给您一个FeedSubmissionId,通过它您可以跟踪您的饲料发生了什么。
如果你去MWS Scratchpad,你可以得到饲料结果。
在身份验证表单中输入所需的凭据,然后选择Feed作为Sezione AP和GetFeedSubmissionResult作为操作。
您将被要求提供您已有的FeedSubmissionId。 看看发生了什么事,为什么它失败?
您正在通过Marketplace Ids,这意味着sku在那里可用。 但在你的情况下,它可能不适用于其中任何一种。 MarketplaceId是可选的,您可以删除
$params['MarketplaceId.Id.1'] = $this->MARCKETPLACE_IT;
$params['MarketplaceId.Id.2'] = $this->MARCKETPLACE_UK;
$params['MarketplaceId.Id.3'] = $this->MARCKETPLACE_ES;
$params['MarketplaceId.Id.4'] = $this->MARCKETPLACE_DE;
$params['MarketplaceId.Id.5'] = $this->MARCKETPLACE_FR;
链接地址: http://www.djcxy.com/p/37613.html