1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace TronTool;
- use GuzzleHttp\Client;
- class NodeClient{
- protected $client;
-
- static function mainNet(){
- return new self('https://api.trongrid.io');
- }
-
- static function testNet(){
- return new self('https://api.shasta.trongrid.io');
- }
-
- function __construct($uri){
- $opts = [
- 'base_uri' => $uri,
- 'verify' => false
- ];
- $this->client = new Client($opts);
- }
-
- function post($api,$payload=[]){
- $opts = [
- 'json' => $payload
- ];
- $rsp = $this->client->post($api,$opts);
- return $this->handle($rsp);
- }
-
- function get($api,$query=[]){
- $opts = [
- 'query' => $query
- ];
- $rsp = $this->client->get($api,$opts);
- return $this->handle($rsp);
- }
-
- function handle($rsp){
- $content = $rsp->getBody();
- //echo $content . PHP_EOL;
- return json_decode($content);
- }
-
- function version(){
- return '1.0.0';
- }
- }
|