JsonResponse

This commit is contained in:
dongwei 2019-01-19 17:10:30 +08:00
parent ffca2c303b
commit d5470ca40d
2 changed files with 7 additions and 12 deletions

View File

@ -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
]);
];
}
}

View File

@ -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);