Skip to content

Commit

Permalink
完善测试
Browse files Browse the repository at this point in the history
  • Loading branch information
HZ-YWH committed Oct 14, 2017
1 parent 87a003d commit 9c9d801
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down

0 comments on commit 9c9d801

Please sign in to comment.