diff --git a/Rpc/Client.php b/Rpc/Client.php index af06d124..b98e2b6f 100644 --- a/Rpc/Client.php +++ b/Rpc/Client.php @@ -7,6 +7,7 @@ namespace Rpc; use Exception; use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Config; +use Snowflake\Core\Json; use Snowflake\Exception\ConfigException; use Swoole\Coroutine\Client as CClient; @@ -47,12 +48,12 @@ class Client extends Component return $this->addError($this->client->errMsg . '(' . $this->client->errCode . ')'); } } - $isSend = $this->client->send(serialize(['cmd' => $cmd, 'body' => $param])); + $isSend = $this->client->send(Json::encode(['cmd' => $cmd, 'body' => $param])); if ($isSend === false) { return $this->addError($this->client->errMsg . '(' . $this->client->errCode . ')'); } - if (is_bool($unpack = unserialize($this->client->recv()))) { + if (is_bool($unpack = Json::decode($this->client->recv()))) { return $this->addError('Service return data format error(500)'); } return $unpack; diff --git a/Rpc/Service.php b/Rpc/Service.php index aa14b044..7e429abf 100644 --- a/Rpc/Service.php +++ b/Rpc/Service.php @@ -73,10 +73,10 @@ class Service extends Component if (($node = router()->find_path($this->replace($request, $service))) === null) { throw new Exception('Cmd not find.'); } - return serialize($node->dispatch()); + return Json::encode($node->dispatch()); } catch (\Throwable $exception) { $this->addError($exception); - return serialize(['state' => 'fail', 'message' => $exception->getMessage()]); + return Json::encode(['state' => 'fail', 'message' => $exception->getMessage()]); } }); }