2021年4月小程序登錄、用戶信息相關接口調整處理

一、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的值有哪些?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章