gpt4 book ai didi

php - 亚马逊产品 API 返回 "SignatureDoesNotMatch"

转载 作者:可可西里 更新时间:2023-11-01 00:16:50 25 4
gpt4 key购买 nike

我想编写应用程序以通过 ISBN(用于慈善计划)获取书籍封面。所以我决定使用亚马逊产品 API。我得到了访问 key 和 secret key 。我得到了一个用于生成 key 的代码,我传递了 URL,但它返回的是那样

<?xml version="1.0"?>
<ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2005-10-05/">
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated
does not match the signature you provided.
Check your AWS Secret Access Key and signing method.
Consult the service documentation for details.
</Message></Error><RequestID>6c60b8b7-8b78-4f21-bb7c-3d5d3a26dc48</RequestID>
</ItemLookupErrorResponse>

这是代码

<?php
$AWSAccessKeyId = "*******ACCESS KEY***************";



$signature = base64_encode(hash_hmac('sha256',$string_to_sign,"******SECRET KEY*******",true));
// encode any plus (+), equal (=), or other reserved characters in $signature
$signature = str_replace('%7E','~',rawurlencode($signature));

$url = "http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=".$AWSAccessKeyId."&IdType=ASIN&ItemId=1933988355&Operation=ItemLookup&ResponseGroup=Medium%2COffers&Service=AWSECommerceService&Timestamp=".gmdate('Y-m-d\TH:i:s\Z')."&Signature=".$signature;

echo $url;
?>

这段代码有什么问题?

更新:

我尝试使用相同的时间戳。仍然没有运气。这是示例代码。

$method = "GET";
$host = "ecs.amazonaws.".$region;
$uri = "/onca/xml";

// additional parameters
$params["Service"] = "AWSECommerceService";
$params["AWSAccessKeyId"] = $public_key;
// GMT timestamp
$params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
// API version
$params["Version"] = "2009-03-31";

// sort the parameters
ksort($params);

// create the canonicalized query
$canonicalized_query = array();
foreach ($params as $param=>$value)
{
$param = str_replace("%7E", "~", rawurlencode($param));
$value = str_replace("%7E", "~", rawurlencode($value));
$canonicalized_query[] = $param."=".$value;
}
$canonicalized_query = implode("&", $canonicalized_query);

// create the string to sign
$string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;

// calculate HMAC with SHA256 and base64-encoding
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));

// encode the signature for the request
$signature = str_replace("%7E", "~", rawurlencode($signature));

最佳答案

从时间戳创建一个变量以在 $string_to_sign 和 url 参数中使用它,否则可能会发生两个时间戳不同的情况。要提供更多帮助,您需要显示 $string_to_sign 的创建。

此外:Timestamp 参数也需要进行 urlencoded。

也许这对您有用:http://mierendo.com/software/aws_signed_query/

关于php - 亚马逊产品 API 返回 "SignatureDoesNotMatch",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6235264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com