微信登录获取头像和名称等用户信息
<button class="sys_btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="appLoginWx">登录</button>
下面展示一些 内联代码片
。
// An highlighted block
appLoginWx() {
let _this = this;
// #ifdef MP-WEIXIN
uni.getProvider({
service: 'oauth',
success: function(res) {
if (~res.provider.indexOf('weixin')) {
uni.login({
provider: 'weixin',
success: (res2) => {
uni.getUserInfo({
provider: 'weixin',
success: (info) => { //这里请求接口
console.log(res2)
console.log(info)
_this.loginuser(info)
},
fail: () => {
uni.showToast({
title: "微信登录授权失败",
icon: "none"
});
}
})
},
fail: () => {
uni.showToast({
title: "微信登录授权失败",
icon: "none"
});
}
})
} else {
uni.showToast({
title: '请先安装微信或升级版本',
icon: "none"
});
}
}
});
//#endif
}