我正在尝试使用coinbase api通过php将satoshis发送到电子邮件,但它对我不起作用。我在网上看到了这个代码。 我收到这个错误:
{"errors": [{"id": "authentication_error", "message": "invalid signature"}]}
我附上了我在网站上的php代码
<?php
$timestamp = time();
$method = 'POST';
$request_path = '/v2/accounts/34en86m3-b0qa-5022-a45c-b110z38631k6/transactions';
$body = 'type=send&to=gabriele.zangari@hotmail.it&amount=0.00002504¤cy=BTC';
$account_id = '34en86m3-b0qa-5022-a45c-b110z38631k6';
$hash_input = $timestamp.''.$method.''.$request_path.''.$body;
$apiSecret = 'VmQruPgmAYsW6Pq1vsC5bnzObd5LpTIn';
$signature = hash_hmac('sha256', $hash_input, $apiSecret, true);
$accesskey = '1XJZLVA1F4zjQ9cO';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.coinbase.com/v2/accounts/'.$account_id.'/transactions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
$headers = array();
$headers[] = 'Cb-Access-Key: '.$accesskey;
$headers[] = 'Cb-Access-Sign: '.$signature;
$headers[] = 'Cb-Access-Timestamp: '.$timestamp;
$headers[] = 'Cb-version: 2017-08-07';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
else
{
echo $result;
}
curl_close ($ch);
?>
注意:代码中发布的密钥和密码是发明的,但在我的网站上我有原件。
答案 0 :(得分:0)
我已经通过这种方式解决了。
$secret = "fffffffff"; //you number secret
$timestamp = time();
$method = "POST";
$request_path = "/v2/accounts/fffff-fffff-ffff-ffff-ffff/transactions"; //you account id
$data = array (
'type' => 'send',
'to' => 'email@gmail.com', //put email
'amount' => '0.0000012'), //put ammount
'currency' => 'BTC', //put crypto
'description' => 'put you description', //put description
);
$body = json_encode($data);
$prehash = $timestamp.$method.$request_path.$body;
$sign = hash_hmac("sha256", $prehash, $secret);
$ch = curl_init();
$headers = array(
'CB-ACCESS-KEY: fffffffffff', //You Key
'CB-ACCESS-SIGN: '.$sign,
'CB-ACCESS-TIMESTAMP: '.$timestamp,
'CB-ACCESS-VERSION: 2018-05-20',
'Content-Type: appliaction/json'
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_URL, 'https://api.coinbase.com'.$request_path);
$res = curl_exec($ch);