简体   繁体   English

Coinbase API - 无效签名

[英]Coinbase API - invalid signature

I'm trying to use the API for Coinbase but I get invalid signature.我正在尝试将 API 用于 Coinbase,但我得到了无效的签名。 So probably I'm actually sign it wrong or I'm missing something.所以可能我实际上签错了,或者我遗漏了一些东西。 please help me.请帮我。

    $API_KEY = "-------";
    $API_SECRET = "------";   
    $USER_ID = "------",
    $timestamp = time();
    $method = "POST";
    $path = '/v2/accounts/'.$USER_ID.'/addresses';
    $message = $timestamp . $method . $path ;
    $signature = hash_hmac('SHA256', $message, $API_SECRET);
    $version = '2017-11-11';

    $headers = array(
        'CB-ACCESS-SIGN: ' . $signature,
        'CB-ACCESS-TIMESTAMP: ' . $timestamp,
        'CB-ACCESS-KEY: ' . $API_KEY,
        'CB-VERSION: ' . $version
    ); 
    $body = array(
        'name: New receive address'
    ); 

    $api_url = "https://api.coinbase.com/v2/accounts/'.$USER_ID.'/addresses";

    $curl = curl_init($api_url);
    curl_setopt($curl,CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl,CURLOPT_POSTFIELDS, $body);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $resp = curl_exec($curl);
    if(!curl_exec($curl)){
        die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
    }
    curl_close($curl);

results api:结果 api:

{"errors":[{"id":"authentication_error","message":"invalid signature"}]}

I'm currently working on this and just got this right (in Elixir).我目前正在研究这个并且刚刚做对了(在 Elixir 中)。 I think there are two problems:我认为有两个问题:

  • Make sure your signature is lower-cased.确保您的签名是小写的。 The docs don't mention this.文档没有提到这一点。
  • You're making a POST request, and are required to concatenate the body param as string in the prehash ( $message in this context) to generate the signature.您正在发出 POST 请求,并且需要将 body 参数连接为 prehash 中的字符串(在此上下文中$message )以生成签名。 You should try this with a simple GET request on a Wallet endpoint before proceeding with this IMHO.在继续此恕我直言之前,您应该在 Wallet 端点上使用简单的 GET 请求尝试此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM