嗨,我正在尝试使用php进行api调用,但是当我使用post方法时,我会得到
{"message":"invalid signature"}
当我使用get方法时它有效,但是我不确定如何输入额外的参数(id) 如果您可以帮助我解决发布问题或使用参数id重新创建get请求,我将非常满意
链接到api文档https://docs.pro.coinbase.com/
这是我的代码
$secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxx..............";
$key = 'xxxxxxxxxx.............';
$passphrase = 'xxxxxxx...';
$time = time();
$method = "POST";
$path = "/accounts";
$url = "https://api.prime.coinbase.com".$path;
$body = array(
'id' => "xxxxxxxxxxxxxx............"
);
$data = $time.$method.$path.json_encode($body);
$sign = base64_encode(hash_hmac("sha256", $data, base64_decode($secret),
true));
$headers = array(
'CB-ACCESS-KEY: '.$key,
'CB-ACCESS-SIGN: '.$sign,
'CB-ACCESS-TIMESTAMP: '.$time,
'CB-ACCESS-PASSPHRASE: '.$passphrase,
'Content-Type: application/json'
);
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
curl_setopt($ch, CURLOPT_URL, $url);
$res = curl_exec($ch);
echo $res;