发送 btc api coinbase?

send btc api coinbase?

我正在尝试使用 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&currency=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);

?>  

注意:代码中的密钥和密码是我发明的,但我的网站上有原件。

我已经这样解决了

          $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 amount
               '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);