区块链 API v1 异常“未找到”

问题描述 投票:0回答:2

我已经按照此处所述安装了本地服务https://github.com/blockchain/service-my-wallet-v3并且它成功启动。但当我试图平衡我的钱包时:

$Blockchain = new \Blockchain\Blockchain();
$Blockchain->setServiceUrl("http://localhost:3000");
$Blockchain->Wallet->credentials('myid', 'mypass');
$stats = $Blockchain->Stats->get();
var_dump($stats);
$balance = $Blockchain->Wallet->getBalance();
var_dump($balance);     

我收到以下异常消息:

Fatal error: Uncaught exception 'Blockchain\Exception\ApiError' with message 'No
t found' in C:\xampp\htdocs\test\Blockchain\Blockchain.php:114
Stack trace:
#0 C:\xampp\htdocs\test\Blockchain\Wallet\Wallet.php(47): Blockchain\Blockchain-
>post('merchant/16d72a...', Array)
#1 C:\xampp\htdocs\test\Blockchain\Wallet\Wallet.php(55): Blockchain\Wallet\Wall
et->call('balance')
#2 C:\xampp\htdocs\test\wallet.php(26): Blockchain\Wallet\Wallet->getBalance()
#3 {main}
  thrown in C:\xampp\htdocs\test\Blockchain\Blockchain.php on line 114

造成此问题的原因以及如何解决?谢谢!

php bitcoin blockchain
2个回答
1
投票

我很困惑你从哪里想到这些功能?

setServiceURL()
credentials()
getBalance()

您使用自定义库或包装器吗?

钱包服务根据发送到您告诉其运行的端口上的本地主机上的服务的 GET 请求来工作。

这是一个例子:

$url = "http://127.0.0.1:3000/merchant/YOUR-GUID/address_balance?address=1someBitcoinAddy&password=YOUR-PASSWORD&api_code=YOUR-API-CODE";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$ccc = curl_exec($ch);
$json = json_decode($ccc, true);
echo "<pre>";
var_dump($json);
echo "</pre>";

API 文档页面上提供了可用 GET 命令的列表:https://blockchain.info/api/blockchain_wallet_api


-1
投票

获取钱包余额

$guid="GUID_HERE";
$main_password="PASSWORD_HERE";
$json_url = "http://localhost:3000/merchant/$guid/list?password=$main_password";
$json_data = file_get_contents($json_url);
$json_feed = json_decode($json_data);
$balance = $json_feed->balance;


Response:
{
  "balance": 1000
}

从列表地址获取余额

$guid="GUID_HERE";
$main_password="PASSWORD_HERE";
$json_url = "http://localhost:3000/merchant/$guid/list?password=$main_password";
$json_data = file_get_contents($json_url);
$json_feed = json_decode($json_data);

Response:
{
  "addresses": [
    {
      "balance": 1400938800,
      "address": "1Q1AtvCyKhtveGm3187mgNRh5YcukUWjQC",
      "label": "SMS Deposits",
      "total_received": 5954572400
    },
    {
      "balance": 79434360,
      "address": "1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq",
      "label": "My Wallet",
      "total_received": 453300048335
    },
    {
      "balance": 0,
      "address": "17p49XUC2fw4Fn53WjZqYAm4APKqhNPEkY",
      "total_received": 0
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.