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

vue tytrock ⋅ 于 2021-10-11 15:58:12 ⋅ 2275 阅读

在企业微信运行小程序需要获取用户资料的时候发现没有反应,查看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

本帖已被设为精华帖!
回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,使用方法请见 Emoji 自动补全来咯,可用的 Emoji 请见 :metal: :point_right: Emoji 列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter