WeChat official account webpage authorized login--JAVA

When searching for information on the Internet, netizens say that the official documents are too rubbish and difficult to understand. Now I have compiled an easy-to-understand and easy-to-use guide, hoping to help you who are new to the WeChat interface.

Check out the flowchart! If you understand the picture, you will understand half of it:

In fact, the overall process generally only takes three steps: the user clicks the login button (actually a link) ---" the user clicks the authorized login ----" to obtain the user information code.

Then it only takes three steps to obtain the user information code: obtain code ----> obtain access_token and openId through code ---> obtain user information through access_token and openId.

 

The above is the overall routine, of course, there are also on the official website, but how to achieve it?

Don't worry, let's go step by step!

 

Step 1: WeChat login button

It is actually a link, but it is a little troublesome to get this link.

1. Settings. WeChat public platform---"Interface permissions---"Web page authorization---"Modify--"Enter the following page---"Set the web page authorization domain name (domain name, excluding http://), in fact, WeChat adjusts you The project path or the project domain name of the java method, such as: www.zzff.net/pp --- "click the setting and the page will pop up (generally, put MP_verify_31qRIDcjN8ZD1lVJ.txt under your project path, such as: www.ffzz.net /pp/MP_verify_31qRIDcjN8ZD1lVJ.txt can be accessed) ---"Click to confirm, the domain name setting of the authorization callback page is successful!

2, spell link.   https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx520c15f417810387& redirect_uri = domain name of the authorization callback page/your action (that is, the address to which WeChat is redirected after authorization)

& response_type=code (fixed) & scope = snsapi_userinfo (or snsapi_base default authorization) & state=STATE#wechat_redirect

 For example: https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf0e81c3bee622d60&redirect_uri=http%3A%2F%2Fnba.bluewebgame.com%2Foauth_response.php&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect

The specific meaning of the parameters in this link is officially explained as follows:

parameter Is it necessary illustrate
appid Yes The unique identifier of the official account
redirects Yes The callback link address redirected after authorization, please use urlencode to process the link
response_type Yes Return type, please fill in code
scope Yes Application authorization scope, snsapi_base (do not pop up the authorization page, jump directly, only get the user's openid), snsapi_userinfo (pop up the authorization page, you can get the nickname, gender, location through openid. And, even if you don't pay attention, As long as the user authorizes, the information can also be obtained )
state no The state parameter will be brought after the redirection, and the developer can fill in the parameter value of a-zA-Z0-9, up to 128 bytes
#wechat_redirect Yes Whether you open it directly or do a page 302 redirection, you must bring this parameter

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325853318&siteId=291194637