In this paper, we analyze the solution to the problem of token authentication failure or request URL Timeout in PHP version of micro-credit development. Share to everyone for your reference, specific as follows:
One of the most recent features of micro-credit development in fact, is a very simple user input and then automatically search the database and a data reply, this and the official not much problem, but small series on the micro-letter token verification failed to toss a lot, the following resolved to analyze for you.
1.Token validation failed
This is to check the configuration file, the most basic is
Define ("TOKEN", "Weixin"); Weixin is the ID of your micro-credit development backstage.
Micro-credit Development token authentication failure or request URL Timeout problem Resolution
2. Request URL Timeout
This is no way to submit more than a few times, this is the server installed a security dog, such as software to intercept the micro-letter IP, you can check.
3. The official download a Wechatcallbackapitest class and then the operation can be, the code is as follows:
Define ("TOKEN", "Weixin");
$WECHATOBJ = new Wechatcallbackapitest ();
if (Isset ($_get[' echostr ')) {
$wechatObj->valid ();
} else{
$wechatObj->responsemsg ();
}
The Wechatcallbackapitest class has the following code:
Class Wechatcallbackapitest {public function valid () {$echoStr = $_get["Echostr"];
if ($this->checksignature ()) {echo $echoStr;
Exit
The 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;
The 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 = "<xml> <tousername><! [cdata[%s]]></ToUserName> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype><![ Cdata[%s]]></msgtype> <content><!
[cdata[%s]]></content> <FuncFlag>0</FuncFlag> </xml> "; 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
}
}
}
For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary
I hope this article will help you with the PHP program design.