This commit is contained in:
dongwei 2019-01-10 14:17:13 +08:00
parent 4964dade7d
commit d903ae3284
2 changed files with 8 additions and 3 deletions

View File

@ -4,18 +4,21 @@ namespace JsonRpc;
use GuzzleHttp\Exception\ServerException; use GuzzleHttp\Exception\ServerException;
use JsonRpc\Exception\RpcServerException; use JsonRpc\Exception\RpcServerException;
use Monolog\Logger;
class Client class Client
{ {
protected $config; protected $config;
protected $id; protected $id;
protected $logger;
/** /**
* @var \GuzzleHttp\Client * @var \GuzzleHttp\Client
*/ */
protected $http; protected $http;
public function __construct($config) public function __construct($config, Logger $logger)
{ {
$default = [ $default = [
'app' => '***', 'app' => '***',
@ -23,6 +26,7 @@ class Client
$this->config = array_merge($default, $config); $this->config = array_merge($default, $config);
$this->id = 0; $this->id = 0;
$this->logger = $logger;
} }
public function endpoint($k) public function endpoint($k)
@ -90,6 +94,7 @@ class Client
if (isset($body['error']) && isset($body['error']['code']) && isset($body['error']['message'])) { if (isset($body['error']) && isset($body['error']['code']) && isset($body['error']['message'])) {
throw new RpcServerException($body['error']['message'], $body['error']['code']); throw new RpcServerException($body['error']['message'], $body['error']['code']);
} }
$this->logger->info('this is a test call log');
return $body['result']; return $body['result'];
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {

View File

@ -19,8 +19,8 @@ class ClientServiceProvider extends ServiceProvider
$this->app->configure('rpc'); $this->app->configure('rpc');
$config = config('rpc.client'); $config = config('rpc.client');
// $logger = new Logger('rpc-client-logger'); $logger = new Logger('rpc-client-logger');
// $logger->pushHandler(new StreamHandler($this->app->storagePath()."/logs/rpc_client_".date("Ymd").".log")); $logger->pushHandler(new StreamHandler($this->app->storagePath()."/logs/rpc_client_".date("Ymd").".log"));
$this->app->singleton('rpc', function () use ($config) { $this->app->singleton('rpc', function () use ($config) {
return new Client($config); return new Client($config);
}); });