1、服务器配置是阿里云的linux

2、下载微信的Token验证Demo,放于根目录测试链接没有任何问题: URL http://www.XXX.com/wx_sample.php Token weixin

3、将验证代码置于TP框架中(application/Weixin/Controller/IndexController.php): <?php namespace Wxapi\Controller;

use Think\Controller; class IndexController extends Controller { function index() { define('TOKEN','weixin'); // $this->valid(); if (!isset($_GET['echostr'])) { $this->responseMsg(); } else { $this->valid(); } } //接收消息验证 public function valid() { $echoStr = $_GET["echostr"]; $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if ($tmpStr == $signature) { ** ob_clean(); //增加的一行** echo $echoStr; exit; } }

通过访问:
URL     http://www.XXX.com/index.php/Weixin/Index/index

Token weixin

配置始终失败!

4、问题所在:Thinkephp框架index入口文件utf-8编码返回BOM头问题

5、解决方式: (1)去掉index.php的BOM头。可以用编程工具新建一个index.php,重新写入代码替换掉入口文件 (2)在echo $echoStr; 前增加语句ob_clean();