企业微信运行小程序不支持 wx.getUserProfile 的解决办法

vue ⋅ tytrock ⋅ at 2021-10-11 15:58:12 ⋅ 5084 Reads

在企业微信运行小程序需要获取用户资料的时候发现没有反应,查看log发现企业微信里提示找不到wx.getUserProfile方法

image.png


网上查看相关,发现企业微信竟然还没有支持新的wx.getUserProfile方法,而是还需要用回旧的getuserinfo方法。

image.png


那只能代码里区分一下了

<button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
<button wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
Page({
    data: {
        userInfo: {},
        canIUseGetUserProfile: false,
    },
      onLoad()
      {
          if (wx.getUserProfile) {
              this.setData({
              canIUseGetUserProfile: true
          })
       }
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    wx.getUserProfile({
        desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
        success: (res) => {
            this.setData({
                userInfo: res.userInfo
            })
        }
    })
  },
  getUserInfo(e) {
      // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
    this.setData({
        userInfo: e.detail.userInfo,
    })
  },
})


参考:https://developers.weixin.qq.com/community/develop/doc/000a465d3e848045680cec75d5fc00

This topic has been mark as Excenllent Topic.
Total Reply Count: 0
    No comments~~
    • publish_typography
    • publish_markdown
    • 支持表情,使用方法请见 Emoji 自动补全来咯,可用的 Emoji 请见 :metal: :point_right: Emoji 列表 :star: :sparkles:
    • publish_image
    • publish_draft
    Ctrl+Enter