


WeChat public platform development introductory tutorial (picture and text), public introductory tutorial_PHP tutorial
Jul 12, 2016 am 08:52 AMWeChat public platform development introductory tutorial (pictures and texts), public introductory tutorial
Keywords: Introduction to WeChat public platform development
Author: C Research Laboratory
Background knowledge: The development of WeChat public platform requires certain basic knowledge of PHP. PHP is an HTML embedded language and is widely used in website development. There are two data transmission methods between the WeChat server and the developer's server, namely XML and JSON. XML is mainly used to receive and send ordinary messages and event push, while user management, creating custom menus and advanced group sending require the use of JOSN format data.
In this WeChat public platform development tutorial, you can follow the tutorial to gain an overall perceptual understanding of the development framework of the WeChat public platform, which can help you get started better.
We will use the WeChat public account Xi’an Campus Maker Space as an example. See the QR code at the bottom.
This introductory tutorial will guide you through the following tasks:
?????????????????????????????????????????????????????????????????????????????????????????
Apply for Sina Cloud Computing and create platform applications
Section 2
Apply for a virtual host and build an environment for the WeChat platform Here I am using the virtual space of Yunbang Internet to demonstrate for everyone. First, open the website as shown below:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Then register in the upper right corner according to the prompts, and select the free space of 1G.
?
3. Next we use 8uftp to log in to the virtual space.
?
4. After logging in, use 8uftp to upload the index.php file to the web folder in the root directory of the virtual space, as follows:
At this point, you have successfully used the virtual space to build a server for the WeChat public platform. You only need to upload the code to implement the corresponding functions through 8uftp.
WeChat public platform development model
Advanced Features
WeChat public platform address: https://mp.weixin.qq.com Log in to the WeChat public platform backend, find "Basic Configuration" at the bottom of the list on the left, and click to enter
Enter the server configuration filling box.
Click the "Modify Configuration" button, and the following picture will appear.
The URL here is the domain name of the cloud application introduced in the previous article, and the Token is defined as weixin in index.php. There is no need to fill in the EncodingAESKey. Click "Randomly Generate" to automatically generate one. Select "Plaintext Mode" for the message encryption and decryption method, and then click the "Submit" button.
In the pop-up prompt box, click "OK"
After modifying the configuration as shown in the picture, click the "Enable" button
Ask "Are you sure you want to enable server configuration?", click "OK"
If it prompts "Token verification failed", you can try again several times. The WeChat server is sometimes unstable.
: If you use Sina SAE, it may require real-name authentication. Please upload your ID card for real-name authentication and pass the review before trying again!
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
If it still fails, please use the WeChat debugger to test whether the URL and token are correct. (Search directly on Baidu and there will be many free ones)
Section 4 Interface calling and implementation of common functions
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Example 1: API call Baidu Translation
Apply for Baidu Translation API
The following describes how to use Baidu Translate API to create a public account with translation function.1. First, log in to apply to become a Baidu developer. The application link address is http://developer.baidu.com/. After applying to become a developer, log in to the website and select Developer Service Management from the drop-down menu of the management console, as shown in the figure below.
We can translate English into Chinese, Chinese into English, Chinese into Japanese, and Japanese into Chinese by calling Baidu Translate's API. Baidu AIP currently supports translation in these three languages
-
First enter the Baidu Translation webpage, as shown by the arrow below
-
After entering, click "User Guide"
-
After entering the smart page, browse the page offline. In the middle part of the page, you can see the API interface of Baidu Translation
-
According to the above interface, we can build the interface code:
- http://openapi.baidu.com/public/2.0/bmt/translate?client_id=uA6zT1kh5O1UXvTrUuFjFHiK&q={$keyword}&from=auto&to=auto
The key code is:
- case "text";
$transon=json_decode($transtr);//json parsing
//print_r($transon);
$contentStr = $transon->trans_result[0]->dst;//Read translation content
break;
The code used is as follows:
-
<span> 1</span> <?<span>php </span><span> 2</span> <span>//</span><span>6.2 百度翻譯 C++研究室 CopyRight 2016 </span> <span> 3</span> <span>define</span>("TOKEN", "weixin"<span>); </span><span> 4</span> <span>$wechatObj</span> = <span>new</span><span> wechatCallbackapiTest(); </span><span> 5</span> <span>if</span> (!<span>isset</span>(<span>$_GET</span>['echostr'<span>])) { </span><span> 6</span> <span>$wechatObj</span>-><span>responseMsg(); </span><span> 7</span> }<span>else</span><span>{ </span><span> 8</span> <span>$wechatObj</span>-><span>valid(); </span><span> 9</span> <span>} </span><span>10</span> <span>11</span> <span>class</span><span> wechatCallbackapiTest </span><span>12</span> <span>{ </span><span>13</span> <span>public</span> <span>$fromUsername</span>=''<span>; </span><span>14</span> <span>public</span> <span>$toUsername</span>=''<span>; </span><span>15</span> <span>public</span> <span>function</span><span> valid() </span><span>16</span> <span> { </span><span>17</span> <span>$echoStr</span> = <span>$_GET</span>["echostr"<span>]; </span><span>18</span> <span>if</span>(<span>$this</span>-><span>checkSignature()){ </span><span>19</span> <span>echo</span> <span>$echoStr</span><span>; </span><span>20</span> <span>exit</span><span>; </span><span>21</span> <span> } </span><span>22</span> <span> } </span><span>23</span> <span>24</span> <span>private</span> <span>function</span><span> checkSignature() </span><span>25</span> <span> { </span><span>26</span> <span>$signature</span> = <span>$_GET</span>["signature"<span>]; </span><span>27</span> <span>$timestamp</span> = <span>$_GET</span>["timestamp"<span>]; </span><span>28</span> <span>$nonce</span> = <span>$_GET</span>["nonce"<span>]; </span><span>29</span> <span>$token</span> =<span> TOKEN; </span><span>30</span> <span>$tmpArr</span> = <span>array</span>(<span>$token</span>, <span>$timestamp</span>, <span>$nonce</span><span>); </span><span>31</span> <span>sort</span>(<span>$tmpArr</span>,<span> SORT_STRING); </span><span>32</span> <span>$tmpStr</span> = <span>implode</span>(<span>$tmpArr</span><span>); </span><span>33</span> <span>$tmpStr</span> = <span>sha1</span>(<span>$tmpStr</span><span>); </span><span>34</span> <span>35</span> <span>if</span>(<span>$tmpStr</span> == <span>$signature</span><span>){ </span><span>36</span> <span>return</span> <span>true</span><span>; </span><span>37</span> }<span>else</span><span>{ </span><span>38</span> <span>return</span> <span>false</span><span>; </span><span>39</span> <span> } </span><span>40</span> <span> } </span><span>41</span> <span>42</span> <span>public</span> <span>function</span><span> responseMsg(){ </span><span>43</span> <span>$postStr</span> = <span>$GLOBALS</span>["HTTP_RAW_POST_DATA"<span>]; </span><span>44</span> <span>$postObj</span> = <span>simplexml_load_string</span>(<span>$postStr</span>, 'SimpleXMLElement',<span> LIBXML_NOCDATA); </span><span>45</span> <span>$fromUsername</span> = <span>$postObj</span>-><span>FromUserName; </span><span>46</span> <span>$toUsername</span> = <span>$postObj</span>-><span>ToUserName; </span><span>47</span> <span>$type</span> = <span>$postObj</span>-><span>MsgType; </span><span>48</span> <span>$event</span>=<span>$postObj</span>-><span>Event; </span><span>49</span> <span>$Event_Key</span>=<span>$postObj</span>-><span>EventKey; </span><span>50</span> <span>$mid</span>=<span>$postObj</span>-><span>MediaId; </span><span>51</span> <span>$link</span>=<span>$postObj</span>-><span>Url; </span><span>52</span> <span>53</span> <span>$latitude</span> = <span>$postObj</span>-><span>Location_X; </span><span>54</span> <span>$longitude</span> = <span>$postObj</span>-><span>Location_Y; </span><span>55</span> <span>$keyword</span> = <span>trim</span>(<span>$postObj</span>-><span>Content); </span><span>56</span> <span>$time</span> = <span>time</span><span>(); </span><span>57</span> <span>$textTpl</span> = "<span><xml> </span><span>58</span> <span> <ToUserName><![CDATA[%s]]></ToUserName> </span><span>59</span> <span> <FromUserName><![CDATA[%s]]></FromUserName> </span><span>60</span> <span> <CreateTime>%s</CreateTime> </span><span>61</span> <span> <MsgType><![CDATA[text]]></MsgType> </span><span>62</span> <span> <Content><![CDATA[%s]]></Content> </span><span>63</span> </xml>"<span>; </span><span>64</span> <span>if</span>(<span>$keyword</span>!=''<span>){ </span><span>65</span> <span>$id</span>="R90FXoW4OPtCbLkD9Aiaihz0"<span>; </span><span>66</span> <span>$url</span>="http://openapi.baidu.com/public/2.0/bmt/translate?client_id=<span>$id</span>&q=<span>$keyword</span>&from=auto&to=auto"<span>; </span><span>67</span> <span>$res</span>=<span>file_get_contents</span>(<span>$url</span><span>); </span><span>68</span> <span>$res</span>=json_decode(<span>$res</span>,<span>true</span><span>); </span><span>69</span> <span>$contentStr</span>=<span>$res</span>['trans_result'][0]['dst'<span>]; </span><span>70</span> } <span>$resultStr</span> = <span>sprintf</span>(<span>$textTpl</span>, <span>$fromUsername</span>, <span>$toUsername</span>, <span>$time</span>, <span>$contentStr</span><span>); </span><span>71</span> <span>echo</span> <span>$resultStr</span><span>; </span><span>72</span> <span> } </span><span>73</span> <span>} </span><span>74</span> ?>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Example 2: API call little yellow chicken
1. Register a simsimi account
URL: http://developer.simsimi.com/signUp2. Activate account
3. Obtain API Key
4. Specific implementation
Call the Little Yellow Chicken API to implement
Call the simsim($keyword) function and replace "Your API Key" with the applied API Key.
At the same time, the WeChat public account can also realize weather query, train query, express query, membership card, coupons, carousel, micro website, 3G photo album and so on. Micro menu, micro website, micro membership, micro group purchase, micro survey, micro photo album, micro push, micro statistics, micro payment, micro customer service, and other functions.
The above is a simple basic tutorial on WeChat public platform. If you understand it with your heart and feel that you have gained something, everything starts with practice. Please follow the tutorial to start your WeChat development journey. Bar! ! If there is anything you still don't understand, please scan the QR code of the official account to follow, reply "code", "WeChat tutorial"... All video tutorials and code information are waiting for you! ! !
Thank you for reading, please understand with your heart! Hope this helps you as a beginner! ! Sharing is also a joy! ! ! Please pass on. . .

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Copying comics is undoubtedly a treasure that cannot be missed. Here you can find basketball comics in various styles, from passionate and inspiring competitive stories to relaxed and humorous daily comedy. Whether you want to relive the classics or discover new works, copying comics can meet your needs. Through the authentic online reading portal provided by copy comics, you will bid farewell to the trouble of pirated resources, enjoy a high-definition and smooth reading experience, and can support your favorite comic authors and contribute to the development of authentic comics.

Combining the latest industry trends and multi-dimensional evaluation data in 2025, the following are the top ten comprehensive AI writing software recommendations, covering mainstream scenarios such as general creation, academic research, and commercial marketing, while taking into account Chinese optimization and localization services:

The latest official website of 2025b Announce is: https://www.marketwebb.co/zh-CN/join?ref=507720986&type=wenzi; Binance Exchange is a global cryptocurrency exchange that serves 180 countries and regions including North America, Europe, Taiwan, the Middle East, Hong Kong, and Malaysia. It provides more than 600 cryptocurrencies and has 270 million registered users worldwide.

Here, you can enjoy the vast ocean of comics and explore works of various themes and styles, from passionate young man comics to delicate and moving girl comics, from suspenseful and brain-burning mystery comics to relaxed and funny daily comics, there is everything, and there is always one that can touch your heartstrings. We not only have a large amount of genuine comic resources, but also constantly introduce and update the latest works to ensure that you can read your favorite comics as soon as possible.

Nice Comics, an immersive reading experience platform dedicated to creating for comic lovers, brings together a large number of high-quality comic resources at home and abroad. It is not only a comic reading platform, but also a community that connects comic artists and readers and shares comic culture. Through simple and intuitive interface design and powerful search functions, NES Comics allows you to easily find your favorite works and enjoy a smooth and comfortable reading experience. Say goodbye to the long waiting and tedious operations, enter the world of Nice comics immediately and start your comic journey!

Android mobile phone users can download and install Huobi/Huobi App through the following steps: 1. Ensure the network is stable and the storage space is sufficient; 2. Download the App through Huobi/Huobi official website, use the browser to access the official website and click the download link or scan the QR code, or search and download through third-party application stores such as AppTreasure and Huawei App Market, and you can also obtain the installation package through friends' sharing; 3. Find the downloaded .apk file, enable the "Unknown Source App" installation permission, follow the prompts to complete the installation, etc.

Frogman Comics has become the first choice for many comic lovers with its rich and diverse comic resources and convenient and smooth online reading experience. It is like a vibrant pond, with fresh and interesting stories constantly emerging, waiting for you to discover and explore. Frog Man comics cover a variety of subjects, from passionate adventures to sweet love, from fantasy and science fiction to suspense reasoning, no matter which genre you like, you can find your favorite works here. Its simple and intuitive interface design allows you to easily get started, quickly find the comics you want to read, and immerse yourself in the exciting comic world.

Implementing an efficient and flexible logging system in C can use the following steps: 1. Define log classes and process log information at different levels; 2. Use policy mode to achieve multi-objective output; 3. Ensure thread safety through mutex locks; 4. Use lock-free queues for performance optimization. This can build a log system that meets the needs of actual application.
