【问题标题】:Blockchain API :: Send payment error区块链 API :: 发送支付错误
【发布时间】:2017-12-02 13:17:42
【问题描述】:

我正在尝试通过区块链 API v2 发送付款。我正在使用 PHP 和 Curl。

区块链钱包服务:0.26.0 v node.js:8.9.0 v

我可以生成比特币地址,获取我的余额并与我的钱包进行交互,但由于未知原因,我无法通过 API 发送付款,请帮助我查找了许多网站以寻求答案。

我的 PHP 代码(只是测试)发送付款:

$my_api_key = 'xxxxx';
$guid='xxxxx';
$firstpassword='xxxx';
$second_password = "xxxx";
$amount = '30000';
$to = '1AQDhKrjvAonjLAUv4PzM9NjGzZZ4HEpU1';
$fee = '2000';

$root_url = 'http://localhost:3000/merchant/'.$guid.'/payment';
$parameters = 'to='.$to.'&amount='.$amount.'&password='.$firstpassword.'&fee='.$fee.'&second_password='.$second_password;

$response = Curl::to($root_url . '?' . $parameters)->get();


return $response;

在控制台上我收到以下错误:-错误:[object object] 响应给我:{“error”:“意外错误,请重试”}

我测试了我的密码、我的 API 代码和我的钱包 ID,都 100% 正确。

【问题讨论】:

    标签: php api blockchain


    【解决方案1】:

    你可以试试这个:

    首先,您必须确保区块链钱包服务在您的服务器上的 3000 端口上运行。您可以通过在浏览器中点击 url 来检查区块链钱包服务的工作情况,即http://localhost:3000。如果它给出响应错误“未找到”,这意味着您的区块链钱包服务正在运行。 要一次向多个用户发送比特币,您可以使用以下 API:

    http://localhost:3000/merchant/$guid/sendmany?password=$main_password&second_password=$second_password&recipients=$recipients&fee=$fee

    其中 $guid 是你的区块链钱包 ID,$main_password 是你的钱包第一个密码,$second_password 是你钱包的第二个密码,如果你打开了第二个密码,$recipients 是你的 JSON 对象,接收地址作为密钥和金额作为值,$fee 是交易费用,必须大于默认交易费用,这是可选的。

    $recipients 对象会像

    {
        "1JzSZFs2DQke2B3S4pBxaNaMzzVZaG4Cqh": 100000000,
        "12Cf6nCcRtKERh9cQm3Z29c9MWvQuFSxvT": 1500000000,
        "1dice6YgEVBf88erBFra9BHf6ZMoyvG88": 200000000
    }
    

    【讨论】:

    • "如果它给出响应错误“未找到”,这意味着您的区块链钱包服务正在运行。" - 废话但真实,它帮助了我。
    • 是的,它给你响应错误。因为您没有传递任何参数或访问任何区块链服务。但是,您只是检查区块链服务是否响应您的请求。这将确保您确定它是否正在运行。
    【解决方案2】:

    必须包含“&from”参数。正如文档所说,这不是可选的。但是您可以将参数设置为 0

    .......

    $root_url = 'http://localhost:3000/merchant/'.$guid.'/payment'; $parameters = 'to='.$to.'&amount='.$amount.'&password='.$firstpassword.'&fee='.$fee.'&second_password='.$second_password.'&from=0';

    $response = Curl::to($root_url . '?' . $parameters)->get();

    返回 $response;

    ......................

    如果你使用的是github上的php版本,可以设置from_address如下

    调用函数如下:

    $address = 'to-address';
    $amount = 0.01;
    $from = 0;
    $fee = 0.00012;
    $Blockchain->Wallet->send($address,$amount,$from,$fee);
    

    $fee 是可选的

    【讨论】:

      【解决方案3】:

      试试这个:

      $address = null;
      
      try {
          // Uncomment to send
          // var_dump($Blockchain->Wallet->send($address, "0.001"));
      } catch (\Blockchain\Exception\ApiError $e) {
          echo $e->getMessage() . '<br />';
      }
      
      // Multi-recipient format
      $recipients = array();
      $recipients[$address] = "0.001";
      
      try {
          // Uncomment to send
      // var_dump($Blockchain->Wallet->sendMany($recipients));
      } catch (Blockchain_ApiError $e) {
          echo $e->getMessage() . '<br />';
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-22
        • 2016-04-02
        • 1970-01-01
        • 1970-01-01
        • 2015-02-26
        • 1970-01-01
        相关资源
        最近更新 更多