微信小程序用户头像昵称获取规则调整对应

根据微信社区的最新公告,自2022年11月8日24时起,小程序 wx.getUserProfile 接口、wx.getUserInfo 接口获取用户昵称头像将被收回

对于来自低于2.27.1版本的访问,小程序通过 wx.getUserProfile 接口将正常返回用户头像昵称,插件通过 wx.getUserInfo 接口将正常返回用户头像昵称。不过基础库2.27.1及以上版本将不再支持。

已使用 wx.getUserProfile 接口的小程序开发者和已使用 wx.getUserInfo 接口的插件开发者应尽快适配。小游戏不受本次调整影响。

官方公告:https://developers.weixin.qq.com/community/develop/doc/00022c683e8a80b29bed2142b56c01

最佳实践

小程序可在个人中心或设置等页面使用头像昵称填写能力让用户完善个人资料

在这里插入图片描述

使用方法

头像选择

需要将 button 组件 open-type 的值设置为 chooseAvatar,当用户选择需要使用的头像之后,可以通过 bindchooseavatar 事件回调获取到头像信息的临时路径。若用户上传的图片未通过安全监测,不触发bindchooseavatar 事件。

<button open-type="chooseAvatar" bindchooseavatar="chooseavatar"></button>
chooseavatar(e) {
    
    
	console.log(e.detail.avatarUrl)//头像信息的临时路径
},

在这里插入图片描述

昵称填写

需要将 input 组件 type 的值设置为 nickname,当用户在此 input 进行输入时,键盘上方会展示微信昵称。

<input type="nickname" bindinput="handleInput" placeholder="设置昵称" />

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44646763/article/details/127869111
今日推荐