如何为比特币操作设置区块链网址?区块链操作url的基本URL是什么?

时间:2017-09-04 11:05:42

标签: php codeigniter codeigniter-2 codeigniter-3 blockchain

我的代码段:

    class Blockchain{
        protected $guid; // Blockchain wallet identifier (Wallet ID)
        protected $api_code; // API code, required for creating wallets
        protected $main_password; // Main Blockchain Wallet password
        protected $second_password; // Second Blockchain Wallet password if double encryption is enabled
        protected $port = 3000; // Blockchain Wallet service port
        protected $base_url = 'http://127.0.0.1'; // Base url to connect to the Blockchain Wallet service

        public function __construct($config)
        {
            // Set config values
            $this->guid = $config['guid'];
            $this->main_password = $config['main_password'];
            // Optional ones
            $this->api_code = ( isset($config['api_code']) ) ? $config['api_code'] : NULL;
            $this->second_password = ( isset($config['second_password']) ) ? $config['second_password'] : NULL;
            $this->base_url = ( isset($config['base_url']) ) ? $config['base_url'] : $this->base_url;
            $this->port = ( isset($config['port']) ) ? $config['port'] : $this->port;

            log_message('info', 'Blockchain Class Initialized');

            // Check if the Blockchain Wallet service is running
            if ($this->execute($this->base_url.':'.$this->port) === NULL) {
                show_error('Blockchain: Unable to connect to Blockchain Wallet service on: '.$this->base_url.':'.$this->port.'');
                log_message('error', "Blockchain: Unable to connect to Blockchain Wallet service.");
            }
        }

        public function wallet_balance()
        {
            // Get the base url
            $url=$this->base_url;

            // Add the port
            $url.=':'.$this->port.'/';

            // Add the api url
            $url.='merchant/'.$this->guid.'/balance';

            // Add options
            // password
            $url.='?password='.$this->main_password;

            // Execute
            return $this->execute($url);
        }

    public function execute($url)
    {
        // Get CURL resource
        $curl = curl_init();
        // Set options
        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_URL => $url,
            // CURLOPT_SSL_VERIFYPEER => FALSE,
        ));

        // Send the request & save response
        $response = curl_exec($curl);

        // Close request to clear up some resources
        curl_close($curl);

        log_message('debug', 'Blockchain: URL executed '.$url);

        // Return the decoded response as an associative array
        return json_decode($response, TRUE);
    }
}

什么是base_url ..

我不理解基本网址部分..

是本地还是“https://api.blockchain.info”(就像这样)

在上面的代码片段的声明中我必须提到的是什么:

protected $base_url = '???????????';

从哪个链接我会得到正确答案?

与区块链连接的确切程序是什么?

请告诉我这个..

1 个答案:

答案 0 :(得分:1)

我是Codeigniter-blockchain图书馆的作者。

base_url是指向您安装的区块链钱包服务的网址,可以找到安装服务的完整指南here

您需要安装nodejsnpm

要安装区块链钱包服务,请运行以下命令:

npm install -g blockchain-wallet-service

现在安装完成后,您可以使用以下命令启动它:

blockchain-wallet-service start --port 3000

3000是端口号,如果您愿意,可以更改它。

现在回到图书馆:

protected $base_url = '???????????';

这应设置为安装区块链钱包服务的网址,在本例中为localhost127.0.0.1,默认情况下已设置。

protected $port = 3000;

这是Blockchain Wallet Service正在运行的端口号,它应该与您在启动服务时使用的端口相同。