Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中使用JSON编码数组[比特币| CoinKite]_Php_Json_Api_Bitcoin - Fatal编程技术网

在PHP中使用JSON编码数组[比特币| CoinKite]

在PHP中使用JSON编码数组[比特币| CoinKite],php,json,api,bitcoin,Php,Json,Api,Bitcoin,我的项目在TOR上作为隐藏服务运行。我的大多数客户使用TOR浏览器,它不支持JS开箱即用。我想让我的客户能够使用比特币进行交易,但必须为每个客户生成一个唯一的地址。CoinKite根据BIP32规范生成高清钱包地址,并允许通过其API请求这些地址。大多数API示例都使用JS,它们的PHP示例比较混乱,文档也不是很完整。以下是我目前拥有的: Sign.php-使用my API secret处理签名过程 这件事我已经琢磨了好几天了。CoinKite的调试界面没有显示除我得到的响应之外的任何信息。非常

我的项目在TOR上作为隐藏服务运行。我的大多数客户使用TOR浏览器,它不支持JS开箱即用。我想让我的客户能够使用比特币进行交易,但必须为每个客户生成一个唯一的地址。CoinKite根据BIP32规范生成高清钱包地址,并允许通过其API请求这些地址。大多数API示例都使用JS,它们的PHP示例比较混乱,文档也不是很完整。以下是我目前拥有的:

Sign.php-使用my API secret处理签名过程


这件事我已经琢磨了好几天了。CoinKite的调试界面没有显示除我得到的响应之外的任何信息。非常感谢您的帮助。

现在我几乎想给自己一拳。因为CoinKite返回一个JSON流,我误以为它也想接收一个。对于遇到相同问题的其他人:省略“$data=json_encode($data);”行,就可以开始了。

帐户和金额不是参数?您可能想联系他们,或者至少给我们提供文档链接。关于/new/receive的文档位于
<?php
date_default_timezone_set('UTC');
function sign($endpoint, $force_ts=false)
{
    $API_SECRET = 'xxxxxxxxx-xxxxxxxx-xxxxxxxxxxxxxxxx';

    if($force_ts) {
        $ts = $force_ts;
    } else {
        $now = new DateTime();
        $ts = $now->format(DateTime::ISO8601);
    }

    $data = $endpoint . '|' . $ts;
    $hm = hash_hmac('sha256', $data, $API_SECRET);

    return array($hm, $ts);
}
?>
<?php
require('sign.php');

$endpoint='/v1/new/receive';
$url='http://api.gcvqzacplu4veul4.onion'.$endpoint;
$sign = sign($endpoint);
$API_KEY = 'xxxxxxxxx-xxxxxxxx-xxxxxxxxxxxxxxxx';

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_HTTPHEADER,array("X-CK-Key: {$API_KEY}", "X-CK-Sign: {$sign[0]}", "X-CK-Timestamp: {$sign[1]}"));
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($curl, CURLOPT_PROXY, "localhost:8118");
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');

$data = array('account' => 'xxxxxxxxxx-xxxxxx', 'amount' => 0.1);

$data = json_encode($data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$result = curl_exec($curl);
curl_close($curl);

echo $result;
?>
{ "help_msg": "Unexpected arg(s): {\"account\":\"xxxxxxxxxx-xxxxxx\",\"amount\":0.1}", "message": "Bad Request", "status": 400 }