The case code also runs out of control. I did some research and finally got it done.
First of all:
Upload an interface file on your server, such as the http://www.xxx.com/weixin.php content as follows:
| The code is as follows |
Copy Code |
| ? <?php Define ("TOKEN", "Weixin"); Define ("MESS", "input point"); $WECHATOBJ = new Wechatcallbackapitest (); $WECHATOBJ->valid (); $WECHATOBJ->responsemsg (); Class Wechatcallbackapitest { Public Function Valid () { $ECHOSTR = $_get["Echostr"]; if ($this->checksignature ()) { Echo $echoStr; Exit } } 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 = "<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 (!empty ($keyword)) { $msgType = "text"; $CONTENTSTR = MESS; $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR); Echo $resultStr; }else{ Echo MESS; } }else { Echo MESS; 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; } } } ?>
|
And then:
Set up the reply interface, fill in the URL and token (must be consistent with the token defined above)
This interface has to be validated first, after success
Then comment out the $wechatobj->valid (); This line, while removing//$WECHATOBJ->responsemsg (), the comment for this line.
The message interface can be used, send a message to try?