gpt4 book ai didi

javascript - 参数时间戳无效。原因 : Must be in ISO8601 format in JavaScript

转载 作者:行者123 更新时间:2023-11-30 16:58:47 29 4
gpt4 key购买 nike

我正在尝试调用亚马逊的 RESTful API,但它似乎是一个糟糕的开始或其他什么!

我收到这条消息:

<ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2013-08-01/">
<Error>
<Code>InvalidParameterValue</Code>
<Message>
Value 2015-3-24T18:38:26Z for parameter Timestamp is invalid. Reason: Must be in ISO8601 format.
</Message>
</Error>
<RequestId>77d4ca11-4f95-42d2-b85a-a4042abded80</RequestId>
</ItemLookupErrorResponse>

这是 JavaScript 中的代码:

    var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1;
var year = today.getFullYear();
var hours = today.getHours() < 10 ? "0"+today.getHours() : today.getHours();
var seconds = today.getSeconds() < 10 ? "0"+today.getSeconds() : today.getSeconds();
var mins = today.getMinutes() < 10 ? "0"+today.getMinutes() : today.getMinutes();
var time = encodeURIComponent(year+"-"+month+"-"+day+"T"+hours+":"+mins+":"+seconds+"Z");
var messageToEncrypt ="GET\nwebservices.amazon.com\n\
/onca/xml\nAWSAccessKeyId=ACCESSID&ItemId=0679722769&&SignatureMethod=HmacSHA256&SignatureVersion=2&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp="+time+"&Version=2013-08-01";

var sig = CryptoJS.HmacSHA256(messageToEncrypt, "SECRET KEY");

var request = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=AccessID&Operation=ItemLookup&ItemId=0976925524&ResponseGroup=SalesRank&Version=2013-08-01&Timestamp="+time+"&Signature="+sig;


function GET(url) {
var oFrame = document.getElementById("MyAjaxFrame");
if (!oFrame) {
oFrame = document.createElement("iframe");
oFrame.style.display = "none";
oFrame.id = "MyAjaxFrame";
document.body.appendChild(oFrame);
}
oFrame.src = url;
}

GET(request);

这里有什么问题吗?谢谢。

最佳答案

您可能缺少月份和日期的前导零。您的值可能应该是 2015-03-24T18:38:26Z

就像评论中建议的@Bergi - 使用toISOString .

关于javascript - 参数时间戳无效。原因 : Must be in ISO8601 format in JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29238841/

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