您好,欢迎访问一九零五行业门户网

问题:微信公众平台的开发中一直显示的是 token验证失败

url能够正常的访问
使用的是微信公众平台给出的文档。
valid(); }else { }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)){ /* libxml_disable_entity_loader is to prevent xml external entity injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $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() { // you must define token by yourself if (!defined(token)) { throw new exception('token is not defined!'); } $signature = $_get[signature]; $timestamp = $_get[timestamp]; $nonce = $_get[nonce]; $token = token; $tmparr = array($token, $timestamp, $nonce); // use sort_string rule sort($tmparr, sort_string); $tmpstr = implode( $tmparr ); $tmpstr = sha1( $tmpstr ); if( $tmpstr == $signature ){ return true; }else{ return false; } }}?>

改动位置就在最前面加入了一个if 判断,后面没有做任何的修改
google了方法也试了没有解决,所有在这里发帖了,谢谢各位。
回复内容: url能够正常的访问
使用的是微信公众平台给出的文档。
valid(); }else { }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)){ /* libxml_disable_entity_loader is to prevent xml external entity injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $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() { // you must define token by yourself if (!defined(token)) { throw new exception('token is not defined!'); } $signature = $_get[signature]; $timestamp = $_get[timestamp]; $nonce = $_get[nonce]; $token = token; $tmparr = array($token, $timestamp, $nonce); // use sort_string rule sort($tmparr, sort_string); $tmpstr = implode( $tmparr ); $tmpstr = sha1( $tmpstr ); if( $tmpstr == $signature ){ return true; }else{ return false; } }}?>

改动位置就在最前面加入了一个if 判断,后面没有做任何的修改
google了方法也试了没有解决,所有在这里发帖了,谢谢各位。
我们在学习的时候也是遇到这个问题,请你用的是租用的虚拟空间,还是利用百度app或者是新浪app的云服务器,如果是前者提到的,那么需要先完成实名验证的。这样才可以去掉那个烦人的提醒,能可以连上微信后台服务器。
如果还是有其他问题,可以继续提问,谢谢
phpif($_get[echostr]){$wechatobj->valid();}else { $wechatobj->responsemsg();//?}
你要确保你 echo $echostr; 之前没有任何输出才行。。。
其它类似信息

推荐信息