This article is about the public platform developer mode of activation and automatic response, has a certain reference value, now share to everyone, the need for friends can refer to
First, what is developer mode?
The developer mode is to verify your server address first, and once the user sends a message to the public, the user's message will be forwarded to the address. after your server has received the data, then you design a set of programs yourself , a result is output and returned to the user by the server.
Personal learning Development Recommended use test number
Test number address: Http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
After logging in, fill in the interface configuration information with the URL address and token that you just generated.
The URL address is the two-level domain name address.
Token is fixed to Weixin in the program
Fill in the submission, prompt configuration success!
if prompted " Token validation failed ", multiple times a few times.
<?php//define your Tokendefine ("TOKEN", "Weixin"); $wechatObj = new Wechatcallbackapitest (); $wechatObj->run (); Class Wechatcallbackapitest{public function Run () {if ($this->checksignature () = = False) {die ("illegal request"); } if (Isset ($_get["Echostr")) {$echoStr = $_get["Echostr"]; Echo $echoStr; Exit }else{$this->responsemsg (); }} Public Function responsemsg () {//get post data, could be due to the different environments$poststr = $GLOBALS ["HTTP _raw_post_data "];//$postStr = file_get_contents (" Php://input "); File_put_contents (' Msg.txt ', $POSTSTR, File_append) ; Extract Post Dataif (!empty ($POSTSTR)) {$POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', LIBX Ml_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 = "Hello!" "; $CONTENTSTR = "hi!"; $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;}}? >