How to solve the problem of Token verification failure or request URL timeout in the development of Wechat for php
This article is about how to solve the problem of Token verification failure or request URL timeout in the development of Wechat for php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1.Token verification failed
This is to check the configuration file, the most basic is
Define ("TOKEN", "weixin"); weixin is the ID behind your Wechat development.
Solution to the problem of Token verification failure or request URL timeout in Wechat development
two。 Request URL timed out
There is no way to submit this a few more times, and this is that the server installed software such as a security dog to block Wechat IP, you can check it.
3. Officially download a wechatCallbackapiTest class and do some operations, as shown below:
Define ("TOKEN", "weixin"); $wechatObj = new wechatCallbackapiTest (); if (isset ($_ GET ['echostr'])) {$wechatObj- > valid ();} else {$wechatObj- > responseMsg ();}
The code for the wechatCallbackapiTest class is as follows:
Class wechatCallbackapiTest {public function valid () {$echoStr = $_ GET ["echostr"]; if ($this- > checkSignature ()) {echo $echoStr; 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;}} public function responseMsg () {$postStr = $GLOBALS ["HTTP_RAW_POST_DATA"]; if (! emptyempty ($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 ($keyword! = "" | |! emptyempty ($keyword)) {msgType = "text"; / / $contentStr. = date ("Y-m-d H:i:s", time ()) $resultStr = sprintf ($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr;}} else {echo "; exit;}} thank you for reading! On "how to solve the php version of Wechat development Token verification failure or request URL timeout problem," this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!