我想要一个“立即购买”链接,并且游戏产品的实际亚马逊价格与游戏名称一起获得。为此,我必须使用“按标题搜索”(http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_SearchingbyTitle.html)。
我找到了一个 XML-Request 的示例并尝试为我构建它。
示例是:
$AWSAccessKeyId = "";
$SecretAccessKey = "";
$ItemId = "0679722769"; // ASIN
$Timestamp = gmdate("Y-m-d\TH:i:s\Z");
$Timestamp = str_replace(":", "%3A", $Timestamp);
$ResponseGroup = "ItemAttributes,Offers,Images,Reviews";
$ResponseGroup = str_replace(",", "%2C", $ResponseGroup);
$String = "AWSAccessKeyId=$AWSAccessKeyId&
AssociateTag=xy&
ItemId=$ItemId&
Operation=ItemLookup&
ResponseGroup=$ResponseGroup&
Service=AWSECommerceService&
Timestamp=$Timestamp&
Version=2009-01-06";
$String = str_replace("\n", "", $String);
$Prepend = "GET\nwebservices.amazon.com\n/onca/xml\n";
$PrependString = $Prepend . $String;
$Signature = base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True));
$Signature = str_replace("+", "%2B", $Signature);
$Signature = str_replace("=", "%3D", $Signature);
$BaseUrl = "http://webservices.amazon.com/onca/xml?";
$SignedRequest = $BaseUrl . $String . "&Signature=" . $Signature;
$XML = simplexml_load_file($SignedRequest);
echo '<a href="'.$SignedRequest.'">XML</a><p>';
print_r ($XML);
这很完美,但不适用于我的搜索值。我编辑了参数并且请求被破坏了。
我的请求:
$AWSAccessKeyId = "";
$SecretAccessKey = "";
$ItemId = "Payday2"; // ASIN
$Timestamp = gmdate("Y-m-d\TH:i:s\Z");
$Timestamp = str_replace(":", "%3A", $Timestamp);
$ResponseGroup = "ItemAttributes";
$ResponseGroup = str_replace(",", "%2C", $ResponseGroup);
$String = "AWSAccessKeyId=$AWSAccessKeyId&
AssociateTag=xy&
Operation=ItemSearch&
SearchIndex=Game&
Title=$ItemId&
ResponseGroup=$ResponseGroup&
Service=AWSECommerceService&
Timestamp=$Timestamp&
Version=2009-01-06";
$String = str_replace("\n", "", $String);
$Prepend = "GET\nwebservices.amazon.com\n/onca/xml\n";
$PrependString = $Prepend . $String;
$Signature = base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True));
$Signature = str_replace("+", "%2B", $Signature);
$Signature = str_replace("=", "%3D", $Signature);
$BaseUrl = "http://webservices.amazon.com/onca/xml?";
$SignedRequest = $BaseUrl . $String . "&Signature=" . $Signature;
$XML = simplexml_load_file($SignedRequest);
echo '<a href="'.$SignedRequest.'">XML</a><p>';
print_r ($XML);
为什么我的请求不起作用?
谢谢