Example #1
0
 /**
  * Create a jsonrpc_client object to talk to the bitcoin server and return it,
  * or false on failure.
  *
  * @param string $scheme
  * 	"http" or "https"
  * @param string $username
  * 	User name to use in connection the Bitcoin server's JSON-RPC interface
  * @param string $password
  * 	Server password
  * @param string $address
  * 	Server hostname or IP address
  * @param mixed $port
  * 	Server port (string or integer)
  * @param string $certificate_path
  * 	Path on the local filesystem to server's PEM certificate (ignored if $scheme != "https")
  * @param integer $debug_level
  * 	0 (default) = no debugging;
  * 	1 = echo JSON-RPC messages received to stdout;
  * 	2 = log transmitted messages also
  * @return jsonrpc_client
  * @access public
  * @throws BitcoinClientException
  */
 public function __construct($scheme, $username, $password, $address = "localhost", $port = 8332, $certificate_path = '', $debug_level = 0)
 {
     $scheme = strtolower($scheme);
     if ($scheme != "http" && $scheme != "https") {
         throw new BitcoinClientException("Scheme must be http or https");
     }
     if (empty($username)) {
         throw new BitcoinClientException("Username must be non-blank");
     }
     if (empty($password)) {
         throw new BitcoinClientException("Password must be non-blank");
     }
     $port = (string) $port;
     if (!$port || empty($port) || !is_numeric($port) || $port < 1 || $port > 65535 || floatval($port) != intval($port)) {
         throw new BitcoinClientException("Port must be an integer and between 1 and 65535");
     }
     if (!empty($certificate_path) && !is_readable($certificate_path)) {
         throw new BitcoinClientException("Certificate file " . $certificate_path . " is not readable");
     }
     $uri = $scheme . "://" . $username . ":" . $password . "@" . $address . ":" . $port . "/";
     parent::__construct($uri);
     $this->setDebug($debug_level);
     $this->setSSLVerifyHost(0);
     if ($scheme == "https") {
         if (!empty($certificate_path)) {
             $this->setCaCertificate($certificate_path);
         } else {
             $this->setSSLVerifyPeer(false);
         }
     }
 }
Example #2
0
<!DOCTYPE html>
<html lang="de">
<head>
         <script src="js/xmlrpc_lib.js"></script>     
         <script src="js/jsonrpc_lib.js"></script>        
</head>

<?php 
include 'xmlrpc.inc';
include 'classes.php';
include 'jsonrpc.inc.php';
// Make an object to represent our server.
$server = new jsonrpc_client('XML_RPC_Server.php', 'sparesprit.de', 80);
/*
$message = new xmlrpcmsg('sample.sumAndDifference',
                         array(new xmlrpcval(5, 'int'),
                               new xmlrpcval(3, 'int')));*/
$message = new jsonrpcmsg('getCoordsByTown', array(new jsonrpcval(Leipzig, 'string'), 1));
$result = $server->send($message);
// Process the response.
if (!$result) {
    print "<p>Could not connect to HTTP server.</p>";
} elseif ($result->faultCode()) {
    print "<p>XML-RPC Fault #" . $result->faultCode() . ": " . $result->faultString();
} else {
    $struct = $result->value();
    $latitude = $struct->structmem('latitude');
    $longitude = $struct->structmem('longitude');
    echo "Latitude: " . htmlentities($latitude->scalarval());
    echo "Longitude: " . htmlentities($longitude->scalarval());
}