当前位置:编程学习 > > 正文

wx小程序请求封装(小程序wx.getUserProfile接口的具体使用)

时间:2022-01-21 00:49:15类别:编程学习

wx小程序请求封装

小程序wx.getUserProfile接口的具体使用

最近微信小程序对于审核小程序提出了带有wx.login、wx.getUserInfo接口的调整,并提出了一个新的接口供开发者调用

下图是对于新的接口的官方文档详情

点击前往官网查看更多详细信息

wx小程序请求封装(小程序wx.getUserProfile接口的具体使用)

wx小程序请求封装(小程序wx.getUserProfile接口的具体使用)

值得注意的是新的接口wx.getUserProfile,只能使用catchtap或者bindtap进行调用(ps:可以再wx.showmodel中使用),并不能再onload、onshow等位置直接调用,并且返回参数有所改变

下图是新的接口wx.getUserProfile返回的数据类型

  • // An highlighted block
     wx.showModal({
       title: '温馨提示',
       content: '正在请求您的个人信息',
       success(res) {
         if (res.confirm) {
           wx.getUserProfile({
           desc: "获取你的昵称、头像、地区及性别",
           success: res => {
             console.log(res)
             let wxUserInfo = res.userInfo;
           },
           fail: res => {
           	 //拒绝授权
             that.showErrorModal('您拒绝了请求');
             return;
           }
         })} else if (res.cancel) {
           //拒绝授权 showErrorModal是自定义的提示
           that.showErrorModal('您拒绝了请求');
           return;
         }
       }
     })
    
    
  • wx小程序请求封装(小程序wx.getUserProfile接口的具体使用)

    新版的wx.login接口返回,暂时wx.getUserInfo的接口返回不变,之后就不能直接获取用户信息了

    wx.login

    wx小程序请求封装(小程序wx.getUserProfile接口的具体使用)

    wx.getUserInfo

    wx小程序请求封装(小程序wx.getUserProfile接口的具体使用)

    为了这个新接口搞了一段时间,可能咱比较菜吧(不是,ヽ(≧□≦)ノ)。总之,这件事总得是有了一个头绪不是吗?希望这些能帮助更多的小伙伴!<( ̄︶ ̄)>

    到此这篇关于小程序wx.getUserProfile接口的具体使用的文章就介绍到这了,更多相关小程序wx.getUserProfile接口内容请搜索开心学习网以前的文章或继续浏览下面的相关文章希望大家以后多多支持开心学习网!

    上一篇下一篇

    猜您喜欢

    热门推荐