Currently mobile development is a relatively hot trend, and many developers are eager to try it. Currently, the field of mobile App development is mainly divided into the following types
In my daily work, I come into contact more with Native App development based on Android and Light App development based on WeChat official accounts. Today I will lead you to quickly enter the development field of WeChat official accounts. .
If a worker wants to do his job well, he must first sharpen his tools. If you want to develop a WeChat public account, you must first prepare two essential things:
1. Have a public account for testing.
2. Development environment used to debug the code.
WeChat public accounts are divided into service accounts, subscription accounts, and enterprise accounts. Subscription accounts can be applied for by individuals. Service accounts and enterprise accounts must have enterprise qualifications.
What we call WeChat public account development refers to subscription accounts and service accounts.
Regarding the difference between subscription account and server, the official explanation is this
Service account : Mainly biased towards service interaction (functions are similar to 12315, 114, bank, providing binding (customized information, service interaction), can send 4 messages per month; service number Applicable people: media, enterprises, governments or other organizations.
Subscription account : Mainly focuses on conveying information to users (functions similar to newspapers and magazines, providing users with news information or entertainment and interesting things), and can send 1 message in groups every day; subscription account Applicable people: individuals, media, businesses, governments or other organizations.
Personal subscription accounts have some interfaces that do not have permissions, which means that personal subscription accounts cannot call some advanced permission interfaces. The following figure is a list of permissions that my personal subscription account has, as shown in the figure below:
And some advanced interfaces, such as generating QR codes, web page authorization, custom menus, WeChat payment, and other interface permissions, personal subscription accounts do not have calling permissions, as shown above Those interfaces framed in red cannot be called by personal subscription accounts.
Fortunately, WeChat public platform provides a test public account . The registration address of the test public account is: http://mp .weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login, you only need to go to this page, click to log in, scan the code with your own WeChat client, and authorize the login. You can get your own test public account. The test public account has almost all interfaces, so when you usually learn WeChat public account development, you can register a test public account, and then use this test public account for development. . No more nonsense, let’s register a test public account first
Visit http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login and register a test public account .
The steps to register a test public account are as shown below:
Scan with WeChat Use the above QR code to log in. After successful login, you can see the information about the test public account assigned to us by Tencent, as shown in the figure below:
Test public The interface permissions owned by the number are as follows:
It can be seen that the test official account has most of the interface calling permissions, so It is completely possible to use the test official account to learn WeChat development.
The biggest pain point in developing applications based on WeChat official accounts is debugging. Every time a function is implemented, it needs to be deployed to a public network server. Test, because every time a WeChat user initiates a request to an official account, the WeChat server will first receive the user's request and then forward it to our server. In other words, the WeChat server needs to interact with our server over the network, so We must ensure that our server can be accessed from the external network. This method of deploying to a public server for testing is simply a nightmare for us developers. So we have to think of a way to deploy locally and debug the code locally. To do this, the problem we have to solve is to map the deployment server of the internal network to the external network so that the WeChat server can be accessed normally. Fortunately What's amazing is that we can do it with the help of the third-party software Ngrok. Ngrok is a free software Ngrok. After using Ngrok, we can achieve intranet penetration, which means that we can map the intranet server to the external network for others to access , This is very fast and helpful for us to debug WeChat code in the local development environment and demonstrate something to users, because we can directly use our own intranet computer as the server.
A better website that provides Ngrok services in China is: http://natapp.cn/, as shown in the figure below:
From http://natapp.cn /Download the ngrok client on the website, as shown in the figure below:
After the download is completed, you will get a compressed package. After decompressing the compressed package, you will get a folder, which contains the contents as shown in the figure below. Several files:
Open the CMD command line window, enter the ngrok_windows directory, and then enter the following command:
ngrok -config ngrok.cfg -subdomain xdp 8080 , as shown in the figure below:
:8080 server is mapped to the external network, as shown in the following figure:
At this time, users on the external network can directly access the domain name http://xdp.ngrok.natapp.cn The 127.0.0.1:8080 server on my intranet is as shown in the figure below:
After using ngrok, we can The intranet server is used as a public network server. The access speed is still within an acceptable range. As of now, ngrok is available and the WeChat public account server is accessible. In this way Once it comes, it won’t hinder us from doing local adjustments. At this point, our WeChat local debugging and development environment has been set up. With tall buildings rising from the ground, we have taken the first step in WeChat development! For more WeChat development—WeChat development environment construction related articles, please pay attention to the PHP Chinese website!