search
HomeBackend DevelopmentPHP TutorialWeChat public platform development introductory tutorial (picture and text), public introductory tutorial_PHP tutorial

WeChat public platform development introductory tutorial (picture and text), public introductory tutorial_PHP tutorial

Jul 12, 2016 am 08:52 AM
c++authorgetting StartedGetting Started TutorialKeywordsGraphics and textplatformdevelopWeChatbackground

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.

2. After opening the space, open the control panel and you can see the host information.

 

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.

Section 3: Enabling development mode and accessing the server

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.

Note

: 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
  1. First enter the Baidu Translation webpage, as shown by the arrow below
  2. After entering, click "User Guide"
  3. 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
  4. According to the above interface, we can build the interface code:
  5. http://openapi.baidu.com/public/2.0/bmt/translate?client_id=uA6zT1kh5O1UXvTrUuFjFHiK&q={$keyword}&from=auto&to=auto

    The string "9peNkh97N6B9GGj9zBke9tGQ" is your Baidu key. You can see it by clicking on the basic information in Baidu's application center

    The key code is:
  6. case "text";

    $tranurl="http://openapi.baidu.com/public/2.0/bmt/translate?client_id=uA6zT1kh5O1UXvTrUuFjFHiK&q={$keyword}&from=auto&to=auto";//Baidu translation address

                                                                                                                                                                                           

    $transon=json_decode($transtr);//json parsing

    //print_r($transon);

    $contentStr = $transon->trans_result[0]->dst;//Read translation content

    break;

    Log in to WeChat on your mobile phone, and the final result is as follows:
  7. 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/signUp

2. 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. . .

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1126417.htmlTechArticleIntroduction to WeChat public platform development tutorial (picture and text), public introductory tutorial keywords: Introduction to WeChat public platform development author: Background knowledge of Laboratory C: The development needs of WeChat public platform...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Describe different HTTP caching headers (e.g., Cache-Control, ETag, Last-Modified).Describe different HTTP caching headers (e.g., Cache-Control, ETag, Last-Modified).Apr 17, 2025 am 12:22 AM

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1?Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1?Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP: An Introduction to the Server-Side Scripting LanguagePHP: An Introduction to the Server-Side Scripting LanguageApr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and the Web: Exploring its Long-Term ImpactPHP and the Web: Exploring its Long-Term ImpactApr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

Why Use PHP? Advantages and Benefits ExplainedWhy Use PHP? Advantages and Benefits ExplainedApr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft