From d5470ca40da57c89d6867d6614c5ec7fbeac4cab Mon Sep 17 00:00:00 2001 From: dongwei <838456736@qq.com> Date: Sat, 19 Jan 2019 17:10:30 +0800 Subject: [PATCH] JsonResponse --- src/Server/JsonRpcMethod.php | 14 ++++---------- src/Server/JsonRpcServer.php | 5 +++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Server/JsonRpcMethod.php b/src/Server/JsonRpcMethod.php index b5abd77..555e5c6 100644 --- a/src/Server/JsonRpcMethod.php +++ b/src/Server/JsonRpcMethod.php @@ -17,29 +17,23 @@ class JsonRpcMethod public function response($result) { - return JsonResponse::create([ + return [ 'jsonrpc' => '2.0', 'result' => $result, 'id' => $this->id - ]); + ]; } - /** - * - * @param $code - * @param $msg - * @return static - */ public function error($code, $msg) { - return JsonResponse::create([ + return [ 'jsonrpc' => '2.0', 'error' => [ 'code' => $code, 'message' => is_array($msg) ? json_encode($msg) : $msg, ], 'id' => $this->id - ]); + ]; } } \ No newline at end of file diff --git a/src/Server/JsonRpcServer.php b/src/Server/JsonRpcServer.php index 2129097..465a550 100644 --- a/src/Server/JsonRpcServer.php +++ b/src/Server/JsonRpcServer.php @@ -65,8 +65,9 @@ class JsonRpcServer app('rpc.logger')->info('server', [$id, $class,$method, $params, $this->request->header('client_app'), $this->request->header('client_addr'), $this->request->header('client_host')]); $ret = call_user_func_array([(new $class($id, $this->request)), $function], $params); - app('rpc.logger')->info('server_result', [$id, \GuzzleHttp\json_decode($ret, true)]); - return $ret; + app('rpc.logger')->info('server_result', [$id, $ret]); + + return JsonResponse::create($ret); } catch (\InvalidArgumentException $e) { return $this->error(self::Rpc_Error_Parse_Error);