2017-02-16 4 views
1

現在、CoinbaseのAPIを使用している小さなアプリを開発中です。CoinBase APIコールのCURL本体の宣言方法

Coinbaseは、認証にCB-ACCESS-SIGNヘッダーが必要でした。プレハッシュ文字列timestamp + method + requestPath + body(+は文字列連結を表します)に秘密鍵を使用してsha256 HMACを作成することによって、CB-ACCESS-SIGNヘッダーが生成されます。 https://developers.coinbase.com/api/v2?shell#create-address

リファレンスページがhttps://developers.coinbase.com/api/v2?shell#api-key

からベース、アドレスを作成します。私は、コマンド書いた:

$timestamp = time(); 
    $method = 'POST'; 
    $request_path = '/v2/accounts'; 
    $body = 'addresses'; 

    $account_id = 'myaaccount_id'; 
    $hash_input = $timestamp.''.$method.''.$request_path.''.$body; 
    $apiSecret = 'myapi secret'; 
    $signature = hash_hmac('sha256', $hash_input, $apiSecret); 
    $accesskey = 'myaccess_key'; 

    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, 'https://api.coinbase.com/v2/accounts/'.$account_id.'/addresses'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 


    $headers = array(); 
    $headers[] = 'Cb-Access-Key: '.$accesskey; 
    $headers[] = 'Cb-Access-Sign: '.$signature; 
    $headers[] = 'Cb-Access-Timestamp: '.$timestamp; 
    $headers[] = 'Cb-version: 2016-12-07'; 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

    $result = curl_exec($ch); 
    if (curl_errno($ch)) { 
     echo 'Error:' . curl_error($ch); 
    } 
    curl_close ($ch); 

を私は常に応答得た:

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

を私はこの問題は、+は文字列を表しCB-ACCESS-SIGN

体(のリクエストボディだと思います連結)。

ボディ値はどこですか?

答えて

0

変更署名

$hash_input = $timestamp.$method.$request_path; 
$signature = hash_hmac("sha256", $hash_input, $apiSecret); 

このヘルプ

+0

は、私は、無効な署名を得ました。 私は署名を書いて間違っていると思う: timestamp + method + requestPath + body(+は文字列の連結を表す)。 「ボディ」の値が何であるか分かりません –

+0

コードを編集して、もう一度お試しください –

0

は次のように署名を作成・ホープ作成するための方法:それでも男は動作しませ

$Datas = $timestamp.$method.$request_path; 
$hmacSig = base64_encode(hash_hmac("sha256", $Datas, base64_decode($apiSecret), true)); 
関連する問題