猿问

科因库专业版 API {“消息”:“无效签名”}

我正在通过一个拉拉维尔项目来运行这个东西。我已经把头发扯了一段时间了。到目前为止,我所拥有的是从科因基专业版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);

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


红颜莎娜
浏览 72回答 1
1回答

慕容森

因此,经过多次摆弄,我发现我缺少一个内容类型标题,所以我添加了:"Content-Type: application/json"添加到CURLOPT_HTTPHEADER数组。我希望这可以帮助某人!
随时随地看视频慕课网APP
我要回答