当我发送获取请求以检索最新地址时,它可以正常工作,但是当我尝试发送发布请求以生成新地址时,我收到此错误身份验证错误无效签名
我确定一切都是正确的,因为我遵循了他们的文档,但我想他们需要更新它
$apiKey = "xx";
$apiSecret = "xxx";
$accountId = "accountx";
$body = '';
$timestamp = time();
$message = $timestamp . 'GET' . '/v2/user' . $body;
$signature = hash_hmac('SHA256', $message, $apiSecret);
$version = '2020-06-23';
$headers = array(
'CB-ACCESS-SIGN: ' . $signature,
'CB-ACCESS-TIMESTAMP: ' . $timestamp,
'CB-ACCESS-KEY: ' . $apiKey,
'CB-VERSION: ' . $version
);
$api_url = 'https://api.coinbase.com/v2/user';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$data = curl_exec($ch);
curl_close($ch);
$ctx = stream_context_create(["http"=>["user_agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0"]]);
$response_btc = file_get_contents('https://api.coinbase.com/v2/prices/BTC-USD/spot', true, $ctx);
$object_btc = json_decode($response_btc, true);
$usdprice = $object_btc["data"]["amount"];
$btcamount = number_format($amount/$usdprice, 8, '.', '');
$body1 = '';
$timestamp1 = time();
$message1 = $timestamp1 . 'POST' . '/v2/accounts/accountx/addresses' . $body1;
$signature1 = hash_hmac('SHA256', $message1, $apiSecret);
$version1 = '2020-06-23';
$headers1 = array(
'CB-ACCESS-SIGN: ' . $signature1,
'CB-ACCESS-TIMESTAMP: ' . $timestamp1,
'CB-ACCESS-KEY: ' . $apiKey,
'CB-VERSION: ' . $version1,
'Content-Type: appliaction/json'
);
$api_url = "https://api.coinbase.com/v2/accounts/accountx/addresses";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"name\": \"New receive address\"}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$data1 = curl_exec($ch);
if(curl_errno($ch))
{
echo "Errore: " . curl_error($ch);
}
else
{
echo $data1;
}
curl_close($ch);