2

我已经把头发扯了一段时间了。到目前为止,我所拥有的内容来自 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;
?>

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

4

0 回答 0