怎么处理微信"token验证失败”

如题所述

第1个回答  2022-07-08
一.

1. 首先要了解的是什么是URL和Token,

在这里,URL就是放置了接口程序的网址,这个网址一般得是你自己的服务器或空间地址。你自己在这个空间上某个目录已经有接口程序了,你知道这个接口程序在互联网上的访问地址是什么。而Token就是一个令牌,该令牌是个数字或字母形式的字符串,用于微信服务器与你的服务器进行通讯的时候的身份验证。防止非法数据来搞乱。

2. 然后要了解的是开发模式为什么要使用Url和Token,

使用url是为了让微信服务器和你的服务器进行通讯对话,从而达到开发模式下自动回复的目的。而实现这个通讯,必须有相应的程序为你完成这个功能,而这个程序必须已经开发完成并且放置于url路径下面,当你填写完url和token的时候,微信服务器就会和你的服务器下的程序进行一次认证过程,认证通过表明这个服务器是你的并且程序没有问题。不然你填个不存在的url或者url下面个没有相应的接口功能,那是通不过的。

3.那么如何处理如下问题”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 = " %s 0 ";             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; } } } ?>

2.在微擎中修改token值也是为roselife

3.登陆微信公众平台中:开发——基本配置——修改配置中

a.服务器配置地址(URL):域名后后面跟wx_sample.php

b.token填写的也是roselife
相似回答
大家正在搜