我正在使用亚马逊Product Advertising API。我正在使用CartCreate operation创建一个远程购物车,并在其中添加两个项目。
这是我的CartCreate操作:
http://webservices.amazon.com/onca/xml?
AWSAccessKeyId=12AWSAccessKey12
AssociateTag=myweb-no
Item.1.ASIN=erq1
Item.1.Quantity=1
Operation=CartCreate
Service=AWSECommerceService
Timestamp=timeanddate
Signature=generatedsignature
答案 0 :(得分:0)
这是一个XML over HTTP API,所以你得到的是XML。以下是一个示例回复:
<Cart>
<Request>
<IsValid>True</IsValid>
<CartCreateRequest>
<Items>
<Item>
<ASIN>B000062TU1</ASIN>
<Quantity>2</Quantity>
</Item>
</Items>
</CartCreateRequest>
</Request>
<CartId>102-5014548-4857758</CartId>
<HMAC>O2p9hhZwJShnp6ZDWvZDO6FhpAI=</HMAC>
<URLEncodedHMAC>O2p9hhZwJShnp6ZDWvZDO6FhpAI=</URLEncodedHMAC>
<PurchaseURL>https://www.amazon.com/gp/cart/aws-merge.html?cart-id=102-5014548-4857758%26associate-id=ws%26hmac=O2p9hhZwJShnp6ZDWvZDO6FhpAI=%26AWSAccessKeyId=1VMEXAMPLEW9C02</PurchaseURL>
<SubTotal>
<Amount>1994</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$19.94</FormattedPrice>
</SubTotal>
<CartItems>
<SubTotal>
<Amount>1994</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$19.94</FormattedPrice>
</SubTotal>
<CartItem>
<CartItemId>U31XY1DHZEGCTB</CartItemId>
<ASIN>B000062TU1</ASIN>
<Quantity>2</Quantity>
<Title>Harry Potter and the Sorcerer's Stone (Full Screen Edition) (Harry Potter 1)</Title>
<ProductGroup>DVD</ProductGroup>
<Price>
<Amount>997</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$9.97</FormattedPrice>
</Price>
<ItemTotal>
<Amount>1994</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$19.94</FormattedPrice>
</ItemTotal>
</CartItem>
</CartItems>
</Cart>
您需要从上面的响应中获取购买网址,并在您的网站上创建一个链接,以允许用户访问亚马逊以完成购买。示例响应中的购买URL如下所示
<PurchaseURL>https://www.amazon.com/gp/cart/aws-merge.html?cart-id=102-5014548-4857758%26associate-id=ws%26hmac=O2p9hhZwJShnp6ZDWvZDO6FhpAI=%26AWSAccessKeyId=1VMEXAMPLEW9C02</PurchaseURL>
您也可以使用HTML Add to cart form来创建远程购物车。这是一种更基本的做事方式,但它会减少您的控制权,因为当您发布此表单时,用户将直接进入亚马逊网站。以下是一个示例表单:
<form method="GET" action="https://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>