search
HomeWeChat AppletWeChat DevelopmentIntroduction to WeChat enterprise account development to obtain user information

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.