/** 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; $tpUsername = $postObj->tousername; $keyword =trim ($ postobj->content); $time =time (); $TEXTTPL = "
%s 0
%s
%s
%s
%s
"If (!empty ($keyword)) {$msgType =" text "; $contentStr =" 1 Phone mailbox 2.QQ Information 3 address information "; if ($keyword = =" 1 ") {//keyword 1 o'clock reply $contentstr = "Tel: 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 keyword Auto-response code, including the content, I hope that the PHP tutorial interested in a friend helpful.