GatewayWorker tcp 上传json数据带有中文字符的显示为空

gaohaichao

我的是linux系统 php7.2
GatewayWorker tcp 上传json数据带有中文字符的显示为空
这是什么问题
{"method":"imvoice","Devices":"sss121","voicetext":"你好吗哈哈哈"}

948 1 1
1个回答

walkor 打赏

json需要utf-8编码,文件编码和网页编码改成utf-8试下。

  • gaohaichao 2022-04-26

    <?php

    header('Content-type: application/json;charset=utf-8');
    use \GatewayWorker\Lib\Gateway;
    use \GatewayWorker\Lib\Db;
    class Events
    {
    public static function onConnect($client_id)
    {
    echo"client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway1:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']} client_id:$client_id\n";
    }

    public static function onMessage($client_id, $message){
    $db = Db::instance('db');
    echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']}
    gateway2:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']} $message\n";

    好像还不行 gateway2:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']} $message\n"; 中文就是不显示 如果是其他字符就可以,或者吧中文转成unicode编码 也可以,就是纯中文死活不显示

  • gaohaichao 2022-04-26

    {"method":"svsice","Device_ID":"232323233","voicetext":"你好"}

  • gaohaichao 2022-04-26

    解决了谢谢

年代过于久远,无法发表回答
×
🔝