我正在尝试为 API coinbase.com 编写请求,但无法正确生成签名。两天来我一直试图找出我的错误,但我做不到。我分析了页面上其他语言的代码:https ://developers.coinbase.com/docs/wallet/api-key-autumnicathion ,但我看不出在实现上有任何差异。
请帮帮我。
<?php
$g_coinbase_key = 'KcxisxqmWRVgtwsj';
$g_coinbase_secret = 'isOLGBLaEkCy3ROQMvmjonGmXK0KRmUS';
$time = time();
$method = "GET";
$path = '/v2/accounts/';
$sign = base64_encode(hash_hmac("sha256", $time.$method.$path, $g_coinbase_secret));
$ch = curl_init('https://api.coinbase.com'.$path);
$headers = array(
"CB-VERSION: 2017-10-26",
"CB-ACCESS-SIGN: ".$sign,
"CB-ACCESS-TIMESTAMP: ".$time,
"CB-ACCESS-KEY: ".$g_coinbase_key,
"Content-Type: application/json"
);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
var_dump($result);
?>
结果:
{"errors":[{"id":"authentication_error","message":"invalid signature"}]}