Php 发送btc api coinbase?

Php 发送btc api coinbase?,php,coinbase-api,Php,Coinbase Api,我试图通过php和coinbase api向电子邮件发送satoshis,但它对我不起作用。我在网上看到了这个代码。 我得到这个错误: {"errors": [{"id": "authentication_error", "message": "invalid signature"}]} 我在我的网站上附加了php代码 <?php $timestamp = time(); $method = 'POST'; $request_path = '/v2/accounts/34en86m3-b

我试图通过php和coinbase api向电子邮件发送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 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);

无效签名
似乎是错误告诉了您这里出了什么问题。您必须联系API支持部门以了解您的凭据不起作用的原因。我与他们取得了联系,但他们没有给我解决方案。。。它告诉我代码中可能有一些错误,但他们没有告诉我是什么。他确切地告诉我:
这很可能是您的时间戳生成的结果。请记住,时间必须在API服务时间的30秒内。根据我的经验,这通常是由无效的API键引起的。
但我不太明白你的意思…我可以解决它,主题已解决。你是如何解决的?我刚刚发布了答案