# User Information Features Page

The user information feature page is used to help the plug-in obtain user information, including Openid And nicknames, etc., are equivalent to wx.login and [wx.getUserInfo ]((wx.getUserInfo )) Of the function.

In the base library version 2.3.1 Previously, the user information feature page is the only access in the plug-in Code And user information in a manner that

Self-base library version 2.3.1 After the user has been authorized in the function page, the plug-in can directly invoke the wx.login and [wx.getUserInfo ]((wx.getUserInfo )):

  • Authorization is given in the form of [User + Mini Program + Authorization for the dimension, that is, the same user uses the same plug-in in different Mini Programs, or different plug-ins in the same Mini Programs, all need to be authorized separately.
  • Self-base library version 2.6.3 Up, can be used wx.getSetting To see if the user has authorized

In addition, the plug-in can directly call the wx.login

  1. The Mini Program that uses the plug-in has the same AppId
  2. The Mini Program that uses the plug-in is bound to the same plug-in WeChat Open Platform The Mini Program and the plug-in which use the plug-in are the same subject or associated subject with the open platform account.

When the above conditions are not met,wx.login and [wx.getUserInfo ]((wx.getUserInfo )) Will return a failure.

# Call parameter

User Information Features Page Use functional-page-navigator When the jump is made, the corresponding parameters Name Should be a fixed value loginAndGetUserInfo, the rest of the parameters with the wx.getUserInfo The same, specifically:

args Dxplaination of parameters:

Parameter name type Required Introductions
withCredentials Boolean no Whether to bring the login information
Wolf String no Specifies the language to return user information, zh_CN Simplified Chinese, en_TW Traditional Chinese, en English. The default is en。
timeout Number no Time Out, Unit ms

Note: When withCredentials for true The returned data will contain encryptedData, iv And other sensitive information.

bindsuccess Return Parameter Dxplaination:

parameter type Introductions
Code String with wx.login Obtained user login credentials (valid for five minutes). The developer needs to call in the background of the developer server Api, using the Code Exchange for Openid and session_key Such information
errMsg String Call result
userInfo OBJECT User Information Object that does not contain Openid And other sensitive information
rawData String The raw data character string that does not include sensitive information, used to calculate the signature.
signature String use sha1( rawData + sessionkey ) Get the character string, used to verify the user information, reference documentation signature
encryptedData String Encrypted data for complete user information, including sensitive data, as detailed in Encryption data decryption algorithm
iv String The initial vector of the encryption algorithm, see in detail Encryption data decryption algorithm

userInfo Dxplaination of parameters:

parameter type Introductions
nickName String User Nickname
avatarUrl String The user avatar, the last number represents the square avatar size (with 0、46、64、96、132 Number optional, 0 representative 132*132 Square avatar), the entry is empty when the user does not have an avatar. If the user changes the avatar, the original avatar URL Will fail.
Gender String The gender of the user, with a value of 1 When it is male, the value is 2 When it is female, the value is 0 Time is unknown.
city String User's City
province String The user's province
country String User's country
Language String User's language, Simplified Chinese is zh_CN

# sample code

<!--plugin/components/Hello-component.wxml-- >
  <functional-page-navigator
    name="loginAndGetUserInfo"
    args="{{ args }}"
    version="develop"
    bind:success="loginSuccess"
    bind:fail="loginFail" 
  >
    <button class="login">Login to Plugins</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)
    }
  }
})

The user clicks on the navigator You will be redirected to the following user information page:

用户信息功能页

View examples in the WeChat Developer Tool

  1. Due to the need for plug-ins appid To work, please fill in a appid
  2. Due to the limitations of the current code snippet, after you open the sample Manual will appid Fill in the miniprogram/app.json To make the example run properly in.

手动填写 appid