将Bitstamp API Python示例代码转换为Laravel/PHP SHA256算法



根据此处的Bitstamp API文档https://www.bitstamp.net/api/以下Python代码可用于生成SHA256签名:

import hmac
import hashlib
message = nonce + customer_id + api_key
signature = hmac.new(
API_SECRET,
msg=message,
digestmod=hashlib.sha256
).hexdigest().upper()

我正在尝试将Laravel/PHP与GuzzleHttp客户端一起使用来做同样的事情。我的代码是:

$client  = new GuzzleHttpClient();
$nonce = time();
$message = $nonce . $bitstamp_customer_id . $bitstamp_api_key;
$signature = strtoupper(hash_hmac("sha256", $message, $bitstamp_api_secret));
$response = $client->request('POST', 'https://www.bitstamp.net/api/v2/balance/', [
'form_params' => [
'key' => $bitstamp_api_key,
'signature' => $signature,
'nonce' => $nonce,
]
]);

无论我尝试什么,我都会得到:

Client error:帖子https://www.bitstamp.net/api/v2/balance/resulted in a403身份验证失败response: {"status": "error", "reason": "API key not found", "code": "API0001"}

我已经检查了三个关键的Bitstamp参数,并多次重新创建API键。我反复检查的三个参数是:

  • bitstamp_customer_id
  • bitstamp_api_key
  • bitstamp_api_secret

我的结论是我没有正确翻译Python代码,希望得到一些帮助。

哦,天哪,我不得不按下绿色的"激活"按钮并通过电子邮件确认。

最新更新