# wx.getUserProfile(Object object)
Start from base library version 2.10.4. Please remaining backward compatible.
with Promise style call: Supported
Mini Program plugin: Not supported
Get user information. The page generates a click event such as button
on bindtap
Each request will pop up an authorization window after the user agrees to return userInfo
The interface is used to replace the wx.getUserInfo
See User Information Interface Adjustment Specification。
# parameter
# Object object
attribute | type | Default values | Required | Introductions |
---|---|---|---|---|
long | string | in | no | Language for displaying user information |
desc | string | yes | Declare the purpose of obtaining the user's personal information, no more than 30 characters | |
success | function | no | Interface calls the successful callback function | |
fail | function | no | Interface calls failed callback functions | |
complete | function | no | Interface calls the end of the callback function (call success or failure will be executed) |
object.long Legal value
value | Introductions | Minimum version |
---|---|---|
in | English | |
zh_CN | Simplified Chinese | |
zh_TW | Traditional Chinese |
# object.success callback
# parameter
# Object res
attribute | type | Introductions | Minimum version |
---|---|---|---|
userInfo | UserInfo | User information object | 2.10.4 |
rawData | string | Raw data string that does not include sensitive information for computing signatures | 2.10.4 |
signature | string | Use sha1( rawData + sessionkey ) Gets a string used to verify user information, see Signature verification and encryption and decryption of user data | 2.10.4 |
encryptedData | string | Encrypted data for complete user information, including sensitive data, see [Signature verification and encryption and decryption of user data]((signature#Encryption data decryption algorithm)) | 2.10.4 |
iv | string | Encryption algorithm initial vector, see [Signature verification and encryption and decryption of user data]((signature#Encryption data decryption algorithm)) | 2.10.4 |
cloudID | string | Cloud of sensitive data ID, OpenCloud DevelopmentThe Mini Program will return, can directly access open data through the cloud call, seeDirect access to open data for cloud calls | 2.10.4 |
# sample code
# Bug & Tip
tip
: only in the Mini Programwx.getUserInfo
Interface adjustment, small game is not affectedtip
Only in developer tools 2.10.4 And above version can be accessedwx.getUserProfile
Interface, you can refer to the sample code on the real machine to determine, without the need to rely on the version number orcanIUse
Conditions of Conduct.tip
:wx.getUserProfile
The returned encrypted data does not containopenId
andunionId
Field.bug
In developer tools2.10.4``2.16.1
Base library version passed<button open-type="getUserInfo">
Returns real data, and on real machines this interval returns anonymous data as advertised.
<view class="container">
<view class="userinfo">
<block wx:if="{{!hasUserInfo}}">
<button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> Get avatar nicknames </button>
<button wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo"> Get avatar nicknames </button>
</block>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
</view>
Page({
data: {
userInfo: {},
hasUserInfo: false,
canIUseGetUserProfile: false,
},
onLoad() {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
getUserProfile(and) {
// Recommended to use wx.getUserProfile to obtain user information, developers every time through the interface access to user personal information are required to confirm the user
// Developers safeguarded the user quickly fill in the avatar nickname, to avoid repeated pop-ups
wx.getUserProfile({
desc: 'Use to improve membership information ', // Declare the user's personal information after the purpose, the follow-up will be displayed in the pop-up window, please fill in carefully
success: (res) => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
getUserInfo(and) {
// It is not recommended to use getUserInfo to get user information, it is expected that from April 13, 2021, getUtherInfo will no longer pop-up pop-up window, and will directly return anonymous user personal information
this.setData({
userInfo: and.detail.userInfo,
hasUserInfo: true
})
},
})