轉自:點擊開啟連結 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 = " %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; } } } ?> 以上為騰訊官方提供的介面文件範例。 解決問題其實很簡單,微信文檔似乎沒寫(或沒找到==): 驗證token時使用:$wechatObj->valid(); 正式生產環境中需要回覆$wechatObj->responseMsg(); 問題解決。 以上就介紹了關於微信公共平台"你的服務未能正確回應Token驗證"錯誤的解決辦法,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。