php - 向 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×tamp='.time()*1000;
$signature = hash_hmac('SHA256', $timestamp, $secret);
$url = 'https://api.binance.com/sapi/v1/accountSnapshot?'.$timestamp.'&signature='.$signature;
解决方案
当您向查询添加附加参数时,您还需要将其插入到签名中。
所以你需要把整个查询字符串放在签名里面
type=SPOT&'.$timestamp
推荐阅读
- android - 有没有办法通过 Android 应用程序中的 StringRequest URL 访问 AWS RDS 数据库?
- mongodb - 使用 MongoDB 时获取组 _id 的数组
- c++ - tensorflow 中 SpatialConvolution 实现的性能
- android - com.rnfs.RNFSManager.mkdir:java.lang.Exception:无法创建目录
- java - 当我已经创建布局时,如何修复“无法解析符号 activity_home”?
- visual-studio - 如何正确链接 MSVC 库
- go - GoLand(JetbBrains)在运行时要求提示不起作用
- android - 由于打开的对话框,应用程序在初始化期间崩溃
- laravel-7 - 应用程序复制到不同的文件夹
- java - “整数太长”当我的方法需要很长时间时出错(Java)