From 7340196bd106ef995261226348fd73708d88d4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 28 Oct 2021 16:19:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RpcJsonp.php | 17 ++++++++++++----- src/RpcManager.php | 6 +++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/RpcJsonp.php b/src/RpcJsonp.php index d296415..8187453 100644 --- a/src/RpcJsonp.php +++ b/src/RpcJsonp.php @@ -97,7 +97,11 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa private function batchDispatch(Server $server, int $fd, array $data): void { if (isset($data['jsonrpc'])) { - $result = json_encode($this->dispatch($data), JSON_UNESCAPED_UNICODE); + $dispatch = $this->dispatch($data); + if (!isset($data['id'])) { + $dispatch = [1]; + } + $result = json_encode($dispatch, JSON_UNESCAPED_UNICODE); } else { $channel = new Channel($total = count($data)); foreach ($data as $datum) { @@ -124,7 +128,11 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa } else if (!isset($datum['method'])) { $channel->push($this->failure(-32700, 'Parse error语法解析错误')); } else { - $channel->push($this->dispatch($datum)); + $dispatch = $this->dispatch($datum); + if (!isset($dispatch['id'])) { + $dispatch = [1]; + } + $channel->push($dispatch); } }); } @@ -141,7 +149,7 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa if (is_null($handler)) { throw new \Exception('Method not found', -32601); } else { - return $this->handler($handler, $params, $data); + return $this->handler($handler, $data); } } catch (\Throwable $throwable) { $code = $throwable->getCode() == 0 ? -32603 : $throwable->getCode(); @@ -152,11 +160,10 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa /** * @param array $handler - * @param array $params * @param $data * @return array */ - private function handler(array $handler, array $params, $data): array + private function handler(array $handler, $data): array { $controller = Kiri::getDi()->get($handler[0]); diff --git a/src/RpcManager.php b/src/RpcManager.php index f1286c7..ce70b25 100644 --- a/src/RpcManager.php +++ b/src/RpcManager.php @@ -26,10 +26,10 @@ class RpcManager foreach ($lists as $reflection) { $methodName = $reflection->getName(); +// +// $params = Kiri::getDi()->getMethodParameters($class, $methodName); - $params = Kiri::getDi()->getMethodParameters($class, $methodName); - - static::$_rpc[$name][$methodName] = [[$class, $methodName], $params]; + static::$_rpc[$name][$methodName] = [[$class, $methodName], null]; } return true; }