当前位置:网站首页>Getting user information for applet learning (getuserprofile and getUserInfo)
Getting user information for applet learning (getuserprofile and getUserInfo)
2022-06-24 09:54:00 【. Bemoan】
Digression :
When learning this module, I read b One of the stations 20 In the video , The video is used when the teacher gives examples getUserInfo Interface , However, the information obtained by the teacher is indeed anonymous . We have to search the Internet and find getUserInfo Interface in 21 In, the function was changed .
getUserInfo The changes to the :
Adjustment instructions
since 2022 year 10 month 25 Japan 24 After the hour ( The following a general designation “ Effective period ” ), The rules for obtaining user avatar nicknames will be adjusted as follows :
- From the effective date , Applet wx.getUserProfile The interface will be retracted : New version of the applet released after the effective date , adopt wx.getUserProfile Interface to get the user image will return to the default Gray head , Nicknames will be returned uniformly “ WeChat users ”. Versions of applets released before the effective date will not be affected , If it needs to be adapted, it needs to be updated .
- From the effective date , Plug in through wx.getUserInfo Interface to get the user's nickname avatar will be recalled : New versions of plug-ins released after the effective date , adopt wx.getUserInfo Interface to get the user image will return to the default Gray head , Nicknames will be returned uniformly “ WeChat users ”. Plug in versions released before the effective date will not be affected , If it needs to be adapted, it needs to be updated . adopt wx.login And wx.getUserInfo Interface acquisition openId、unionId Capability not affected .
- 「 Ability to fill in Avatar nicknames 」 Support to get the nickname of the user's Avatar : If the business needs to obtain the user's Avatar nickname , have access to 「 Ability to fill in Avatar nicknames 」( Base library 2.21.2 Version starting support ), Specific practices can be seen below 《 Best practices 》.
- Applet wx.getUserProfile And plug-ins wx.getUserInfo Interface compatibility base library 2.21.2 The following versions of avatar nickname acquisition requirements : Above 「 Ability to fill in Avatar nicknames 」 From the base library 2.21.2 Version starting support ( Cover wechat 8.0.16 Above version ). For access from lower versions of basic libraries and wechat clients , Small program passed wx.getUserProfile The interface will normally return the user's Avatar nickname , Plug in through wx.getUserInfo Interface will return the user's Avatar nickname , Developers can continue to use the above capabilities for downward compatibility .
That is to say, the original passage wx.getUserInfo Interface to get the user id And the function of the avatar is getUserProfile Interface substitution .
getUserProfile
Function description :
Get user information . Page click event ( for example button On bindtap In the callback ) Can only be called after , Each request will bring up an authorization window , The user agrees and returns userInfo. This interface is used to replace wx.getUserInfo,
Examples :
js:
// index.js
// Get application instance
const app = getApp()
Page({
data: {
motto: ' Clean Calculator Beta ',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile:false,
canIUseOpenData: false // To try to get user information, change to false
},
// Event handler
// bindViewTap() {
// wx.navigateTo({
// url: '../logs/logs'
// })
// },
onLoad() {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
getUserProfile(e) {
// Recommended wx.getUserProfile Get user information , Every time the developer obtains the user's personal information through the interface, the user needs to confirm , Developers keep the nicknames of avatars that users fill in quickly , Avoid repeated pop ups
wx.getUserProfile({
desc: ' Display user information ', // Declare the purpose of obtaining the user's personal information , The follow-up will be shown in the pop-up window , Please fill in carefully
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
getUserInfo(e) {
// It is not recommended to use getUserInfo Get user information , Estimated from 2021 year 4 month 13 The date of ,getUserInfo Pop ups will no longer pop up , And directly return the anonymous user's personal information
console.log(e)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}wxml:
<!--index.wxml-->
<view class="container">
<view class="userinfo">
<block wx:if="{
{canIUseOpenData}}">
<view class="userinfo-avatar" bindtap="bindViewTap">
<open-data type="userAvatarUrl"></open-data>
</view>
<open-data type="userNickName"></open-data>
</block>
<block wx:elif="{
{!hasUserInfo}}">
<button wx:if="{
{canIUseGetUserProfile}}" bindtap="getUserProfile"> Sign in </button>
<button wx:elif="{
{canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> Get head nickname </button>
<view wx:else> Please use 1.4.4 And above </view>
</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 class="usermotto">
<button >
<navigator url="/pages/calculator/calculator" open-type="switchTab"> Clean Calculator Beta </navigator>
</button>
<button class="change" >
<navigator url="/pages/change_/changes_" open-type="switchTab"> Conversion tool </navigator>
</button>
</view>
</view>



边栏推荐
- 小程序学习之获取用户信息(getUserProfile and getUserInfo)
- Summary of medical image open source datasets (II)
- [Eureka source code analysis]
- 416-二叉树(前中后序遍历—迭代法)
- Which of the top ten securities companies has the lowest Commission and is the safest and most reliable? Do you know anything
- PHP file lock
- 二十、处理器调度(RR时间片轮转,MLFQ多级反馈队列,CFS完全公平调度器,优先级翻转;多处理器调度)
- Binary tree part I
- Prct-1400: failed to execute getcrshome resolution
- How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
猜你喜欢

NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!

grpc本地测试联调工具BloomRPC

Record the range of data that MySQL update will lock

有关二叉树 的基本操作

Oracle 12c升级至19c后ORA-28000错误

如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!

Canvas draw picture

nVisual数字基础设施运营管理软件平台

R 椭圆随机点产生并画图

CICFlowMeter源码分析以及为满足需求而进行的修改
随机推荐
Servlet快速筑基
算法---矩阵中战斗力最弱的 K 行(Kotlin)
port 22: Connection refused
算法--找到和最大的长度为 K 的子序列(Kotlin)
桌面软件开发框架大赏
观察者模式
Is there a reliable and low commission futures account opening channel in China? Is it safe to open an account online?
PRCT-1400 : 未能执行 getcrshome解决方法
R 椭圆随机点产生并画图
indexedDB本地存储,首页优化
PHP file lock
Cicflowmeter source code analysis and modification to meet requirements
5分钟,客服聊天处理技巧,炉火纯青
字节跳动-面试官: 谈下音视频同步原理,音频和视频能绝对同步吗?
Top issue tpami 2022! Behavior recognition based on different data modes: a recent review
二叉树第一部分
数字化转型的失败原因及成功之道
Why is LNX of e equal to X
WindowManager 简单悬浮框的实现
Literature Research Report