**验证码:**此代码可以提交成功,并且可以使用Scratchpad工具获得正确的响应。但它最终不工作!我该如何修改?
我还使用Scratchpad工具测试了XML,它工作正常。
$file = 'test.xml';
$i = 1;
$sku = "xxxxx";
$new_price = 20.59;
$merchant_ID = Config("MERCHANT_ID");
$currency = "USD";
$feed = <<< EOD
<?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>$merchant_ID</MerchantIdentifier>
</Header>
<MessageType>Price</MessageType>
<Message>
<MessageID>$i</MessageID>
<Price>
<SKU>$sku</SKU>
<StandardPrice currency="$currency">$new_price</StandardPrice>
</Price>
</Message>
</AmazonEnvelope>
EOD;
$feedHandle = @fopen($file, 'w+');
fwrite($feedHandle, $feed);
rewind($feedHandle);
print_r(stream_get_contents($feedHandle));
$params = array(
'AWSAccessKeyId' => AWS_ACCESS_KEY_ID,
'Action' => "SubmitFeed",
'Merchant' => MERCHANT_ID,
'MWSAuthToken' => MWSAuthToken,
'SignatureVersion' => "2",
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version'=> "2009-01-01",
'SignatureMethod' => "HmacSHA256",
'FeedType' => '_POST_PRODUCT_PRICING_DATA_',
'MarketplaceIdList.Id.1' => MARKETPLACE_ID,
'PurgeAndReplace' => 'false',
'ContentMD5Value'=> base64_encode(md5(stream_get_contents($feedHandle), true)),
);
$url_parts = array();
foreach(array_keys($params) as $key)
$url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));
sort($url_parts);
$url_string = implode("&", $url_parts);
$string_to_sign = "POST\nmws.amazonservices.com\n/\n" . $url_string;
// Sign the request
$signature = hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, TRUE);
$signature = urlencode(base64_encode($signature));
$url = "https://mws.amazonservices.com/" . '?' . $url_string . "&Signature=" . $signature;
echo $url;
$md5 = base64_encode(md5(stream_get_contents($feedHandle), true));
$httpHeader=array();
$httpHeader[]='Transfer-Encoding: chunked';
$httpHeader[]='Content-type: text/xml';
$httpHeader[]='Content-MD5: ' . $md5;
$httpHeader[]='Expect:';
$httpHeader[]='Accept:';
$ch = curl_init($url);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_PORT , 443);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_USERAGENT, '<MWS_SubmitFeed>/<1.02> (Language=PHP/' . phpversion() . ')');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_UPLOAD,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$feedHandle);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
$response = curl_exec($ch);
var_dump($response);.
提交后,我得到如下响应:
<?xml version="1.0"?>
<SubmitFeedResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/">
<SubmitFeedResult>
<FeedSubmissionInfo>
<FeedSubmissionId>50624017558</FeedSubmissionId>
<FeedType>_POST_PRODUCT_PRICING_DATA_</FeedType>
<SubmittedDate>2018-01-27T14:03:39+00:00</SubmittedDate>
<FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus>
</FeedSubmissionInfo>
</SubmitFeedResult>
<ResponseMetadata>
<RequestId>ad455b8b-7959-451d-b914-fbe2d9cc5ac8</RequestId>
</ResponseMetadata>
</SubmitFeedResponse>
但是当我查看产品的价格时,价格没有变化。
有人能帮帮我吗
1条答案
按热度按时间kwvwclae1#
在亚马逊StandardPrice接受文本格式。
试试这个