转换亚马逊MWS暂存器查询API调用 [英] Converting amazon MWS scratchpad queries to API calls

查看:767
本文介绍了转换亚马逊MWS暂存器查询API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有转换我的亚马逊MWS 暂存器的方式查询的API呼叫

I want to know if there is a way to convert my Amazon MWS scratchpad queries to an API call

例如。使用MWS暂存器,当我给一个String签署

e.g. when using the MWS scratchpad I'm given a String to sign

   "mws.amazonservices.co.uk"
   ."/Products/2011-10-01"
   ."AWSAccessKeyId=xxx&Action=ListMatchingProducts"
   ."&MarketplaceId=xxx&Query=star%20wars&SellerId=xxx"
   ."&SignatureMethod=HmacSHA256&SignatureVersion=2
   ."&Timestamp=2012-07-27T18%3A59%3A30Z&Version=2011-10-01

消磨时间试图让<一后href=\"https://developer.amazonservices.com/gp/mws/api.html/192-8794163-0963027?ie=UTF8&group=orders&section=orders&version=latest\">Amazons为了API 工作,我已经放弃了,并一直希望下面的函数会返回一个XML字符串...但没有运气

After spending days trying to get Amazons order API to work I have given up and have been hoping that the following function would return an xml string...but with no luck

function callAmazon(){
    $apicall =  "mws.amazonservices.co.uk"
   ."/Products/2011-10-01"
   ."AWSAccessKeyId=xxx&Action=ListMatchingProducts"
   ."&MarketplaceId=xxx&Query=star%20wars&SellerId=xxx"
   ."&SignatureMethod=HmacSHA256&SignatureVersion=2
   ."&Timestamp=2012-07-27T18%3A59%3A30Z&Version=2011-10-01   

    $resp = simplexml_load_file($apicall);   //make the call
}

没有任何人有任何可能的建议?

does anyone have any possible suggestions?

推荐答案

我这个挣扎了很长一段时间为好,这里是我如何解决它的产品API:

I struggled with this for a long time as well, here is how I solved it for the Products API:

<?php
require_once('.config.inc.php');
$base_url = "https://mws.amazonservices.com/Products/2011-10-01";
$method = "POST";
$host = "mws.amazonservices.com";
$uri = "/Products/2011-10-01";

function amazon_xml($searchTerm) {

    $params = array(
        'AWSAccessKeyId' => AWS_ACCESS_KEY_ID,
        'Action' => "ListMatchingProducts",
        'SellerId' => MERCHANT_ID,
        'SignatureMethod' => "HmacSHA256",
        'SignatureVersion' => "2",
        'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
        'Version'=> "2011-10-01",
        'MarketplaceId' => MARKETPLACE_ID,
        'Query' => $searchTerm,
        'QueryContextId' => "Books");

    // 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.com\n/Products/2011-10-01\n" . $url_string;

    // Sign the request
    $signature = hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, TRUE);

    // Base64 encode the signature and make it URL safe
    $signature = urlencode(base64_encode($signature));

    $url = "https://mws.amazonservices.com/Products/2011-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);

    $parsed_xml = simplexml_load_string($response);

    return ($parsed_xml);
}

?>

.inc.config.php 文件包含了我的访问密钥,密钥等。

The .inc.config.php file contains my access key, secret key etc.

编辑:

$搜索关键词是ISBN我从我的形式传递。


$searchterm is the isbn I am passing from my form.

这篇关于转换亚马逊MWS暂存器查询API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆