我正在尝试使用MWS的PHP API获取我的履行清单。当我在暂存器上使用amazon提供的参数时,我得到了完美的答案,但是当我尝试使用我的代码时,它表示签名不匹配,我做错了什么?
<?php
$base_url = "https://mws.amazonservices.co.uk/FulfillmentInventory/2010-10-01";
$method = "POST";
$host = "mws.amazonservices.co.uk";
$uri = "/FulfillmentInventory/2010-10-01";
function amazon_xml() {
$params = array(
'AWSAccessKeyId' => "123456788",
'Action' => "ListInventorySupply",
'SellerId' => "234234123412341",
'SignatureVersion' => "2",
//'Timestamp'=> gmdate("Y-m-d\TH:i:s.Z", time()),
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version'=> "2010-10-01",
'SignatureMethod' => "HmacSHA256",
'SellerSkus.member.1' => '1EU-AMZ-FIRE-TV-MOUNT');
// 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 = "POST\nmws.amazonservices.co.uk\n/FulfillmentInventory/2010-10-01\n" . $url_string;
echo $string_to_sign."<br/>";
// Sign the request
$signature = hash_hmac("sha256", $string_to_sign, 'sdgsdfgsdfgsdgsdgsdg', TRUE);
echo $signature."<br />";
// Base64 encode the signature and make it URL safe
$signature = urlencode(base64_encode($signature));
echo $signature."<br />";
$url = "https://mws.amazonservices.co.uk/FulfillmentInventory/2010-10-01" . '?' . $url_string . "&Signature=" . $signature;
$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);
$response = curl_exec($ch);
echo "La respuesta es ".$response;
$parsed_xml = simplexml_load_string($response);
//return ($parsed_xml);
echo $parsed_xml;
}
amazon_xml();
?>
答案 0 :(得分:1)
您似乎按值对ksort($url_parts);
数组进行排序,您应该按键对其进行排序。
Merchant
我在代码中看不到任何其他系统问题。我的代码与您的代码不同的另一点是,我的代码使用的是SellerId
参数,而不是SellerId
- 我还没有检查使用{{1}}是否也能正常工作。