The first step of Java wechat development API server access

How to access the server through wechat development API is introduced below

1、 Explain

*This example is based on wechat development documents: http://mp.weixin.qq.com/wiki/home/index.html The latest version (4 / 3 / 2016 5:34:36 PM) for development demonstration* Editing platform: MyEclipse 10 7+win32+jdk1. 7+tomcat7. 0 * server: alicloud Windows Server 2008 64bits * platform requirements: servlet uses annotation method, platform requirements: j2ee6 0+、jdk6. 0+、tomcat7. 0 + * the demo focuses more on API parsing* For the convenience of test description, each test case is independent and does not depend on other methods. No more consideration is given to packaging* The demonstration shall be conducted according to the API requirements as far as possible. The purpose is to understand the use of documents and draw inferences from one example* Knowledge requirements: solid Java foundation, knowledge of HTTP network communication, sufficient understanding of JavaWeb, JSON parsing * current time: 4 / 3 / 2016 5:32:57 PM, subject to this time.

2、 Original document (Abstract)

Document address: http://mp.weixin.qq.com/wiki/8/f9a0b8382e0b77d87b3bcc1ce6fbc104.html To access wechat public platform development, developers need to follow the following steps:

1. Fill in the server configuration 2. Verify the validity of the server address 3. Implement the business logic according to the interface document

3、 Document understanding

Verify the validity of the server address

1. The API is introduced as follows:

After the developer submits the information, the wechat server will send a get request to the filled server address URL. The get request carries four parameters: signature, timestamp, nonce The echostr developer verifies the request by verifying the signature (there are verification methods below). If you confirm that the get request comes from the wechat server, please return the content of the echostr parameter as it is, then the access will take effect and become a developer success, otherwise the access will fail. The encryption / verification process is as follows: 1) lexicographically sort the three parameters token, timestamp and nonce. 2) splice the three parameter strings into a string for SHA1 encryption 3) . the encrypted string obtained by the developer can be compared with signature to identify that the request comes from wechat

2. Understand

It indicates that the request is in the "get" mode, and access to the request will return four parameters: signature, timestamp, nonce and echostr. We need to accept these parameters and then process them. If the verification is successful, the received "echostr" is returned, otherwise the verification fails. The verification method is to sort the received token, timestamp and nonce parameters in dictionary order, then encrypt them with SHA1, and finally compare them with signature* The encrypted string can be compared with signature. If it is equal [the API here may not explain clearly], it returns "echostr" and the verification is successful.

3. Realize

Create a servlet coreservlet to implement httpservlet and overload the doget method. Parameter preparation

Operate according to the three steps described in the API

4. Fill in server configuration

1) Including content server configuration, which mainly refers to the server and wechat access interface to be configured after we have written our own code for accessing wechat development platform. 2) . server operation: open the Tomcat of the server and put the written code in the webapps file. 3) . wechat public platform operation * apply for wechat test account (you can log in by scanning wechat directly): http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login *Open the wechat public platform test number and configure the interface configuration information. Configure the following URL: http://ip/WeixinApiDemo/CoreServlet Token: wgyscsf * there will be reminders of successful and failed configuration after submission.

All the operation source codes in this part can be used directly

The first part of the Java wechat development API will be introduced here. I hope you will continue to pay attention to the updated content in the future. Thank you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>