我正在尝试将 API 用于 Coinbase,但我得到了无效的签名。所以可能我实际上签错了,或者我遗漏了一些东西。请帮我。
$API_KEY = "-------";
$API_SECRET = "------";
$USER_ID = "------",
$timestamp = time();
$method = "POST";
$path = '/v2/accounts/'.$USER_ID.'/addresses';
$message = $timestamp . $method . $path ;
$signature = hash_hmac('SHA256', $message, $API_SECRET);
$version = '2017-11-11';
$headers = array(
'CB-ACCESS-SIGN: ' . $signature,
'CB-ACCESS-TIMESTAMP: ' . $timestamp,
'CB-ACCESS-KEY: ' . $API_KEY,
'CB-VERSION: ' . $version
);
$body = array(
'name: New receive address'
);
$api_url = "https://api.coinbase.com/v2/accounts/'.$USER_ID.'/addresses";
$curl = curl_init($api_url);
curl_setopt($curl,CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl,CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
if(!curl_exec($curl)){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
curl_close($curl);
结果API:
{"errors":[{"id":"authentication_error","message":"invalid signature"}]}