A feature recently used for development is actually a very simple user input, and then the database is automatically searched for and a data reply. This is not a big problem with the official team, however, I have made a lot of effort in Token verification failure. I will give you an analysis on the Solution Below. A feature recently used for development is actually a very simple user input, and then the database is automatically searched for and a data reply. This is not a big problem with the official team, however, I have made a lot of effort in Token verification failure. I will give you an analysis on the Solution Below.
Script ec (2); script
1. Failed Token Verification
This is to check the configuration file, the most basic is
Define ("TOKEN", "weixin"); weixin is the ID of your development background
2. request URL timeout
There is no way to submit it several times. This is also because the server has installed software such as dongle to intercept the IP address. You can check it.
3. Download a wechatCallbackapiTest class and perform the following operations.
The Code is as follows: |
|
Define ("TOKEN", "weixin "); $ WechatObj = new wechatCallbackapiTest (); If (isset ($ _ GET ['echostr']) { $ WechatObj-> valid (); } Else { $ WechatObj-> responseMsg (); } |
The code for the wechatCallbackapiTest class is as follows:
The Code 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 (! Empty ($ postStr )){ $ PostObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA ); $ FromUsername = $ postObj-> FromUserName; $ ToUsername = $ postObj-> ToUserName; $ Keyword = trim ($ postObj-> Content ); $ Time = time (); $ TextTpl =" %s %s % S %s %s 0 "; If ($ keyword! = "" |! Empty ($ 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; } } } |