【问题标题】:Coinbase Pro API {"message":"invalid signature"}Coinbase Pro API {“消息”:“无效签名”}
【发布时间】:2020-02-11 20:03:48
【问题描述】:

我正在通过一个 Laravel 项目运行这个东西。我已经把头发扯了一段时间了。到目前为止,我所掌握的内容来自 Coinbase Pro API 文档。

    $request_path = "/orders";
    $body = array('size' => $size, 'price' => $eth_price, 'side' => 'sell', 'product_id' => 'ETH-GBP' );
    $body = is_array($body) ? json_encode($body) : $body;

    $secret = my secret;

    $ch = curl_init("https://api.pro.coinbase.com/time");
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
      curl_setopt($ch,CURLOPT_USERAGENT,'CoinbaseProAPI');
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $result = json_decode(curl_exec($ch));
      curl_close($ch);
      $timestamp = $result->epoch;
      $timestamp_rounded = intval(ceil($timestamp));

    $what = $timestamp_rounded.'POST'.$request_path.$body;
    $sig =  base64_encode(hash_hmac("sha256", $what, base64_decode($secret), true));


    $ch = curl_init("https://api.pro.coinbase.com".$request_path) ;
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;
        curl_setopt($ch,CURLOPT_USERAGENT,'CoinbaseProAPI');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'CB-ACCESS-KEY: public_key',
        'CB-ACCESS-SIGN: '.$sig,
        'CB-ACCESS-PASSPHRASE: passphrase',
        'CB-ACCESS-TIMESTAMP: '.$timestamp));
        $coinbasepro_response = curl_exec($ch) ;
        curl_close($ch) ;

    dd($coinbasepro_response);

我收到的响应是无效签名。我很难过,非常感谢任何帮助。

【问题讨论】:

  • 您收到的回复表明 Coinbase 拒绝了您的 API 调用。因此,您确实需要向 Coinbase 查询您的通话中哪一部分不正确...

标签: php laravel coinbase-api


【解决方案1】:

所以经过一番折腾,我发现我缺少一个内容类型的标题,所以我添加了:

"Content-Type: application/json"

到 CURLOPT_HTTPHEADER 数组。我希望这对某人有帮助!

【讨论】:

  • 你救了我的命! :P
猜你喜欢
  • 2020-04-09
  • 1970-01-01
  • 1970-01-01
  • 2020-09-05
  • 2019-01-12
  • 2015-04-21
  • 1970-01-01
  • 2015-10-17
  • 1970-01-01
相关资源
最近更新 更多