微信小程序为优化用户体验,使用wx.getUserInfo接口直接弹出授权框的开发方式将逐渐不在支持。从2018年4月30日开始,小程序与小游戏的体验版、开发版调用wx.getUserInfo接口,将无法弹出授权框,默认调用失败。正式版暂不受影响,开发者可使用一下方式获取或展示与用户信息
一、小程序
1、使用 button 组件,并将 open-type 指定为 getUserInfo 类型,获取用户基本信息。
详情参考文档:https://developers.weixin.qq.com/miniprogram/dev/component/button.html
2、使用open-data展示用户信息
详情参考文档:https://developers.weixin.qq.com/miniprogram/dev/component/open-data.html
代码如下:
<button open-type="getUserInfo" @tap=