CoinBase“无效签名"; PHP Buy API请求 [英] CoinBase "invalid signature" PHP Buy API Request

查看:127
本文介绍了CoinBase“无效签名"; PHP Buy API请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过很多遍代码了,但是每当我向API发送请求时,它都会返回"message":"invalid signature"

I have looked over the code many times but whenever I send request to API it returns "message":"invalid signature"

我认为这可能与散列身体有关.我是PHP及其第一个项目的新手. :)

I am thinking it has to do with hashing the body, possibly. I'm new to PHP and its my first project. :)

有人看到错误吗?谢谢.

Anyone see an error? Thanks.

<?php
$arr = array('size' => ".01", 'price' => '240', 'side' => 'sell',
 'product_id' => 'BTC-USD');

$output = json_encode($arr);

echo json_encode($arr)."<br/>";



$key = "f23612b06cb4d020cda7e04b1ae6ef9a";
$secret = "RENqodtuTCn4v7g7Pn/FFdQAIKReVXGayNPrNN/Zb7AjATI0hP4R0MCDD5RqnDu60qTZ5Qry329fFu7kcObGBw==";
$passphrase = "tradebot";

$time = time();
$url = "https://api.gdax.com/orders";

$data = $time."POST"."/orders";
echo $data . "<br/>";

$hashinput = "$output"."$data";

$sign = base64_encode(hash_hmac("sha256", $hashinput, base64_decode($secret), true));                
echo $sign . "<br/>";

$headers = array(                
    'CB-ACCESS-KEY: '.$key,
    'CB-ACCESS-SIGN: '.$sign,
    'CB-ACCESS-TIMESTAMP: '.$time,
    'CB-ACCESS-PASSPHRASE: '.$passphrase,
    'Content-Type: application/json'
);

var_dump($headers);

echo $url;

static $ch = null;

if (is_null($ch)) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'local server');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, $output);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    $res = curl_exec($ch);
    echo $res;
}

推荐答案

替换

$hashinput = "$output"."$data";

使用

$hashinput = "$data"."$output";

并替换

curl_setopt($ch, CURLOPT_POST, $output);

使用

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $output);

(来自 Coinbase社区论坛)

这篇关于CoinBase“无效签名"; PHP Buy API请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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