Home  >  Article  >  WeChat Applet  >  Introduction to WeChat enterprise account development to obtain user information

Introduction to WeChat enterprise account development to obtain user information

高洛峰
高洛峰Original
2017-03-24 14:48:514509browse

When the user clicks on the application to jump to the URL we set, it does not actually bring any user information. In order to obtain user information, we need to use the OAuth2.0 interface provided by WeChat.

Obtaining user information is divided into two steps:

  1. Construct the URL to obtain the code

  2. Obtain member information according to the code

1. Construct the URL to obtain the code

If an enterprise requires employees to bring their identity information when jumping to the corporate 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

#redirect_uri is the callback link address redirected after authorization. Please use urlencode to process the linkresponse_type is the return type of , which is fixed at this time: codescope is Application authorization scope, fixed at this time: snsapi_basestateNoThe state parameter will be included after redirection, and the enterprise can fill it in The parameter value of a-zA-Z0-9, the length cannot exceed 128 bytes#wechat_redirectYesWeChat terminal uses this parameter Determine whether identity information needs to be brought
Parameters Must Description
appid is the CorpID## of the enterprise
After the employee clicks, the page will jump to redirect_uri?code=CODE&state=STATE. The company can obtain the employee's userid based on the code parameter.

appid

Get it as shown in the figure below

Introduction to WeChat enterprise account development to obtain user information

scope

You can use snsapi_base or snsapi_userinfo, snsapi_userinfo can be obtained More information, but user explicit authorization is required

Modify URL

Assume that the page we want to access is http://abc.com/homepage.html, and the CORPID is wx7ce4xxxxxxxa4dd1. Finally, we construct The URL is

https://open.weixin.qq.com/connect/oauth2/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 this URL. When the user clicks on the application, the final page that jumps 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 able to jump.

Introduction to WeChat enterprise account development to obtain user information

2. Obtain according to the code Member information

Get member information based on code

  • Request description

Https request method: GET

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

  • Parameter description

ParametersmustDescriptionaccess_tokenisCall interface certificatecode is the code obtained by through member authorization. The code brought by member authorization will be different each time. The code can only be used once and will automatically expire if not used for 10 minutes
  • Permission Description

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

  • Return results

a) The example returned when enterprise members are authorized is as follows:

    {
       "UserId":"USERID",
       "DeviceId":"DEVICEID"
    }
<br>

The above is the detailed content of Introduction to WeChat enterprise account development to obtain user information. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn