From 9c9d801b918b859f195172e32f51ca519687ab50 Mon Sep 17 00:00:00 2001 From: YWH <773837391@qq.com> Date: Sat, 14 Oct 2017 21:33:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/App.php b/App.php index d06db03..3a7f230 100644 --- a/App.php +++ b/App.php @@ -207,13 +207,33 @@ public function onClientMessage($connection,$data){ // 添加默认参数 json_encode的JSON_UNESCAPED_UNICODE参数 使之支持中文 不转义 public function ServerJson($data,$option=JSON_UNESCAPED_UNICODE){ Http::header("Content-type: application/json"); - if ($option) { + //传入0 不做处理 + if ($option==0){ + $this->conn->send(json_encode($data)); + }else{ + + if ($option==JSON_UNESCAPED_UNICODE) { // json_encode的JSON_UNESCAPED_UNICODE参数 PHP版本必须是5.4以上 - if (version_compare(PHP_VERSION,'5.4.0','>=')) { - $this->conn->send(json_encode($data,$option)); + if (version_compare(PHP_VERSION,'5.4.0','>=')) { + $this->conn->send(json_encode($data,$option)); + }else{ +// PHP版本小于5.3的支持 未经测试 + +// 实现方法一 如下 实现方法二 可以使用urldecode函数 +// $str = json_encode($data); +// $str = preg_replace_callback("#\\\u([0-9a-f]{4})#i",function($matchs){ +// iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1])); +// },$str); +// $this->conn->send($str); + $this->conn->send(json_encode($data)); + } } + +// 如果传入了别的参数 + $this->conn->send(json_encode($data),$option); + + } - $this->conn->send(json_encode($data)); }