微信小程序之获取用户信息接口优化调整

由于收到开发者的反馈,为了方便开发者更好地使用获取用户信息的接口,开发者仍然可以使用 wx.getUserInfo 接口获取用户信息。

具体优化调整如下:

1.获取用户头像昵称,第一次需要使用 button 组件授权,如果已经用组件授权了,wx.getUserInfo 可直接返回用户数据,无需重复授权弹窗。
2. 如果没有用 button 组件授权,wx.getUserInfo 调用接口返回失败,提醒开发者需要先使用 button 组件授权。
3. 用户可在设置中,取消授权。取消授权后需重新用 button 组件拉起授权。

此次调整仅会影响开发者工具、体验版和开发版,正式版本小程序暂不受影响。

详细可见如下接口文档:

小程序:

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

小游戏:

1.使用用户信息按钮 UserInfoButton。

详情参考文档:

https://developers.weixin.qq.com/minigame/dev/document/open-api/user-info/wx.createUserInfoButton.html

2.开放数据域下的展示用户信息。

详细参考文档:

https://developers.weixin.qq.com/minigame/dev/document/open-api/data/wx.getUserInfo.html

请各位开发者注意及时调整接口,正式版未来也会逐步切换为这个逻辑。

突然收到这个消息的我是懵逼的,因为这意味着我要改需求!
新的处理方式就是
我的做法是做一个缓冲加载页,然后通过wx.getUserInfo获取用户信息,如果已经授权过了,那么是可以获取信息的
如果没有授权过,则出现button,然后再获取用户信息
基于weui,getUserInfo请参考链接微信小程序至wx.getUserInfo与wx.login接口应用分享
loading.js

var app=getApp()
Page({
  data:{
    loading:true,
  },
  onLoad: function () {
    var that = this;
    app.getUserInfo(function(){
      app.toIndex()//加载成功
    },function(){
      that.setData({loading:false})//加载失败
    });
  },
  login:function(e){
    app.globalData.userInfo = e.detail.userInfo;
    console.log('用户信息', app.globalData.userInfo);
    wx.login({
      success: function (res) {
        var code = res.code;
        app.login(code, e.detail, function () {
          app.toIndex()
        });
      }
    })
  }
})

loading.wxml

<view class="page">
  <view class="loading_tip ">
    <view class="classname">为体育赛事提供在线解决方案</view>
    <button open-type="getUserInfo" type='primary' bindgetuserinfo="login" hidden='{{loading}}'>点此登录</button>
    <view class="weui-loadmore" hidden='{{!loading}}'>
      <view class="weui-loading"></view>
      <view class="weui-loadmore__tips">启动中</view>
    </view>
  </view>
  <view class="page__bd page__bd_spacing">
    <view class="weui-footer weui-footer_fixed-bottom">
      <view class="weui-footer__links">
        <view class="weui-footer__link">赛事通</view>
      </view>
      <view class="weui-footer__text">Copyright © 2018</view>
    </view>
  </view>
</view>

loading.wxss

.loading_tip{
  position: fixed;
  height: 100%;
  width: 100%;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content: center;
  font-size: 1rem
}

猜你喜欢

转载自blog.csdn.net/xjc8289555/article/details/80297854