


WeChat public platform development introductory tutorial (picture and text), public introductory tutorial_PHP tutorial
WeChat 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

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

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

Undress AI Tool
Undress images for free

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

The history and evolution of C# and C are unique, and the future prospects are also different. 1.C was invented by BjarneStroustrup in 1983 to introduce object-oriented programming into the C language. Its evolution process includes multiple standardizations, such as C 11 introducing auto keywords and lambda expressions, C 20 introducing concepts and coroutines, and will focus on performance and system-level programming in the future. 2.C# was released by Microsoft in 2000. Combining the advantages of C and Java, its evolution focuses on simplicity and productivity. For example, C#2.0 introduced generics and C#5.0 introduced asynchronous programming, which will focus on developers' productivity and cloud computing in the future.

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

Golang is better than C in concurrency, while C is better than Golang in raw speed. 1) Golang achieves efficient concurrency through goroutine and channel, which is suitable for handling a large number of concurrent tasks. 2)C Through compiler optimization and standard library, it provides high performance close to hardware, suitable for applications that require extreme optimization.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

C interacts with XML through third-party libraries (such as TinyXML, Pugixml, Xerces-C). 1) Use the library to parse XML files and convert them into C-processable data structures. 2) When generating XML, convert the C data structure to XML format. 3) In practical applications, XML is often used for configuration files and data exchange to improve development efficiency.

Python is better than C in development efficiency, but C is higher in execution performance. 1. Python's concise syntax and rich libraries improve development efficiency. 2.C's compilation-type characteristics and hardware control improve execution performance. When making a choice, you need to weigh the development speed and execution efficiency based on project needs.

Golang is suitable for rapid development and concurrent scenarios, and C is suitable for scenarios where extreme performance and low-level control are required. 1) Golang improves performance through garbage collection and concurrency mechanisms, and is suitable for high-concurrency Web service development. 2) C achieves the ultimate performance through manual memory management and compiler optimization, and is suitable for embedded system development.

The best cryptocurrency trading and analysis platforms include: 1. OKX: the world's number one in trading volume, supports multiple transactions, provides AI market analysis and on-chain data monitoring. 2. Binance: The world's largest exchange, providing in-depth market conditions and new currency first-time offerings. 3. Sesame Open Door: Known for spot trading and OTC channels, it provides automated trading strategies. 4. CoinMarketCap: an authoritative market data platform, covering 20,000 currencies. 5. CoinGecko: Known for community sentiment analysis, it provides DeFi and NFT trend monitoring. 6. Non-small account: a domestic market platform, providing analysis of linkage between A-shares and currency markets. 7. On-chain Finance: Focus on blockchain news and update in-depth reports every day. 8. Golden Finance: 24 small
