最新微信更新了授权的接口 wx.getUserProfile, 并且会在2021年4月28日回收原来的接口 wx.getUserInfo. 详情见微信官方文档
由于我们是社区类小程序,必须要拿到用户的昵称和头像。所以及时更新了接口,以下是开发过程中遇到的问题和解决方案:
-
基础库2.10.4版本以下的设备无法通过getUserProfile登陆
解决方案是按照官方给的demo, 在页面加载时判断wx.getUserProfile是否可用。如果不可用,暂时用旧的接口替代。
<view class="container">
<view class="userinfo">
<block wx:if="{
{!hasUserInfo}}">
<button wx:if="{
{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
<button wx:else open-type="getUserInfo