JsonResponse
This commit is contained in:
parent
ffca2c303b
commit
d5470ca40d
|
@ -17,29 +17,23 @@ class JsonRpcMethod
|
||||||
|
|
||||||
public function response($result)
|
public function response($result)
|
||||||
{
|
{
|
||||||
return JsonResponse::create([
|
return [
|
||||||
'jsonrpc' => '2.0',
|
'jsonrpc' => '2.0',
|
||||||
'result' => $result,
|
'result' => $result,
|
||||||
'id' => $this->id
|
'id' => $this->id
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param $code
|
|
||||||
* @param $msg
|
|
||||||
* @return static
|
|
||||||
*/
|
|
||||||
public function error($code, $msg)
|
public function error($code, $msg)
|
||||||
{
|
{
|
||||||
return JsonResponse::create([
|
return [
|
||||||
'jsonrpc' => '2.0',
|
'jsonrpc' => '2.0',
|
||||||
'error' => [
|
'error' => [
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
'message' => is_array($msg) ? json_encode($msg) : $msg,
|
'message' => is_array($msg) ? json_encode($msg) : $msg,
|
||||||
],
|
],
|
||||||
'id' => $this->id
|
'id' => $this->id
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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')]);
|
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);
|
$ret = call_user_func_array([(new $class($id, $this->request)), $function], $params);
|
||||||
app('rpc.logger')->info('server_result', [$id, \GuzzleHttp\json_decode($ret, true)]);
|
app('rpc.logger')->info('server_result', [$id, $ret]);
|
||||||
return $ret;
|
|
||||||
|
return JsonResponse::create($ret);
|
||||||
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
return $this->error(self::Rpc_Error_Parse_Error);
|
return $this->error(self::Rpc_Error_Parse_Error);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user