使用亚马逊MWS API创建签名查询

时间:2017-10-18 21:59:56

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

我仍有与Make a signed query with Amazon API MWS相同的错误。

适用于mws.amazonservices.com。 但是mws.amazonservices.de不起作用。 我应该怎么做在欧洲或中国亚马逊上运行脚本。

这是我的代码。

function call_amz_mws($ api,$ version,$ p = array())     {

    $params = array(
         'AWSAccessKeyId' => AWS_ACCESS_KEY_ID,        
         'MWSAuthToken'=>MWSAuthToken,
         'SellerId' => MERCHANT_ID,
         'SignatureMethod' => "HmacSHA256",
         'SignatureVersion' => "2",
         'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
         'Version'=> $version,       
         'MarketplaceId' => MARKETPLACE_ID);


    foreach ($p as $key => $value) 
    {
        $params[$key]=$value;
    }     
    $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 = "GET\nmws.amazonservices.de\n/$api/$version\n" . $url_string;
    $signature = hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, TRUE);

    $signature = urlencode(base64_encode($signature));

    $url = "https://mws.amazonservices.de/$api/$version" . '?' . $url_string . "&Signature=" . $signature;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    
    curl_setopt($ch, CURLOPT_URL, $url);
    $response = curl_exec($ch);
    $parsed_xml = simplexml_load_string($response);
    return $parsed_xml;
}

0 个答案:

没有答案