gpt4 book ai didi

php - 亚马逊 MWS 订单 API 时间戳必须遵循 ISO8601

转载 作者:可可西里 更新时间:2023-11-01 12:54:14 31 4
gpt4 key购买 nike

我正在使用亚马逊 MWS 订单 API (ListOrders),我可以在亚马逊 Scratchpad 上成功运行它,但我收到以下错误

Sender
MalformedInput
timestamp must follow ISO8601

下面是我从一些 Stackoverflow 帖子中得到的 php 脚本

$base_url = "https://mws.amazonservices.com/Orders/2013-09-01";
$method = "POST";
$host = "mws.amazonservices.com";
$uri = "/Orders/2013-09-01";

$params = array(
'AWSAccessKeyId' => "AWSAccessKeyId",
'Action' => "ListOrders",
'SellerId' => "SellerId",
'SignatureMethod' => "HmacSHA256",
'SignatureVersion' => "2",
//'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Timestamp'=> gmdate("Y-m-d\TH:i:s\Z", time()),
'Version'=> "2013-09-01",
'MarketplaceId' => "MarketplaceId",
'CreatedAfter'=>'2014-07-06T19%3A00%3A00Z',
'CreatedBefore'=>'2014-07-08T19%3A00%3A00Z'
);

// Sort the URL parameters
$url_parts = array();
foreach(array_keys($params) as $key)
$url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));

sort($url_parts);

// Construct the string to sign
$url_string = implode("&", $url_parts);
$string_to_sign = "GET\nmws.amazonservices.com\n/Orders/2013-09-01\n" . $url_string;

// Sign the request
$signature = hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, TRUE);

// Base64 encode the signature and make it URL safe
$signature = urlencode(base64_encode($signature));

$url = "https://mws.amazonservices.com/Orders/2013-09-01" . '?' . $url_string . "&Signature=" . $signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);

$parsed_xml = simplexml_load_string($response);
print '<pre>';
print_r($response);

谁能帮我找出错误?

最佳答案

您要发送三个日期值:

'Timestamp'=> gmdate("Y-m-d\TH:i:s\Z", time()),
'CreatedAfter'=>'2014-07-06T19%3A00%3A00Z',
'CreatedBefore'=>'2014-07-08T19%3A00%3A00Z'

首先,您可以去掉 gmdate() 的第二个参数,因为无论如何它默认为 time()。除此之外它很好,不应该是你的问题的原因。

其他两个参数具有 url 编码字符(冒号编码为 %3A),然后您通过 rawurlencode() 发送这些字符以再次编码。这将用 %25 替换上面编码的百分号。因此,您实际发送给亚马逊的 CreatedAfterCreatedAfter 值是 2014-07-06T19%253A00%253A00Z。试试这个:

'Timestamp'=> gmdate("Y-m-d\TH:i:s\Z"),
'CreatedAfter'=>'2014-07-06T19:00:00Z',
'CreatedBefore'=>'2014-07-08T19:00:00Z'

关于php - 亚马逊 MWS 订单 API 时间戳必须遵循 ISO8601,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24651819/

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