Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get basic user Information by developing Wechat Public platform

Shulou Source: shulou.com Published: 2022-06-03 15:56:18 10月01日 Update

This article mainly introduces the development of Wechat public platform how to obtain basic user information, the article is very detailed, has a certain reference value, interested friends must read it!

First, obtain basic user information through the global Access Token

When users follow and reply to messages, they can get their OpenID.

1372307736

The FromUserName is OpenID.

Then use the access_token interface to request a global Access Token

Return the result:

{"access_token": "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ", "expires_in": 7200}

Then use the global ACCESS_TOKEN to get the details of OpenID

The return is as follows:

{"subscribe": 1, "openid": "oLVPpjqs2BhvzwPj5A-vTYAX4GLc", "nickname": "baby hedgehog", "sex": 1, "language": "zh_CN", "city": "Shenzhen", "province": "Guangdong", "country": "China", "headimgurl": "http://wx.qlogo.cn/mmopen/JcDicrZBlREhnNXZRudod9PmibRkIs5K2f1tUQ7lFjC63pYHaXGxNDgMzjGDEuvzYZbFOqtUXaxSdoZG6iane5ko9H30krIbzGv/0"," subscribe_time ": 1386160805}

At this point, get the basic information of the user.

This is the best way for users to reply to a message "Welcome follow + user nickname" when following, as shown in the reply when following the public account below. Scanning the QR code can be experienced.

Second, pop up the authorization page to get the basic information of the user through OAuth3.0.

1. First configure the callback domain name

Reply the link to the follower, and after the user clicks, the application authorization interface pops up.

The callback page is linked as follows. The callback url will contain the parameter code.

Then use code in exchange for the authorized access_token of oauth3

Url is as follows:

Authorized Access Token:

{"access_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-G0ZWEE5-uBjBz941EOPqDQy5sS_GCs2z40dnvU99Y5AI1bw2uqN--2jXoBLIM5d6L9RImvm8Vg8cBAiLpWA8Vw", "expires_in": 7200, "refresh_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-G0ZWEE5-uBjBz941EOPqDQy5sS_GCs2z40dnvU99Y5CZPAwZksiuz_6x_TfkLoXLU7kdKM2232WDXB3Msuzq1A", "openid": "oLVPpjqs9BhvzwPj5A-vTYAX3GLc", "scope": "snsapi_userinfo,"}

Then use authorized Access Token to obtain user information

Return as follows

{"openid": "oLVPpjqs9BhvzwPj5A-vTYAX3GLc", "nickname": "Baby hedgehog", "sex": 1, "language": "zh_CN", "city": "Shenzhen", "province": "Guangdong", "country": "China", "headimgurl": "http://wx.qlogo.cn/mmopen/utpKYf69VAbCRDRlbUsPsdQN38DoibCkrU6SAMCSNx558eTaLVM8PyM6jlEGzOrH67hyZibIZPXu4BK1XNWzSXB3Cs4qpBBg18/0"," privilege: []}

Access to user information is complete.

The final user information is as follows

For the detailed process of this method, please refer to Wechat Public platform Development (71) OAuth3.0 Page Authorization

This method is suitable for

1. Get the user's information in the moments.

two。 Get user information in the web page.

3. Get user information in the custom menu.

It should be noted that if you use this method in a service number that already has authorized permissions for OAuth3.0 pages, it will be automatically converted to method 3, without the "Wechat login" prompt box.

You can scan the QR code below on Wechat, and then reply to "Authorization" to experience this way of acquisition.

Third, obtain the basic information of the user without popup the authorization page through OAuth3.0.

Return as follows

{"access_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-oJ9VmO-0Z-_izfnSAX_s0aqDsYkW4s8W5dLZ4iyNj5Y6vey3dgDtFki5C8r6D0E6mSVxxtb8BjLMhb-mCyT_Yg", "expires_in": 7200, "refresh_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-oJ9VmO-0Z-_izfnSAX_s0aqDsYkW4s8W5dLZ4iyNj5YBkF0ZUH1Ew8Iqea6x_itq13sYDqP1D7ieaDy9u2AHHw", "openid": "oLVPpjqs9BhvzwPj5A-vTYAX3GLc", "scope": "snsapi_base"}

Return the result:

{"access_token": "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ", "expires_in": 7200}

The return is as follows:

{"subscribe": 1, "openid": "oLVPpjqs2BhvzwPj5A-vTYAX4GLc", "nickname": "baby hedgehog", "sex": 1, "language": "zh_CN", "city": "Shenzhen", "province": "Guangdong", "country": "China", "headimgurl": "http://wx.qlogo.cn/mmopen/JcDicrZBlREhnNXZRudod9PmibRkIs5K2f1tUQ7lFjC63pYHaXGxNDgMzjGDEuvzYZbFOqtUXaxSdoZG6iane5ko9H30krIbzGv/0"," subscribe_time ": 1386160805}

The basic information of the user was successfully obtained.

This is suitable for service numbers that have been authorized by the OAuth3.0 page to be used in the web page, and the "Wechat login" page does not pop up. Reduce interruptions to users.

The above is all the contents of the article "how to get basic user Information by developing Wechat Public platform". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: User information web page public method page platform global hedgehog baby method China Guangdong Shenzhen Weibo content time article result link Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux MySQL Xiaomi Microsoft