{“message”:“无效签名”} Coinbase Pro API

时间:2021-04-01 01:32:01

标签: coinbase-api coinbase-php gdax-api

我已经脱发有一段时间了。到目前为止,我所拥有的内容来自 Coinbase Pro API 文档。

Coinbase Pro API 需要四个不同的标头,其中之一是经过加密的签名。我在形成有效签名时遇到问题。根据 Coinbase Pro API 文档:

<?php
// Your code here!

$request_path = "/accounts";

$secret = "ZSTJxPU6g9+QLITr5U4IeKWiaoCMqs9TFnCEavdvIjQOO/TqS4ZuRirtKLKUI4UBAen0TyBEsyDmzOZQQ6SC1w==";

$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.'GET'.$request_path;

$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_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'CB-ACCESS-KEY: 513194d14d510c48fd3ba86edef54969',
    'CB-ACCESS-SIGN: '.$sig,
    'CB-ACCESS-PASSPHRASE: bbujnpclpsv',
    'CB-ACCESS-TIMESTAMP: '.$timestamp,
    'Content-Type: application/json'));
    $coinbasepro_response = curl_exec($ch) ;
    curl_close($ch) ;

echo $coinbasepro_response;
?>

我得到的响应是无效的签名。我很难过,任何帮助表示赞赏。

0 个答案:

没有答案
相关问题