我正在try 调用批处理getItemOffersBatch 使用PHP和curl来签名和进行调用--我可以单独调用getItemOffers,没有任何问题. 我运行了一个批处理2,我得到了一个403 Forbidden错误-这里是代码(PHP 8):

json_encode($body, JSON_THROW_ON_ERROR);
$post = 'POST';
$body=json_encode($body, JSON_UNESCAPED_SLASHES);
//var_dump($body);
$urlbatch= "https://sellingpartnerapi-na.amazon.com/batches/products/pricing/v0/itemOffers". $body ;
//var_dump($urlbatch);
$ch = curl_init($urlbatch);
curl_setopt_array($ch, [CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true
,CURLOPT_CONNECTTIMEOUT => 5,]);
//  var_dump($header);
if ($post) curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
if ($header) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('curl.log', 'a+'));
$out = curl_exec($ch);
if (curl_errno($ch)) exit('Error: ' . curl_error($ch));
if ($status !== null) $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $out

* 是有效的私有亚马逊数据. 在与亚马逊和使用POSTMAN来回之后,我让它在POSTMAN中工作,但我很难正确添加数据部分,这里是POSTMAN的代码.

curl --location 'https://sellingpartnerapi-na.amazon.com/batches/products/pricing/v0/itemOffers' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-amz-access-token: ****' \
--header 'Authorization: AWS4-HMAC-SHA256 Credential=****/20240110/us-east-1/execute-api/aws4_request,SignedHeaders=host;user-agent;x-amz-access-token;x-amz-date,Signature=******' \
--data '{
"requests": [
    {
        "uri": "/products/pricing/v0/items/B000P6Q7MY/offers",
        "method": "GET",
        "MarketplaceId": "ATVPDKIKX0DER",
        "ItemCondition": "New",
        "CustomerType": "Consumer"
    },
    {
        "uri": "/products/pricing/v0/items/B001Q3KU9Q/offers",
        "method": "GET",
        "MarketplaceId": "ATVPDKIKX0DER",
        "ItemCondition": "New",
        "CustomerType": "Consumer"
    }
]

}‘

我try 将数据添加到

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

但这不管用,任何帮助都好,我差不多有了.

推荐答案

这就是答案--有时候简单是最好的

 $canonicalRequest = $method . "\n" // HTTP method
. $path . "\n" //  Path component of the URL
. $qs . "\n" // Query string component of the URL (without '?')
. 'host:' . HOST . "\n" // Header
. 'user-agent:' . USER_AGENT . "\n" // Header
. 'x-amz-access-token:' . $accessToken . "\n" // Header
. 'x-amz-date:' . $date . "\n" // Header
. "\n" // A newline is needed here after the headers
. 'host;user-agent;x-amz-access-token;x-amz-date' . "\n" // Header names
. hash('sha256', $data); // Hash of the payload (empty string okay)

function httpRequest($url,  $post = '', $header = null, &$status = null) {
$ch = curl_init($url);

curl_setopt_array($ch, [
    CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2,
    CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CONNECTTIMEOUT => 5,
]);
if ($post) curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
if ($header) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('curl.log', 'a+'));

$out = curl_exec($ch);

if (curl_errno($ch)) exit('Error: ' . curl_error($ch));
if ($status !== null) $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $out;

}

没有将数据放入canonicalRequest中,因此它可以通过散列

Php相关问答推荐

Nginx重写扩展名为.php的动态URL

如何删除WordPress用户的个人资料描述或其他个人资料字段中的链接?

如何修复警告:当使用WordPress get_the_Terms()时,Foreach()参数必须是ARRAY|OBJECT类型?

WHERE方法不能与有效查询Laravel一起使用

Symfony 6.2 IsGraned具有多个角色

Chillerlan/php-iOS名称字段的QR vCard错误

如何在execute语句中使用存储过程参数?

如何将WooCommerce产品从一个产品复制到另一个产品S

使用随机生成器在MYSQL中创建唯一ID-定义一个数组来存储已知ID是否安全

函数存储到变量中

从WooCommerce订单项目获取Dokan卖家详细信息

ANTLR4-lexer如何消耗更多的 token 并停止现有规则?

使用 php Carbon 获取两个日期之间的随机日期和时间

在 WooCommerce 中应用优惠券时显示购物车商品折扣金额

如何正确判断 PHP 是否已正确配置为使用 DOMDocument?

由于 PHP 版本不受支持,如何终止 PHP 脚本?

Laravel 添加到经过身份验证的用户的数据将应用于每个查询

如何将文件上传添加到 WooCommerce 结帐?

htaccess Rewriterule 无法以任何方式工作

PHP:如何将多列sql查询结果转换成数组