How to obtain OAuth2 authentication interface in WeChat Enterprise Account Development

How to obtain OAuth2 authentication interface in WeChat Enterprise Account Development

URL links in enterprise applications (including links in custom menus or messages) can obtain employee identity information through OAuth2.0.

Note that the domain name of this URL must completely match the 'Trusted Domain Name' in the enterprise application settings , otherwise a 50001 error code will be returned when obtaining user information.

1. Enterprises obtain code

If an enterprise requires employees to bring their identity information when they jump to the enterprise website, they need to construct the following link:

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

  • Parameter Description
parameter must illustrate
appid yes CorpID of the company
redirect_uri yes The callback link address redirected after authorization. Please use urlencode to process the link.
response_type yes Return type, fixed at this time: code
scope yes Application authorization scope, fixed at this time: snsapi_base
state no After redirection, the state parameter will be added. Enterprises can fill in the parameter value of a-zA-Z0-9
#wechat_redirect yes WeChat terminal uses this parameter to determine whether identity information is required

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

2. Get member information

  • Request Instructions

Https request method: GET

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

  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
code yes The code obtained through employee authorization will be different each time the employee authorizes it. The code can only be used once and will automatically expire if not used within 5 minutes.
agentid yes The enterprise application ID where the link is redirected
  • Permissions

The administrator must have permission to use the agent; the agentid must be the same as the enterprise application ID where the link is redirected.

  • Return results

a) If it is correct, the return example is as follows:

  1. {
  2. "UserId":"USERID"
  3. }
parameter illustrate
UserId Employee UserID

The following is an example of what is returned when an error occurs:

  1. {
  2. "errcode" : "40029" ,
  3. "errmsg" : "invalid code"  
  4. }

<<:  How to use custom menus in WeChat Enterprise Account Development

>>:  WeChat Enterprise Account Development: Encryption Scheme and Global Return Code Description

Recommend

The Giant Panda among Birds - Great Bustard

"The feathers of the great bustards flutter ...

Practical examples: one article explains user growth in detail! !

The concept of User Growth (UG) originated from t...

Gamification design for user activation and retention

Gamification design can be seen in many products....

64-bit phones will be everywhere next year: thanks to Android L

When Apple launched the iPhone 5s last year, many...

Office Administration Guide: From a Thankless Job to a Successful Job

Administrative work is not as simple as just doin...

Urticaria is common in spring. How to get rid of it?

The weather is getting warmer and the days are ge...

How much does it cost to develop a Shigatse fruit mini program?

How much does it cost to develop the Shigatse Fru...

On the eve of 5G, mobile phone companies should not panic

Not long ago, a video about 5G experience by &quo...

How to write a good Tik Tok short video script?

Everyone loves short videos. It stimulates the us...

A long article to talk about overseas mobile traffic advertising monetization

There are more and more Chinese mobile developers...

How should marketing campaigns be designed?

The purpose of marketing activities is mainly to ...

The last unknown blue ocean of Android emulator mobile games

Since the development of the mobile game market, ...