Coinbase Pro API {"message":"invalid signature"}

Coinbase Pro API {"message":"invalid signature"}

我是 运行 通过 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);

我得到的响应是无效签名。我很困惑,非常感谢任何帮助。

所以经过多次摆弄,我发现我少了一个 content-type header 所以我补充说:

"Content-Type: application/json"

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