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

3+7 routines to teach you how to play poster fission

There is a very important way to attract fans to ...

Cancer may hold the secret to immortality?

Friends who have watched "The Emperor of All...

How many flowers and trees related to dad do you know?

When it comes to Mother's Day, people will th...

How to make online brand promotion strategy “heartfelt”?

The company's corresponding promotion strateg...

Adobe's first mobile selfie app demo: the effect is comparable to SLR

Adobe's PhotoShop is a great tool for photo ed...

How to evaluate the pros and cons of multiple promotion channels?

I have always wanted to write an article like thi...

The culprit for allergies has been found, it's not flowers, but...

Audit expert: Gu Haitong Beijing Tongren Hospital...

How to promote Xiaohongshu

With the continuous development of the Internet, ...

IHS Markit: Average U.S. vehicle lifespan reaches record 12.1 years in 2020

The average useful life of U.S. cars and light tr...

50 Children's Day copywriting sentences, worth collecting!

I have shared the copy for Children’s Day before....

Faraday Future says it has not yet raised $1 billion in "life-saving money"

On December 18, in response to media reports that...

Starting from 209,800 yuan, Xpeng P7+ starts pre-sale at Paris Motor Show

On the first day of the 2024 Paris Motor Show, a ...

Traffic war! How to deeply tap the value of long-tail channels?

"Channels are king" is an iron rule in ...