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

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

May 26, 2016 am 08:20 AM
iconv preg_match

微信公众平开发时碰到回复中文乱码了,这个问题小编发现是编码问题,其实只要把编码转成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

即可

文章网址:

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

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)