首页 > 解决方案 > 向 Binance GET url 添加参数会导致签名错误

问题描述

当我向任何 GET url 添加参数时得到-1022 Signature for this request is not valid.,即使我通过他们的开发人员常见问题解答正确放置,其中声明将参数放在首位和have timestamp and signature (in this order) as the last parameters. 除了时间戳/签名之外,我可以从不需要任何其他参数的 url 获取结果。

$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;

标签: phpcurlbinance

解决方案


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

所以你需要把整个查询字符串放在签名里面

type=SPOT&'.$timestamp

推荐阅读