我正在尝试通过 Coinbase Exchange 私有 API 进行身份验证以获取余额和下/取消订单。下面是我尝试使用的代码的演示版本。我已关注文档,但我不断收到以下错误:
{"message":"invalid signature"}
有人可以告诉我我做错了什么吗?:)
编辑:我已经根据 Sašo 的回答修改了下面的代码,所以它现在可以工作了。
<?php
$key = "";
$secret = "";
$passphrase = "";
$time = time();
$url = "https://api.gdax.com/accounts";
$data = $time."GET"."/accounts";
echo $data . "<br/>";
$sign = base64_encode(hash_hmac("sha256", $data, base64_decode($secret), true));
echo $sign . "<br/>";
$headers = array(
'CB-ACCESS-KEY: '.$key,
'CB-ACCESS-SIGN: '.$sign,
'CB-ACCESS-TIMESTAMP: '.$time,
'CB-ACCESS-PASSPHRASE: '.$passphrase,
'Content-Type: application/json'
);
var_dump($headers);
echo $url;
static $ch = null;
if (is_null($ch)) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$res = curl_exec($ch);
echo $res;
}