web前端全系列 教程
1839个小节阅读:2243.6k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
获取用户信息。页面产生点击事件后才可调用,每次请求都会弹出授权窗口,用户同意后返回 userInfo
通过wx.getUserProfile()
方法进行获取
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
desc | string | 是 | 声明获取用户个人信息后的用途,不超过30个字符 | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
xxxxxxxxxx
<button type="primary" bindtap="getUserProfile"> 获取头像昵称 </button>
<view>
<image src="{{userInfo.avatarUrl}}"></image>
<text>{{userInfo.nickName}}</text>
</view>
xxxxxxxxxx
Page({
data: {
userInfo: {},
},
getUserProfile(e) {
wx.getUserProfile({
desc: '展示用户信息',
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo
})
},
fail(err){
console.log(err);
},
complete(){
console.log("获取完成");
}
})
}
})
实时效果反馈
1. 在微信小程序中,获取用户信息,是否可以直接获取用户的微信号:
A 可以获取
B 无法获取
答案
1=>B