问题
This is the code I have
<?php
include("connect.php");
$bc = $dbh->prepare("SELECT * FROM `blockchain`");
$bc->execute();
$bcs = $bc->fetch(PDO::FETCH_ASSOC);
$type = $_REQUEST['type'];
$price = $_REQUEST['amount'];
$uid = $_REQUEST['uid'];
$secret = $bcs['apikey'];
$my_address = $bcs['badd'];
$my_callback_url = 'http://www.imusicsong.com/api/bcp.php?secret='.$secret;
$root_url = 'https://blockchain.info/api/receive';
$parameters = 'method=create&address=' . $my_address .'&callback='. urlencode($my_callback_url);
$response = file_get_contents($root_url . '?' . $parameters);
$object = json_decode($response);
$stmt = $dbh->prepare("INSERT INTO `orders` (`uid`, `processor`, `type`, `date`, `price`) VALUES (:uid, 'bitcoin', :type, '".date("Y-m-d")."', :price)");
$stmt->execute(array(":uid" => $uid, ":type" => $type, ":price" => $price));
echo 'Send Payment in the amount of '.$price.' BTC To Bitcoin Address : ' . $object->input_address;
?>
Which is derived from their own code for the api located here https://blockchain.info/api/api_receive
Everything is set up correctly but I get the following error
Warning: file_get_contents(https://blockchain.info/api/receive?method=create&address=yourbitcoinaddress&callback=http://www.imusicsong.com/api/bcp.php?secret=replacewithbcapi): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:\wamp\www\music\bc.php on line 23
if I copy and paste that url into my browser it does load but it gives me the error Error You Must Provide a Destination Address
If I change all of the &
back to just &
in that link then it loads the json response
{"callback_url":"http:\/\/www.imusicsong.com\/api\/bcp.php?secret=replacewithbcapi","input_address":"16uEPhaC5B5v6xLKem4hDoQRE11yZ4nEc4","destination":"1McVCZZrUgtkrUMkqfTF8kaaSSQBg54Fkd","fee_percent":0}
So not only do I not know why it is giving me that error, even it it wasn't throwing that error the fact that is passes the url with &
instead of &
is going to cause their system to not pass the proper response.
So I need to identify how to fix both problems.
1.) Why is file_get_contents
not opening the url
2.) How can I make file_get_contents
not change &
into &
来源:https://stackoverflow.com/questions/34167944/file-get-contents-not-working-with-blockchain-api