转自:点击打开链接
http://lvwenhan.com/create/372.html
实质:就是使用官方文件,调用
$wechatobj->valid();而不是,注释后,调用:
$wechatobj->responsemsg();关于微信公共平台你的服务未能正确响应token验证错误的解决办法valid();class wechatcallbackapitest{ public function valid() { $echostr = $_get[echostr]; //valid signature , option if($this->checksignature()){ echo $echostr; exit; } } public function responsemsg() { //get post data, may be due to the different environments $poststr = $globals[http_raw_post_data]; //extract post data if (!empty($poststr)){ $postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $fromusername = $postobj->fromusername; $tousername = $postobj->tousername; $keyword = trim($postobj->content); $time = time(); $texttpl = %s0; if(!empty( $keyword )) { $msgtype = text; $contentstr = welcome to wechat world!; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; }else{ echo input something...; } }else { echo ; exit; } } private function checksignature() { $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 ){ return true; }else{ return false; } }}?> 以上为腾讯官方提供的接口文件示例。解决问题其实很简单,微信文档貌似没写(或者我没找到==):
验证token时使用:$wechatobj->valid();正式生产环境中需要回复用户消息时,使用:$wechatobj->responsemsg();
问题解决。
以上就介绍了关于微信公共平台你的服务未能正确响应token验证错误的解决办法,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。