我正在编写一个脚本来接受比特币付款。我的 $json 变量返回 null。var_dump() 返回 NULL。
我尝试过的事情: 1. 我已经获取了 $callbackurl 的值,并且 $recievingaddress 将 URL 直接粘贴到了我的浏览器中,并且我得到了 JSON 响应
我使用了 json_last_error 并收到了“无错误”响应
我已经逃脱了 magic_quotes 但这没有效果
我究竟做错了什么?
$receiving_address = BITCOIN_ADDRESS;
if(get_magic_quotes_gpc()){
$callback_url = urlencode(stripslashes(CALLBACK_URL));
} else {
$callback_url = urlencode(CALLBACK_URL);
}
$ch = curl_init("https://blockchain.info/api/receive?method=create&address=$receiving_address&shared=false&callback=$callback_url");
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json=json_decode(curl_exec($ch),true);
var_dump($json);
echo $json[0]->text;
更正后的代码如下:
$receiving_address = BITCOIN_ADDRESS;
if (get_magic_quotes_gpc()) {
$callback_url = urlencode(stripslashes(CALLBACK_URL));
} else {
$callback_url = urlencode(CALLBACK_URL);
}
$ch = curl_init("https://blockchain.info/api/receive?method=create&address=$receiving_address&shared=false&callback=$callback_url");
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CAINFO, "C:\Program Files\BitNami WAMPStack\apache2\htdocs\coming\cacert.pem");
$res = curl_exec($ch);
if ($res === FALSE) {
die("Curl failed with error: " . curl_error($ch));
}
//var_dump($res);
$json = json_decode($res, true);