我正在尝试从apirone实现比特币网关。问题是,当我运行CURL函数时,它将返回内部服务器错误500。
所以我试图运行他们的演示代码。尽管在他们的网站上工作正常,但我在服务器上尝试返回相同的内部服务器错误。下面是代码
<?php
$json_data = array (
'type' => "forwarding",
'currency' => "btc",
'callback' => array(
'url'=> "http://example.com/callback",
'data' => array (
'invoice_id' => "1234"
)
),
'destinations' => array (
array('address' => "1apiKcJM95jENZeom2dQo8ShK7dUQkRaS", 'amount' => 40330),
array('address' => "1ApiwpetcWnBbkpU7cb7biPfc6Tiucasf8", 'amount' => 40330)
)
);
$api_endpoint = "https://apirone.com/api/v2/wallet";
$curl = curl_init($api_endpoint);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json_data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
$http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($http_status_code==200){
$decoded = json_decode($response, true);
echo "Wallet: " . $decoded["wallet"] . "<BR>";
echo "Key: " . $decoded["transfer_key"];
} else {
var_dump($response);
}
?>
更多详细信息,请点击此处https://apirone.com/docs/forwarding-wallet
有人可以让我知道什么可能导致此错误吗?
谢谢
答案 0 :(得分:0)
我认为这可能是cURL设置问题。
尝试放置
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
之后
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json_data));
此外,我不会直接在函数参数中json_encode($json_data)
。尝试先对其进行编码,然后在CURLOPT_POSTFIELDS
选项中发送已编码的json。