# Feature Page of User Information

The feature page of user information helps a plug-in obtain user information, including openid and the nickname. This page is functionally equivalent to wx.login and wx.getUserInfo.

In addition, as of the base library 2.3.1, a plug-in can directly call wx.login]((wx.login)) and [wx.getUserInfo after obtaining user authorization on this feature page, without needing to obtaining user information on this feature page again.

# Call Parameters

When functional-page-navigator is used for redirection to the functional page of user information, the corresponding parameter name should be set to the fixed value loginAndGetUserInfo. The remaining parameters are the same as those for wx.getUserInfo. Specifically:

Parameters of args:

Parameter Name Type Required Description
withCredentials Boolean No Specifies whether to include login status information
lang String No Specifies the language in which user information is returned. The value zh_CN indicates simplified Chinese, zh_TW indicates traditional Chinese, and en indicates English. It is en by default.
timeout Number No Timeout time (in ms)

Note: When withCredentials is set to true, returned data will include encryptedData, iv, and other sensitive information.

Description of Return Parameters for bindsuccess:

Parameter Type Description
code String It is similar to the user login credential (valid for five minutes) obtained via wx.login. The developer needs to call an API in the developer server backend, and exchange the code for information such as the openid and session_key.
errMsg String Call results
userInfo OBJECT User information object, excluding openid and other sensitive information.
rawData String Raw data string that excludes sensitive information and is used to calculate signatures.
signature String String obtained through sha1 (rawData + sessionkey) and used to verify user information. For details, refer to signature.
encryptedData String The complete encrypted user data, including sensitive data. For details, see Decryption Algorithm for Encrypted Data.
iv String The initial vector of the encryption algorithm. For details, see Decryption Algorithm for Encrypted Data.

userInfo parameter description:

Parameter Type Description
nickName String Nickname of a user
avatarUrl String Profile photo of a user. The last numeric value represents the size of a square profile photo (The value can be 0, 46, 64, 96, or 132. The value 0 represents a 132*132 square profile photo). This parameter is left blank if a user has no profile photo. If the user changes the profile photo, the URL of the original profile photo will expire.
gender String Gender of a user. The value 1 indicates male, 2 indicates female, and 0 indicates unknown.
city String City of a user
province String Province of a user
country String Country of a user
language String Language used by the user. The value zh_CN indicates simplified Chinese.

Code example:

<!--plugin/components/hello-component.wxml-->
  <functional-page-navigator
    name="loginAndGetUserInfo"
    args="{{ args }}"
    version="develop"
    bind:success="loginSuccess"
    bind:fail="loginFail"
  >
    <button class="login">Log in to a plug-in</button>
  </functional-page-navigator>
// plugin/components/hello-component.js
Component({
  properties: {},
  data: {
    args: {
      withCredentials: true,
      lang: 'zh_CN'
    }
  },
  methods: {
    loginSuccess: function (res) {
      console.log(res.detail);
    },
    loginFail: function (res) {
      console.log(res);
    }
  }
});

After clicking navigator, a user is redirected to the following user information feature page:

Feature Page of User Information

View the Sample in the Weixin DevTools:

  1. Enter an appid which is required for plug-ins to function.
  2. Due to limits on the code fragment, enter appid in miniprogram/app.json (as show below) manually after opening the sample to make the sample function properly.

Set appid manually