<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
</head>
<body>
<script>
let apikey = '';
let secretKey = "";
var serverTime = new Date().getTime() + 1000;
var urlStr = "timestamp="+serverTime+"&recvWindow=1000";
function sha256Sign(secretKey, data) {
const dataBytes = CryptoJS.enc.Utf8.parse(data);
const hash = CryptoJS.HmacSHA256(dataBytes, secretKey);
const signature = hash.toString(CryptoJS.enc.Hex);
return signature;
}
let data = JSON.stringify(urlStr);
let signature = sha256Sign(secretKey, data);
var url = 'https://fapi.binance.com/fapi/v3/account?'+urlStr+"&signature="+signature;
console.log("===========v:"+url);
$.ajax({
url: url,
type: 'GET',
headers: {
'X-MBX-APIKEY': apikey
},
success: function (response) {
console.log('success:', response);
},
error: function (error) {
console.log('fail:', error);
}
});
</script>
</body>
</html>
刚开始是提示Timestamp for this request is outside of the recvWindow.通过增加1000ms解决了,但是现在一直提示-1022 Signature for this request is not valid.,检查了apiKey正常,headers也带了,参数顺序也检查了,没发现异常。
请各位大佬帮忙指导下