Home > php教程 > php手册 > php版本微信公众平台回复乱码问题解决方法

php版本微信公众平台回复乱码问题解决方法

WBOY
Release: 2016-05-26 08:20:51
Original
1677 people have browsed it

微信公众平开发时碰到回复中文乱码了,这个问题小编发现是编码问题,其实只要把编码转成utf8就可以解决了,具体来看看。

很多微信公众平台的自动回复程序都是 ThinkWechat.class.php 这个类开发的,今天碰到一个莫名其妙的乱码问题,查问题发现是GB2312编码导致,所以要修改源码。

先增加一个方法

/**
 * 检测是否UTF-8
 * @param $str
 * @return bool
 */
private function is_utf8($str)
{
    return preg_match('//u', $str);
}
Copy after login

找到

$this->data ['Content'] = $content;
Copy after login

修改为

if ($this->is_utf8($content)) {
    $this->data ['Content'] = $content;
} else {
    $this->data ['Content'] = iconv('gb2312', 'UTF-8//IGNORE', $content);
}
Copy after login

即可

文章网址:

随意转载^^但请附上教程地址。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template