【发布时间】:2017-10-07 00:57:12
【问题描述】:
我确定我离得很近,但就在附近。我正在尝试使用 Bitfinex v2 API 返回我的钱包余额,但我不断收到“无效密钥”错误。
查看this question 后,我认为我的问题可能与此相关,但使用utf8_encode 更新我的代码并没有解决问题。
这是我第一次使用 cURL,所以我不太确定我是否正确设置了所有选项。
提前感谢您提供的任何帮助。
到目前为止我的代码(您必须相信 _APISECRET 和 _APIKEY 已设置):
CONST _APIPATH = "v2/auth/r/wallets";
CONST _APIURL = "https://api.bitfinex.com/";
$nonce = strval(time()*1000);
$body = json_encode(array());
$signature = '/api/' . _APIPATH . $nonce . $body;
$signature = hash_hmac('sha384', $signature, utf8_encode(_APISECRET));
$headers = array('bfx-nonce' => $nonce, 'bfx-apikey' => utf8_encode(_APIKEY), 'bfx-signature' => $signature, 'content-type' => 'application/json');
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_URL, _APIURL . _APIPATH);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_exec($ch);
curl_close($ch);
【问题讨论】:
-
这不是 javascript,PHP 字符串是二进制安全的,如果编码不正确,你从哪里获得这个 api 密钥?
-
API 密钥与我的帐户绑定(您可以从帐户界面中获取)。我确信我输入正确。
-
我刚刚发现
bfx-signature这个字符串必须是小写的。