Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Wechat Enterprise developer obtain user information?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to obtain user information for Wechat enterprise development". The content is simple and clear. I hope it can help you solve your doubts. Next, let the editor lead you to study and learn this article "how to obtain user information for Wechat enterprise development".

When the user clicks on the app to jump to the URL we set, he doesn't actually bring any information about the user. In order to get the user information, we need to use the OAuth3.0 interface provided by Wechat.

There are two steps to obtain user information:

Construct URL to get code

Get member information according to code

First, construct URL to obtain code

If an enterprise requires employees to bring their identity information with them when they jump to the corporate web page, they need to construct the following link:

Https://open.weixin.qq.com/connect/oauth3/authorize?appid=CORPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect

Parameter description

The parameter must indicate that appid is the callback link address of the enterprise whose CorpIDredirect_uri is redirected after authorization. Please use urlencode to process the link. Response_type is the return type, which is fixed as: codescope is the application authorization scope, and it is fixed as: whether snsapi_basestate is redirected with the state parameter, and the enterprise can enter the parameter value of a-zA-Z0-9. The length cannot exceed 128bytes. # wechat_redirect is a Wechat terminal that uses this parameter to determine whether identity information is required.

After the employee clicks, the page will jump to redirect_uri?code=CODE&state=STATE, and the enterprise can obtain the employee's userid according to the code parameter.

Appid

As shown in the following figure

Scope

You can use snsapi_base or snsapi_userinfo,snsapi_userinfo to get more information, but user explicit authorization is required.

Modify URL

Suppose the page we are going to visit is http://abc.com/homepage.html Magi CORpid is wx7ce4xxxxxxxa4dd1, and finally the URL we constructed is

Https://open.weixin.qq.com/connect/oauth3/authorize?appid=wx7ce4xxxxxxxa4dd1&redirect_uri=http%3a%2f%2fabc.com%2fhomepage.html&response_type=code&scope=snsapi_base&state=1#wechat_redirect

Finally, set the home page URL of the application to the URL, and when the user clicks on the application, the final page to jump to is http://abc.com/homepage.html?code=xxxx&state=1.

Note: the application needs to set a trusted domain name. If the domain name of the final jump page does not match the trusted domain name, it will not be redirected.

2. Obtain member information according to code

Get member information according to code

Request description

Https request method: GET

Https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE

Parameter description

The parameter must indicate that access_token is the code obtained by calling the API credential code through member authorization. The code with member authorization will be different each time. Code can only be used once, and it will automatically expire if it is not used for 10 minutes.

Permission description

The redirected domain name must exactly match the trusted domain name of any application in the management group.

Return the result

A) the example returned when the enterprise member is authorized is as follows:

{"UserId": "USERID", "DeviceId": "DEVICEID"} these are all the contents of this article entitled "how to get user Information for Wechat Enterprise Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report