This commit is contained in:
2021-10-28 16:19:20 +08:00
parent cd17f2b63b
commit 7340196bd1
2 changed files with 15 additions and 8 deletions
+12 -5
View File
@@ -97,7 +97,11 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
private function batchDispatch(Server $server, int $fd, array $data): void private function batchDispatch(Server $server, int $fd, array $data): void
{ {
if (isset($data['jsonrpc'])) { 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 { } else {
$channel = new Channel($total = count($data)); $channel = new Channel($total = count($data));
foreach ($data as $datum) { foreach ($data as $datum) {
@@ -124,7 +128,11 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
} else if (!isset($datum['method'])) { } else if (!isset($datum['method'])) {
$channel->push($this->failure(-32700, 'Parse error语法解析错误')); $channel->push($this->failure(-32700, 'Parse error语法解析错误'));
} else { } 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)) { if (is_null($handler)) {
throw new \Exception('Method not found', -32601); throw new \Exception('Method not found', -32601);
} else { } else {
return $this->handler($handler, $params, $data); return $this->handler($handler, $data);
} }
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
$code = $throwable->getCode() == 0 ? -32603 : $throwable->getCode(); $code = $throwable->getCode() == 0 ? -32603 : $throwable->getCode();
@@ -152,11 +160,10 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
/** /**
* @param array $handler * @param array $handler
* @param array $params
* @param $data * @param $data
* @return array * @return array
*/ */
private function handler(array $handler, array $params, $data): array private function handler(array $handler, $data): array
{ {
$controller = Kiri::getDi()->get($handler[0]); $controller = Kiri::getDi()->get($handler[0]);
+3 -3
View File
@@ -26,10 +26,10 @@ class RpcManager
foreach ($lists as $reflection) { foreach ($lists as $reflection) {
$methodName = $reflection->getName(); $methodName = $reflection->getName();
//
// $params = Kiri::getDi()->getMethodParameters($class, $methodName);
$params = Kiri::getDi()->getMethodParameters($class, $methodName); static::$_rpc[$name][$methodName] = [[$class, $methodName], null];
static::$_rpc[$name][$methodName] = [[$class, $methodName], $params];
} }
return true; return true;
} }