Enterprise micro-channel for user information

Enterprise micro-channel for user information

In this article from the official document:     https://work.weixin.qq.com/api/doc/10028# obtain membership information according to code    

Directly to the question:

Implementation requirements: New applications on enterprise micro-channel, direct free access to the application log into the application.

Access procedure described OAuth2.0

 

 

The first step, get code 

You need to configure the following address in particular access should be opened in:

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

parameter:

appid: Enterprise CorpID

redirect_uri: callback after the authorization redirect link address, use urlencode to link processing, that is, the request method own program.

response_type: fixed: code

scope: the scope of application of the authorization.
snsapi_base: Silent authorized to obtain basic information about members of the (UserId and DeviceId);
snsapi_userinfo: Silent authorization, detailed member information available, but does not contain the phone, mail;
snsapi_privateinfo: manual authorization, detailed member information available, include mobile / email

agentid: id enterprise applications.
When the scope is snsapi_userinfo or snsapi_privateinfo, this parameter is required
attention redirect_uri domain name must match the trusted domain name of the application.

state: when the request is redirected back tape parameters, parameter values ​​that are a-zA-Z0-9 length not exceed 128 bytes,

wechat_redirect: Be sure to add this parameter.

When accessing micro-enterprises in the letter, the page will jump to redirect_uri? Code = CODE & state = STATE, then can get the user's userid according to code

Note: code a maximum of 512 bytes. Every member of the band authorization code will be different, code can only be used once, five minutes is not used expire automatically.

Get access_toekn

 

According code for user information and access_token

请求方式:GET(HTTPS)
请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE

返回数据:

 

 

这样的话就可以根据获取到的  UserId  (注意大小写)来实现免密登录到应用中。

如果需要获取详细的用户信息,调用下面的接口地址请求获取。

使用user_ticket获取成员详情

请求方式:POST(HTTPS)
请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail?access_token=ACCESS_TOKEN

 

Guess you like

Origin www.cnblogs.com/misscole/p/12085099.html