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

修正获取关注者详细信息可能出现的错误 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mako0403
Copy link
Contributor

如用户信息某一字段存在特殊字符,这导致JSON_DECODE返回NULL,现对微信服务器请求结果进行编码替换后在进行解析。

示例代码:
$str = '{"subscribe":1,"openid":"o7TC3v_zvuxmuRPU6YeBOD6cz0Ng","nickname":"文文","sex":2,"language":"zh_CN","city":"S�Y4","province":"Q���Sä","country":"","headimgurl":"http://wx.qlogo.cn/mmopen/0dhrpQA7Vn64H2u2zApyiaicEg4hk0UCIqrJP0EcRDh1z108ARaaWUYIDfmLvBXicxGpo4uWej1PjsdMZcWIdPQ7TJehRnLWaJD/0","subscribe_time":1482894792,"remark":"","groupid":0,"tagid_list":[]}';

json_decode($str, true); 返回NULL 主要原因是city字段含有特殊符合或表情符号

如用户信息某一字段存在特殊字符,这导致JSON_DECODE返回NULL,现对微信服务器请求结果进行编码替换后在进行解析。
@zoujingli
Copy link
Owner

微信中用户信息的地址也出现了特殊字符吗? 我目前还没有发现

@mako0403
Copy link
Contributor Author

有这种情况,我贴出的实例代码就是拉取到的一位用户的信息,而且这个CITY字段不同编码解析出来内容也不一样,导致JSON_DECODE无法解析。你把示例代码json直接用json_decode试一下就可以看出问题了

@docXU
Copy link

docXU commented Oct 13, 2017

微信服务器会返回规定编码的字符串,我觉得特殊字符也会被微信端转换为UTF-8 ,所以目前应该无需考虑这个问题,之所以这里出现特殊字符,可能是楼主在浏览器直接访问接口时浏览器的编码为GBK或者GB18030,试着修改一下浏览器的默认编码为UTF-8

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

Successfully merging this pull request may close these issues.

3 participants