美文网首页
微信小程序 wx.getUserProfile 获取用户信息

微信小程序 wx.getUserProfile 获取用户信息

作者: hao_developer | 来源:发表于2022-06-27 17:56 被阅读0次

作用:
  获取用户信息。
  每次请求都会弹出授权窗口,用户同意后返回 userInfo对象
  成功时返回一下:

  userInfo:{
  avatarUrl: "头像链接"
  city: "城市"
  country: "国家"
  gender: 1(性别1/0)
  language: "语言"
  nickName: "昵称"
  province: "省份"}

wxml

<view class="box">
  <button class="btn" catchtap="GetUserInfo">登录</button>
</view>

js

GetUserInfo(e) {
    wx.getUserProfile({
      desc:'正在获取',//不写不弹提示框
      success:function(res){
        console.log('获取成功: ',res)
      },
      fail:function(err){
        console.log("获取失败: ",err)
      }
    })
  }

效果图


image.png

相关文章

网友评论

      本文标题:微信小程序 wx.getUserProfile 获取用户信息

      本文链接:https://www.haomeiwen.com/subject/ncwpvrtx.html