将参数添加到 Binance GET url 给出签名错误

Adding parameters to Binance GET url gives signature error

当我将参数添加到任何 GET url 时获得 -1022 Signature for this request is not valid.,即使我通过他们的 developer faq 遵循正确的位置,其中声明将参数放在第一位并放在 have timestamp and signature (in this order) as the last parameters。我很容易从 urls 获得结果,除了 timestamp/signature.

不需要任何其他参数
$timestamp = 'timestamp='.time()*1000;
$signature = hash_hmac('SHA256', $timestamp, $secret);
$url = 'https://api.binance.com/sapi/v1/accountSnapshot?type=SPOT&'.$timestamp.'&signature='.$signature;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$key));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);

$result = curl_exec($ch);

$result = json_decode($result, true);

print_r($result);

编辑解决方案

$timestamp = 'type=SPOT&timestamp='.time()*1000;
$signature = hash_hmac('SHA256', $timestamp, $secret);
$url = 'https://api.binance.com/sapi/v1/accountSnapshot?'.$timestamp.'&signature='.$signature;

当您向查询添加附加参数时,您还需要将其插入到签名中。

所以你需要在整个查询字符串中签名

type=SPOT&'.$timestamp