嘿我正在尝试设置远程购物车。非常令人沮丧,因为亚马逊没有列出远程购物车的任何代码示例而没有客户离开网站。
这是我到目前为止的地方。我可以让某人离开我的网站并使用此网站将我的网站上的产品添加到亚马逊(来自: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]
但是当我对如何生成时间戳和签名感到困惑时。我把它放到表格动作中吗?有代码示例吗?我一整天都在搜索,找不到它。非常感谢任何帮助。
答案 0 :(得分:0)
我正在使用此方法生成api请求网址,并且它完全正常工作。相信这会对你有所帮助
$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);