WeChat Open Platform

Mini Programs Documentation

User Info

wx.getUserInfo(OBJECT)

Gets user information, the wx.login interface needs to be called first.

OBJECT parameter descriptions:

Parameter name Type Required Description Minimum version
withCredentials Boolean No Whether login status information included
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

Note: When withCredentials is true, wx.login needs to have been called previously and the login status cannot have expired. The data that is now returned will contain sensitive information including encryptedData and iv. When withCredentials is false, no login status is required and the data returned will not contain sensitive information such as encryptedData or iv.

success return parameter descriptions:

Parameter Type Description
userInfo OBJECT User information object, does not contain sensitive information such as openid
rawData String Raw data strings that do not contain sensitive information, used to calculate signatures
signature String Strings obtained using sha1( rawData + sessionkey ), used to verify user information, refer to signature document
encryptedData String Contains complete encrypted user information data within its sensitive data, refer to Decryption Algorithms for Encrypted Data for more details
iv String The encryption algorithm's initialization vector, refer to Decryption Algorithms for Encrypted Data for more details

Sample code:

wx.getUserInfo({
  success: function(res) {
    var userInfo = res.userInfo
    var nickName = userInfo.nickName
    var avatarUrl = userInfo.avatarUrl
    var gender = userInfo.gender //sex 0: unknown, 1: male, 2: female
    var province = userInfo.province
    var city = userInfo.city
    var country = userInfo.country
  }
})

The json structure below is used after encryptedData is decrypted, refer to Decryption Algorithms for Encrypted Data for more details.

{
    "openId": "OPENID",
    "nickName": "NICKNAME",
    "gender": GENDER,
    "city": "CITY",
    "province": "PROVINCE",
    "country": "COUNTRY",
    "avatarUrl": "AVATARURL",
    "unionId": "UNIONID",
    "watermark":
    {
        "appid":"APPID",
    "timestamp":TIMESTAMP
    }
}

Explanation of UnionID mechanism:

If a developer possesses multiple mobile applications, website applications, and official accounts (including Mini Programs), they can use a UnionID to differentiate the uniqueness of users. This is because a user's UnionID is unique, as long as the mobile applications, website applications or official accounts (including Mini Programs) are under the same WeChat Open Platform account. In other words, a user will have the same UnionID for different applications under the same WeChat Open Platform account.

WeChat Open Platform Mini Program binding process

Prerequisite: WeChat Open Platform accounts must have completed developer qualification verification.

Developer qualification verification process:

Log in to the WeChat Open Platform (open.weixin.qq.com) – Account Center – Developer Qualification Verification.

img

Binding process:

Log in to the WeChat Open Platform (open.weixin.qq.com)—Administration Center—Official Accounts—Bind Official Accounts.

img

Bugs & Tips

  1. tip: The wx.getUserInfo requires user authorization, it is a scene where compatible users are requested to decline authorization.