From 9523b00c7bcf35624a8958c6e2e2137ac87cf1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 23 Mar 2021 18:05:16 +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 --- Rpc/Client.php | 5 +++-- Rpc/Service.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) 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()]); } }); }