wx.getUserInfo 切换到 wx.getUserProfile
发布于 2 年前 作者 houyan 4086 次浏览 来自 分享

看了一下很久以前的小程序,发现之前用的wx.getUserInfo需要进行修改

官方的文档

https://developers.weixin.qq.com/community/develop/doc/000cacfa20ce88df04cb468bc52801?highLine=getUserInfo%2520%25E5%2588%2587%25E6%258D%25A2%25E5%2588%25B0%2520getUserProfile

因为微信修改了规则

所以原来的wx.getUserinfo不能够使用了

所以使用wx.getUserProfile

  /**
   * 判断用户是否登录
   */
  jugdeUserLogin: function(event) {
        var that = this
        wx.getUserProfile({
          desc:'登录',
          success:(res)=>{
              that.data.user = res.userInfo;
              console.log(that.data.user)
              that.formSubmit();
          },
          fail:(res)=>{
            // debugger
            console.log(res)
          }
        });
    // // 查看是否授权
    // wx.getSetting({
    //   success(res) {
    //     if (res.authSetting['scope.userInfo']) {
    //       // 已经授权,可以直接调用 getUserInfo 获取头像昵称
    //       wx.getUserInfo({
    //         success: function(res) {

    //           that.data.user = res.userInfo;
    //           console.log(that.data.user)
    //         }
    //       })
    //     }
    //   }
    // })
  },

可以看一下我的注释部分是之前的版本的

同时我还删除了 button 中的open-type的属性

变得地方就在跳转而已,其他没有大的变化。

3 回复

hh我用小程序的时候就已经是wx.getUserProfile了,所以就一直用这个了

怎么返回是否授权结果呢

回到顶部