【问题标题】:AMAZON: Add to remote cart without leaving site亚马逊:无需离开站点即可添加到远程购物车
【发布时间】:2016-10-25 17:20:24
【问题描述】:

嘿,我正在尝试设置远程购物车。非常令人沮丧,因为亚马逊没有列出任何客户离开网站的远程购物车的代码示例。

这是我目前所处的位置。我可以让某人离开我的网站并将产品从我的网站添加到亚马逊使用这个(来自:http://docs.aws.amazon.com/AWSECommerceService/latest/DG/AddToCartForm.html):

<form method="GET" action="http://www.amazon.com/gp/aws/cart/add.html"> 
<input type="hidden" name="AWSAccessKeyId" value="Access Key ID" />     <br/> 
<input type="hidden" name="AssociateTag" value="Associate Tag" /><br/> 
<p>One Product<br/> 
ASIN:<input type="text" name="ASIN.1"/><br/> 
Quantity:<input type="text" name="Quantity.1"/><br/> 
<p>Another Product<br/> 
ASIN:<input type="text" name="ASIN.2"/><br/> 
Quantity:<input type="text" name="Quantity.2"/><br/> 
</p> 
<input type="submit" name="add" value="add" /> 
</form>

但我想这样做,以便他们可以将商品添加到购物车并留在我的网站上。看来这就是我实现这一目标的方式:

http://webservices.amazon.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
AssociateTag=[Associate Tag]&
Operation=CartCreate&
Item.1.OfferListingId=B000062TU1&
Item.1.Quantity=2
&Timestamp=[YYYY-MM-DDThh:mm:ssZ]
&Signature=[Request Signature]

但是当我完全不知道如何生成时间戳和签名时。我是否将其放入表单操作中?有代码示例的地方吗?我找了一天也没找到。非常感谢任何帮助。

【问题讨论】:

    标签: amazon-web-services amazon-product-api


    【解决方案1】:

    我正在使用这种方法来生成 api 请求 url,并且它完全可以正常工作。相信这会对你有所帮助

     $uri   = "/onca/xml";
     $asin  = "B00C5AHTC0";
     $end_point = "webservices.amazon.com";
    
              $params = array(
                "Service" => "AWSECommerceService",
                "Operation" => "CartCreate",
                'Version' => "2013-08-01",
                "AWSAccessKeyId" => AWS_ACCESS_KEY,
                "AssociateTag" => AWS_ASSOCIATE_TAG,
                "Item.1.ASIN" => $asin,
                "Item.1.Quantity" => "5",
                "Timestamp"=> gmdate('Y-m-d\TH:i:s\Z')
              );
    
            // Sort the parameters by key
            ksort($params);
    
            $pairs = array();
    
            foreach ($params as $key => $value) {
                array_push($pairs, rawurlencode($key) . "=" . rawurlencode($value));
            }
    
            // Generate the canonical query
            $canonical_query_string = join("&", $pairs);
            $string_to_sign         = "GET\n" . $end_point. "\n" . $uri . "\n" . $canonical_query_string;
            $signature              = base64_encode(hash_hmac("sha256", $string_to_sign, AWS_SECRET_KEY, true));
    
            $request_url            = 'http://' . $end_point. $uri . '?' .$canonical_query_string . '&Signature='.rawurlencode($signature); 
    

    【讨论】:

      猜你喜欢
      • 2012-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-13
      • 2016-10-11
      相关资源
      最近更新 更多