Yesterday, the message interface of the public platform was connected to a blog, which enables users to display messages directly in the blog when sending messages to the public account. Yesterday, the message interface of the public platform was connected to a blog, which enables users to display messages directly in the blog when sending messages to the public account.
In fact, the development of the Message Interface function of the public platform can achieve many functions. this is just a very simple application, such as inputting specific characters in many public accounts to return the corresponding data, querying weather, and translating Chinese and English.
Next I will post the PHP SDK provided by the public platform:
valid(); class wechatCallbackapiTest{public function valid() { $echoStr = $_GET["echostr"]; //valid signature , option if($this->checkSignature()){ echo $echoStr; exit; } } public function responseMsg() {//get post data, May be 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; $keyword = trim($postObj->Content); $time = time(); $textTpl = "
%s
%s
%s
%s
%s
0
"; if(!empty( $keyword )) { $msgType = "text"; $contentStr = "Welcome to wechat world!"; $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;}}} ?>
Specific can view the public platform Message Interface Guide: http://mp.weixin.qq.com/wiki/index.php? Title = % E6 % B6 % 88% E6 % 81% AF % E6 % 8E % A5 % E5 % 8F % A3 % E6 % 8C % 87% E5 % 8D % 97
This SDK provides two simple operations: public platform information submission and verification, and user message reply. we can implement different requirements based on different message interfaces provided in the interface guide.