In this public platform development tutorial, we assume that you already have PHP language programs, MySQL databases, computer network communication, and HTTPXMLCSSJS. In this public platform development tutorial, we assume that you already have the PHP language program, MySQL database, computer network communication, and HTTP/XML/CSS/JS basics.
We will use the public account Fang times studio as an example. the QR code can be found at the bottom.
This series of tutorials will guide you through the following tasks:
Apply for resources on the Baidu Cloud Platform
Enable public platform development mode
Article 1 Apply for server resources
Create a Baidu Cloud Application
Apply for an account
Log on to the http://developer.baidu.com/bae, use your mailbox or phone to register an account, registration needs to be bound to a mobile phone and verify the mailbox at the same time.
Create an application
Click
valid();}else{ $wechatObj->responseMsg();}class wechatCallbackapiTest{ public function valid() { $echoStr = $_GET["echostr"]; if($this->checkSignature()){ echo $echoStr; 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; } } public function responseMsg() { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!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($keyword == "?" || $keyword == "?") { $msgType = "text"; $contentStr = date("Y-m-d H:i:s",time()); $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } }else{ echo ""; exit; } }}?>
And then compress it into ZIP format, not RAR format
URL: http://pondbay.duapp.comToken: pondbay
Enter as shown in,
So far, your public platform account has automatically responded.
For more articles about enabling APIs for Message Interface development on the public platform, refer to PHP Chinese network!