用于Coinbase的api密钥身份验证 [英] Api key authentication for coinbase

查看:242
本文介绍了用于Coinbase的api密钥身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写对API coinbase.com的请求,但是我无法正确生成签名.我已经尝试寻找错误2天了,但是我找不到.我在页面上分析了其他语言的代码: https://developers.coinbase .com/docs/wallet/api-key-autumnicathion ,但在实现上没有任何区别.

I'm trying to write a request for API coinbase.com, but I can not correctly generate a signature. I've been trying to find my mistake for 2 days, but I can not. I analyzed the code for other languages on the page: https://developers.coinbase.com/docs/wallet/api-key-autumnicathion but I do not see any differences in implementation.

请帮助我.

<?php
$g_coinbase_key = 'KcxisxqmWRVgtwsj';
$g_coinbase_secret = 'isOLGBLaEkCy3ROQMvmjonGmXK0KRmUS';

$time = time();
$method = "GET";
$path = '/v2/accounts/';
$sign = base64_encode(hash_hmac("sha256", $time.$method.$path, $g_coinbase_secret));
$ch = curl_init('https://api.coinbase.com'.$path);
$headers = array(
    "CB-VERSION: 2017-10-26",
    "CB-ACCESS-SIGN: ".$sign,
    "CB-ACCESS-TIMESTAMP: ".$time,
    "CB-ACCESS-KEY: ".$g_coinbase_key,
    "Content-Type: application/json"
);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
var_dump($result);
?>

结果:

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

推荐答案

替换

$sign = base64_encode(hash_hmac("sha256", $time.$method.$path, $g_coinbase_secret));

使用

$sign = hash_hmac("sha256", $time.$method.$path, $g_coinbase_secret);

Coibase Api使用hash_mac

Coibase Api uses hash_mac

这篇关于用于Coinbase的api密钥身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆