0

我下载了Product Advertising PHP Soap Library并浏览了示例代码。我在 sampleSettings.php 文件中配置了 'AWS_API_KEY'、'AWS_API_SECRET_KEY'、'AWS_ASSOCIATE_TAG'、'AWS_ANOTHER_ASSOCIATE_TAG' 的值。尝试访问“sampleItemSearch.php”时,我的浏览器中出现以下错误。

SOAP 错误:解析 WSDL:无法从“ http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl ”加载:需要开始标记,未找到“<”

我试图从链接获得帮助:https ://forums.aws.amazon.com/thread.jspa?messageID=270273但它没有用。

注意:我尝试在浏览器中运行以下 url 并得到以下输出:

$request="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AssociateTag=ASSOCIATETAG01-20&AWSAccessKeyId=MY_ACCESS_KEY_ID&Operation=ItemSearch&Version=2011-08-01&SearchIndex=Books&Keywords=harry%20potter&Timestamp=2013-04-10T12%3A44%3A42.000Z&Signature=ASasd5645AdSG878asdHsaHJ9YTefl1F6i0%3D";

请建议我应该做什么。

4

1 回答 1

1

我终于解决了。下面提到的代码工作正常。

    AWSAccessKeyId   = "*******************";
    $SecretAccessKey = "******************************";
    $AssociateTag    = "***************";

    $ItemId = '****'; //10 or 13 digit isbn
    $Timestamp = gmdate("Y-m-d\TH:i:s\Z");
    $Timestamp = str_replace(":", "%3A", $Timestamp);
    $ResponseGroup = "ItemAttributes,Images";
    $ResponseGroup = str_replace(",", "%2C", $ResponseGroup);


    $String = "AWSAccessKeyId=$AWSAccessKeyId&AssociateTag=$AssociateTag&IdType=ISBN&ItemId=$ItemId&Operation=ItemLookup&ResponseGroup=$ResponseGroup&SearchIndex=Books&Service=AWSECommerceService&Timestamp=$Timestamp&Version=2011-08-01";

    $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);

    print_r($xml); // output
于 2013-07-27T05:46:13.957 回答