2021年4月小程序登录、用户信息相关接口调整处理

原创
2021/05/22 10:42
阅读数 251

一、2021年4月小程序登录、用户信息相关接口调整处理

官方参考链接:

https://developers.weixin.qq.com/community/develop/doc/000cacfa20ce88df04cb468bc52801

 

考虑到近期开发者对小程序登录、用户信息相关接口调整的相关反馈,为优化开发者调整接口的体验,回收wx.getUserInfo接口可获取用户授权的个人信息能力的截止时间由2021年4月13日调整至2021年4月28日24时。
 
  1. 2021年4月28日24时后发布的小程序新版本,无法通过wx.getUserInfo与<button open-type="getUserInfo"/>获取用户个人信息(头像、昵称、性别与地区),将直接获取匿名数据(包括userInfo与encryptedData中的用户个人信息),获取加密后的openID与unionID数据的能力不做调整。此前发布的小程序版本不受影响,但如果要进行版本更新则需要进行适配。
  2. 新增getUserProfile接口(基础库2.10.4版本开始支持),可获取用户头像、昵称、性别及地区信息,开发者每次通过该接口获取用户个人信息均需用户确认。具体接口文档:《getUserProfile接口文档》

 

 

二、小程序页面中处理

1.wxml: bindtap="getUserInfo"

  <view class="empower">
    <button class="grant" bindtap="getUserInfo">授权</button>
    <!-- <button class="grant" open-type="getUserInfo" bindgetuserinfo="getUserInfo">授权</button> -->
    <navigator class="cancel" url="/pages/index/index" open-type="reLaunch">取消授权</navigator>
  </view>

2.js:

  //登陆处理
  getUserInfo: function () {
    var _this = this;
    var info = {};
    //获取配置
    wx.getUserProfile({
      desc: '用于登录使用',
      success: function (data) {
        var userInfo = data.userInfo;
        //获取code
        wx.login({
          success: res => {
            userInfo.code = res.code;
            userInfo.recommendID = wx.getStorageSync("RecommendID");
            var RecommendID = wx.getStorageSync("RecommendID");
            userInfo.RecommendID = RecommendID;
            wx.showLoading({
              title: '正在登录',
            })
            //后台登录验证,此处去后台解密获取用户信息
            account.checkUser(userInfo, res => {
              //初始化位置操作
              account.initLocation();
              wx.showToast({
                title: '登录成功',
                success: () => {
                  // wx.reLaunch({
                  //   url: '/pages/index/index',
                  // })
                  wx.navigateBack({})
                }
              })
            });
          }
        })
      },
      fail: function (e) {
        console.info(e);
        if (e.errMsg.indexOf('deny') != -1) {
          //wx.openSetting();
          wx.showModal({
            title: '登陆失败',
            content: '授权失败,将影响部分高级功能体验哦',
            showCancel: false,
            success: res => {}
          })
        }
      }
    });
  },

获取到用户资料:

 

更多:

 wx.openDocument()微信小程序打开word文件不能转发/编辑 问题

 微信小程序Echarts 图表组件使用整理

 微信小程序 wx.getSystemInfo 返回的platform的值有哪些?

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部