/** WeChat php Test*///define your Tokendefine ("TOKEN", "Weixin"); $wechatObj =new wechatcallbackapitest (); $WECHATOBJ-& Gt;valid (); $wechatObj->responsemsg (); class Wechatcallbackapitest{public function valid () {$echoStr = $_get[' Echostr '];//valid signature, optionif ($this->checksignature ()) {echo $echoStr; exit;}} Public Function responsemsg () {//get post data, May is due to the different environments$poststr = $GLOBALS ["Http_raw_post _data "];//extract Post Dataif (!empty ($POSTSTR)) {$POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', Libxml_nocdata); $fromUsername = $postObj->fromusername; $toUsername = $postObj->tousername; $type = $postObj-> ; Msgtype; $customevent = $postObj->event; $keyword =trim ($postObj->content); $time =time (); $TEXTTPL = "
%s
%s
%s
%s
%s
0
"if ($type = =" Event "and $customevent = =" Subscribe ") {$CONTENTSTR =" Thank you for your attention \ reply 1 phone mailbox \ n reply to the 2.QQ message \ n reply to 3 address information "; $msgType = "Text"; $resultStr = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr;} if (!empty ($keyword)) {$msgType = "text"; $contentStr = "1 Phone mailbox 2.QQ Information 3 address information"; if ($keyword = = "1") {//keyword 1 o'clock reply $contentstr = "Power Words: 15057190640 email:2323178881@qq.com! ";} if ($keyword = = "2") {//Keyword 2 o'clock reply $contentstr = "My QQ is 2323178881!";} if ($keyword = = "3") {//Keyword 3 o'clock reply $contentstr = "Zha nong Kou Jie Dao, Jianggan District, Hangzhou city, Zhejiang province";} $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;}}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the focus on the reply code, including the content, I hope the PHP tutorial interested in a friend helpful.