Home > Article > WeChat Applet > A preliminary study on the development of WeChat development platform
WeChat and the open platform that followed WeChat have become really popular recently. I have always wanted to try out a WeChat platform. I recently had a good idea and wanted to implement it as soon as possible. Fortunately, WeChat does not require any UI or other design, it only needs to show the logic. In fact, if the WeChat public platform is only used as a platform for publishing information, it is "Edit mode "In fact, there is no need to type code. It is just that in the developer mode, developers need to design certain logic and code to achieve specific functions. Next, let’s talk about the start of development:
1. Develop WeChat The public platform must first have server resources. Of course, the editing mode does not count. The so-called editing mode is a public account that simply pushes a message every day. Server resources are available in various clouds and servers. BAE/ is recommended. SAE/Nuts/Alibaba, etc., each has its own advantages, and due to competition, some free resources will be given away, which is enough to practice
##. #a. Apply for a BAE account and create an application. If it is a test, go to the homepage of the WeChat public platform to download the testPHP code, and just change the TOKEN to your own TOKEN, such as the PHP below. Test code, the logic of the code is very clear, that is, a verification process, and can also define part of the logical operations Upload this file and create version 1 of your own application:
<?php /** * wechat php test */ //define your token define("TOKEN", "weixin");//此时你的微信公众平台的token即为weixin $wechatObj = new wechatCallbackapiTest(); $wechatObj->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 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 = "<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 = "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; } } } ?>The new version was created successfully. As shown in the figure, the application is created successfully:
2. Enter the developer mode of the WeChat public platform You need to verify separately to become a developer mode. Please note that the URL in the picture below must be filled in correctly, which is the URL of a platform application you just applied for. Remember to be accurate. URL, otherwise an error "404 NOTFOUND" will be reported
##Slide the upper right corner to enable the
button##You can successfully enable the development modeAt this point, you can define various functions and logic in the code to meet your needs and start the magical WeChat public platform. trip.
The above is the detailed content of A preliminary study on the development of WeChat development platform. For more information, please follow other related articles on the PHP Chinese website!