Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中文转码问题直接传第二个参数JSON_UNESCAPED_UNICODE即可 #361

Open
ionepub opened this issue Sep 19, 2018 · 1 comment
Open

Comments

@ionepub
Copy link

ionepub commented Sep 19, 2018

类中自定义了一个json_encode方法,避免在内容中有中文时会被转义成unicode,导致收到的消息是乱码(unicode),其实php中可以向json_encode方法传递第二个参数的值为 JSON_UNESCAPED_UNICODE,这个时候中文不会转义

json_encode(['index' => '中文'], JSON_UNESCAPED_UNICODE);  // 输出: {"index": "中文"}
@landall
Copy link

landall commented Dec 5, 2018

类里边的json函数无法正确处理\n,在发送字段里包含\n的模板消息时无法正确被微信识别。

我简单改了一下,还没充分测试。
static function json_encode($arr) {
return json_encode($arr, JSON_UNESCAPED_UNICODE);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants