Directly display user profile picture and name (only current user can be obtained)
<open-data type="userAvatarUrl"></open-data>
<open-data type="userNickName"></open-data>
<open-data type="userCountry"></open-data>
<open-data type="userCity"></open-data>
Copy the code
wx.getUserInfo
A dialog box cannot be displayed. Only authorized users can obtain user information
wx.getUserInfo({
success: res => {
console.log(res)
}
})
Copy the code
Confirm to obtain the user information
// WXML <button open-type="getUserInfo" bindgetUserinfo ="onGetUserInfo"> console.log(e) }Copy the code
To obtain the openId
Regular pattern
- The applets get the code credentials through wx.login, and then call wx.request to pass the code to the back-end server
- The backend server uses code in exchange for openI and session_key
- The back-end server sends the user id to the applet local store
Cloud Development model
To get user information, call the login function
wx.cloud.callFunction({
name: 'login'
}).then(res => {
console.log(res)
)
Copy the code
OpenId is different from unionId
The wechat mini program is not associated with the openId of the wechat public account and can be identified by unionId.