Obtain basic user information

The mini program is allowed to obtain basic information of the wallet users. This is an open service that captures basic user information such as avatar, nickname, gender, and region after obtaining the user's authorization.

Requirements

When obtaining basic user information, mini program developers must meet the following requirements:

  • Do not guide users to grant authorization at the launch of the mini program. Users have the right to fully understand the mini program and its operations before giving any authorization.
  • Do not obtain the user ID and the user's real name. The information to obtain can only include basic user information, such as user avatar, nickname, gender, and location.
  • As the basic user information and the user's mobile phone number are obtained by two JSAPIs, these two kinds of information cannot be requested in the same modal.
  • Do not obtain user information that is not related to the business. If the user does not grant authorization at the first request, display the modal to allow the user to reverse the decision when the business requires the authorization again.

Procedures

To obtain the user's basic information in the mini program, mini program developers must complete the following steps:

Step 1: Create a mini program

Apply for an account and create a mini program on the Mini Program Platform.

Step 2: Add the feature

Enter the mini program you just created. Click the "Features" tab, then "Add Feature" to pop up the feature list. Tick "obtain basic member information" and click the "Confirm" button to activate the feature.

image

Step 3: Call the JSAPI

Call the my.getOpenUserInfo JSAPI to obtain the user's basic information.

Note:

Developers must consider the possibility that users reject to authorize the mini program to collect their information. In such cases, developers must have corresponding solutions, such as guiding users to manually fill in or upload their information.

Display the authorization modal

In the button component, set the value of open-type as getAuthorize and set the value of scope as userInfo.

Sample code:

copy
<!-- .axml -->
<button 
    open-type="getAuthorize" 
    onGetAuthorize="onGetAuthorize" 
    onError="onAuthError" 
    scope='userInfo'>
</button>

Button properties

Name

Description

open-type

The value is getAuthorize.

scope

The value is userInfo.

onGetAuthorize

Authorization success callback. The mini program can call my.getOpenUserInfo to get information in this callback.

onError 

Authorization failure callback, including user rejection and system errors.

Call the my.getOpenUserInfo JSAPI

After the user grants the authorization, the mini program can call the my.getOpenUserInfo JSAPI to obtain basic user information.

Sample code:

copy
// .js 
onGetAuthorize(res) {
    my.getOpenUserInfo({
        fail: (res) => {
        },
        success: (res) => {
            let userInfo = JSON.parse(res.response).response
        }
    });
}

Sample of a successfully returned message format:

copy
{
    "response":{
        "response":{
            "code":"10000",
            "msg":"Success",
            "countryCode":"code",
            "gender":"f",
            "nickName":"XXX",
            "avatar":"https://image_domain/images/partner/XXXXXXXX",
            "city":"city",
            "province":"province"
        }
    }
}

API list

JSAPI

Description

my.getAuthCode

Gets user's authorization code.

my.getOpenUserInfo

Gets basic user information.

FAQs

1. Can the function of obtaining basic user information be used to obtain the wallet userId?

No. If mini programs need to obtain the user ID, see user authorization for details and call my.getAuthCode to get the user ID.

2. Can mini programs obtain the user's mobile phone number, avatar, nickname, and other public information at the same time?

No. Mini programs cannot obtain the user's mobile phone number, avatar, nickname at the same time in the same modal.

The following public user information can be obtained with my.getOpenUserInfo:

  • Avatar
  • Nickname
  • Gender
  • Country

The following private user information can be obtained with my.getAuthCode:

  • User ID
  • Phone number

3. Can mini programs get user ID, real name, and private information through the function of obtaining basic user information?

No. Through the function of obtaining basic user information, mini programs can only get user avatar, nickname, gender, location, and other public information.