我的linux服务器上有一个电子钱包。我试图通过php运行命令来控制它。
Electrum基本上说,使用curl并返回json。
http://docs.electrum.org/en/latest/merchant.html 最后一节
以下是我到目前为止它无效。
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://myuserame:mypassword==@serverip:7777");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id\":\"curltext\",\"method\":\"getbalance\",\"params\":[]}");
$result = curl_exec($ch);
if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); }
curl_close ($ch);
var_dump($result);
?>
返回:
Error:bool(false)
答案 0 :(得分:0)
修改强>
试试这样:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://serverip:7777");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST , 1);
curl_setopt($ch, CURLOPT_USERPWD , 'myuserame:mypassword');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id\":\"curltext\",\"method\":\"getbalance\",\"params\":[]}");
$result = curl_exec($ch);
//if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); }
//curl_close ($ch);
dd(json_decode($result,1));
?>