/** 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 =" Hi welcome your attention! "; $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 automatic response code, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.