This article analyzes the introduction of enterprise ID development to get user information. when a user clicks an application and jumps to the URL we set, it does not actually contain any user information. in order to get user information, we need to use the provided OAuth2.0 interface.
To obtain user information, follow these steps:
-
Construct a URL to obtain the code
-
Obtain member information by code
1. construct a URL to obtain the code
If an enterprise requires employees to carry their identity information when they jump to the Enterprise webpage, the following link must be constructed:
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
| Parameters |
Required |
Description |
| Appid |
Yes |
Enterprise CorpID |
| Redirect_uri |
Yes |
URL of the redirection callback link after Authorization. use urlencode to process the link. |
| Response_type |
Yes |
Return type, which is fixed as: code |
| Scope |
Yes |
Application authorization scope, which is fixed as: snsapi_base |
| State |
No |
With the state parameter, the enterprise can enter the a-zA-Z0-9 parameter value, length cannot exceed 128 bytes |
| # Wechat_redirect |
Yes |
The terminal 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. enterprises can obtain the employee's userid based on the code parameter.
Appid
Obtain as shown in
2. obtain member information based on code
Obtain member information by code
Https request method: GET
Https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo? Access_token = ACCESS_TOKEN & code = CODE
| Parameters |
Required |
Description |
| Access_token |
Yes |
Interface call credential |
| Code |
Yes |
The code obtained through member authorization will vary with the code carried by each member authorization. the code can only be used once and will automatically expire if it is not used for 10 minutes. |
The domain name to be redirected must match the trusted domain name of any application in the management group.
A) An example is returned when an enterprise member is authorized:
{ "UserId":"USERID", "DeviceId":"DEVICEID" }
The above is the detailed introduction of enterprise code development to get user information. For more information, see other related articles on php Chinese network!