1
我想轉換一個亞馬遜MWS暫存器飼料查詢到PHP的捲曲請求(更新價),但出現以下錯誤:亞馬遜MWS飼料到PHP捲曲的請求 - 更新價格
the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed
問題是我不知道如何將xml數據($ feed)包含到curl請求中。
該代碼適用於不需要提要的其他請求,但是如何將提要包含在請求中?
$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_token</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('php://temp', 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle);
$params = array(
'AWSAccessKeyId' => $this->awsAccessKeyId,
'Action' => "SubmitFeed",
'Merchant' => $this->sellerId,
'SignatureMethod' => "HmacSHA256",
'SignatureVersion' => "2",
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version'=> "2009-01-01",
'MarketplaceIdList.Id.1' => $this->markedplaceId,
'FeedType' => '_POST_PRODUCT_PRICING_DATA_',
//'FeedContent' => $feedHandle,
'PurgeAndReplace' => 'false', //Leave this PurgeAndReplace to false so that it want replace whole product in amazon inventory
//'Content-Md5' => base64_encode(md5(stream_get_contents($feedHandle), true))
);
$md5 = base64_encode(md5(stream_get_contents($feedHandle), true));
// Sort the URL parameters
$url_parts = array();
foreach(array_keys($params) as $key)
$url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));
sort($url_parts);
// Construct the string to sign
$url_string = implode("&", $url_parts);
$string_to_sign = "GET\nmws.amazonservices.de\n/Feeds/2009-01-01\n" . $url_string;
// Sign the request
$signature = hash_hmac("sha256", $string_to_sign, $this->awsSecretAccessKey, TRUE);
// Base64 encode the signature and make it URL safe
$signature = urlencode(base64_encode($signature));
$url = "https://mws.amazonservices.de/Feeds/2009-01-01" . '?' . $url_string . "&Signature=" . $signature;
//var_dump($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml',
'Content-MD5: '.$md5,
'FeedContent: '.$feedHandle
)
);
$response = curl_exec($ch);
$parsed_xml = simplexml_load_string($response);
return $parsed_xml;