【发布时间】:2021-11-05 17:49:27
【问题描述】:
我正在尝试连接到 API,但它们仅提供 Python 和 Javascript 指南。 我正在尝试找到 php 的等价物,但结果不足。
更多参考:https://docs.deribit.com/#authentication
我无法在 PHP 中获得正确的签名。
Javascript:
var timestamp = Date.now();
var nonce = "abcd";
var data = "";
var signature = CryptoJS.HmacSHA256(`${timestamp}\n${nonce}\n${data}`, accessSecret).toString();
Python:
timestamp = round(datetime.now().timestamp() * 1000)
nonce = "abcd"
data = ""
signature = hmac.new(
bytes(clientSecret, "latin-1"),
msg=bytes('{}\n{}\n{}'.format(timestamp, nonce, data), "latin-1"),
digestmod=hashlib.sha256
).hexdigest().lower()
PHP: (*我不知道如何创建随机数)
$timestamp = number_format(microtime(true) * 1000, 0, '.', '');
$nonce = number_format(microtime(true) * 1000, 0, '.', '');
$data = "";
$key = $timestamp.$nonce.$data;
$sign = hash_hmac('sha256',$key,$secret);
$sign = bin2hex($sign);
【问题讨论】:
-
对于 PHP,
$nonce = "abcd"; -
@KenLee - 这只是他们提供的一个示例。
-
@KenLee docs.deribit.com/#authentication
-
当然,您需要将
abcd更改为您想要的。 (我稍后会给你一个例子) -
什么确切不起作用?你有什么努力让它发挥作用?
标签: javascript python php api encryption