Home  >  Article  >  WeChat Applet  >  How to build a local test environment for java WeChat public account development

How to build a local test environment for java WeChat public account development

高洛峰
高洛峰Original
2017-03-14 13:59:481728browse

This article mainly introduces the development of Java WeChat public account. The main content includes testing the public account and building a local test environment. Friends in need can refer to it

As the saying goes, if you want to do your job well, you must first do it well. Sharpen your tools. To develop a WeChat public account, two things are indispensable, that is, a public account for testing and a development environment for debugging the code.

Test public account

WeChat public account has subscription account, service account, and enterprise account. When registering, you see this information. Only subscription account can be applied for personally. , service accounts and enterprise accounts must have enterprise qualifications. The WeChat public account development mentioned here refers to subscription accounts and service accounts.

How to build a local test environment for java WeChat public account development

In addition, some interfaces of unauthenticated personal subscription accounts do not have permissions, and currently personal subscription accounts no longer support WeChat authentication, that is It is said that personal subscription accounts cannot call some advanced permission interfaces. The picture below is a list of permissions that an uncertified personal subscription account has, such as generating QR codes, web page authorization, custom menu, and WeChat payment. Interface permissions are not available.

How to build a local test environment for java WeChat public account development

After talking for a long time, what should I do if I don’t have enterprise qualifications and want to develop advanced interfaces.

WeChat public platform provides a test public account, the login address 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 official account has almost all interfaces. If there is no available official account for normal development, just use this test official account.

Local test environment

One of the major pains in developing WeChat public accounts is the debugging problem, which needs to be deployed every time a function is implemented To a public network server, although there are currently various free cloud platforms that can be deployed, the debugging basically can only rely on log output, and there is no modification->deployment->view log. This operation process is very time-consuming and time-consuming. It’s life, isn’t this a waste of life? So, is there a way to deploy and debug locally?

Of course, because every time you send an instruction to the official account, the server where the official account is located needs to interact with your server over the network. Therefore, your server must ensure that it can be accessed from the external network, so you only need to You can map the local address to an external network address to realize local debugging of the WeChat official account. There are many softwares that provide such functions, such as Peanut Shell, but they are charged. Here is a free software, ngrok, which may require FQ to access. According to the local version required, windows or linux version, then register an account. After account registration is successful, you will get a free authorization code. This authorization code is used when starting ngrok for the first time. Will be used.

Taking my local area as an example, I downloaded the Windows version. After downloading and decompressing, find the decompression directory, double-click ngrok.exe, and enter the following command when starting it for the first time:

ngrok -authtoken Authorization code 80

Then start, double-click ngrok.exe, enter the command after startup to map the machine to the external network, and set the local 8080 The web service under the port is mapped to the external network port 80. The command is as follows:

ngrok http 8080

The interface after startup is as follows:

How to build a local test environment for java WeChat public account development 

The red part is the mapped external network address. Now accessing this address means accessing the local port 8080. However, for the free version of ngrok, the external network mapping address generated is random and will be different every time it is restarted. However, it is not a big deal because ngrok will basically not shut down during startup once a day. After each startup, go to WeChat to test Official account management page, just reconfigure it.

How to build a local test environment for java WeChat public account development

As of now, ngrok is available, which means that although the ngrok server is blocked, the WeChat public account server is accessible, which does not prevent us from doing things. Locally adjusted. Just download and register ngrok and you need to FQ it.

There are also some ngrok servers in China, but I have not tried them. If you are interested, you can search yourself. Of course, if you have the ability, you can build an ngrok platform yourself. ngrok is implemented in the go language.

The above is using java to develop WeChat public accounts to implement public account testing and local test environment construction. I hope it will be helpful to everyone's learning.

The above is the detailed content of How to build a local test environment for java WeChat public account development. For more information, please follow other related articles on the PHP Chinese website!

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