Blockchain api v2:发送付款不起作用

时间:2017-05-02 04:48:36

标签: php api blockchain

我正在尝试使用区块链V2 API将btc发送给用户。 我已经阅读了文档并使用以下代码将btc发送给用户。但它没有被执行。

<?php



echo " send test<br>";
include 'db_config/connection.php';


$action = "completed";
$order_id = "12345";

$sql = "SELECT * from wallet_config";
$result= $conn->query($sql) or die(mysqli_error($conn));

if ($result->num_rows > 0) {
     while($row = $result->fetch_array()) {
        $guid = $row['wallet_id'];
        $main_password = $row['password'];
        $from = $row['wallet'];

      }

    $amount = 0.01 * 100000000;  // 100000000satoshi = 1 btc
    $to = "1J528hXvotieFZJkLA66g7NntXCXtNSm78";


    $json_url = "https://blockchain.info/merchant/$guid/payment?password=$main_password&to=$to&amount=$amount&from=$from";

    echo $json_url;

    $json_data = file_get_contents($json_url);

    $json_feed = json_decode($json_data);

    $message = $json_feed->message;
    $tx_hash = $json_feed->tx_hash;

    print_r($json_feed);


    $sql1 = "UPDATE buy_order set status ='$action', tx_id = '$tx_hash' where order_id = '$order_id'";

    $result1=$conn->query($sql1) or die (mysqli_error($conn));

    if($result1){
      if(!isset($tx_hash)){
        echo "Transaction for Order id $order_id not porceeded. Try sending BTC manually.";
      }
      echo "Order id $order_id marked as $action..";
    }else{
      echo "Something went wrong... Try Again";
    }

}else{
  echo "Something went wrong... Try Checking wallet config";
}
echo "<br>last";

?>

问题是交易没有完成。我甚至试图回应 $ json_feed 并且它什么也没显示。

我真的不明白为什么它不在这里工作。

当我在浏览器中粘贴$ json_url时,它会显示以下错误

`<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>`

1 个答案:

答案 0 :(得分:0)

您是否从https://github.com/blockchain/service-my-wallet-v3在本地安装了库? 如果没有,请先安装它。

您是否通过此API呼叫创建了GUID?根据您的错误消息,似乎您没有创建GUID。 http://localhost:3000/api/v2/create 如果没有创建,请查看文档以获取详细信息

然后拨打付款api,您的网址将是您的本地主机网址

http://localhost:3000/merchant/$guid/payment?password=$main_password&second_password=$second_password&to=$address&amount=$amount&from=$from&fee=$fee



$json_url = "http://localhost:3000/merchant/$guid/payment?password=$main_password&second_password=$second_password&to=$address&amount=$amount&from=$from&fee=$fee";    
$json_data = file_get_contents($json_url);
$json_feed = json_decode($json_data);
var_dump($json_feed);

希望这会对你有所帮助。