1、主动授权登录
<button open-type="getUserInfo" bindgetuserinfo="getUserInfomation">
微信账号登录
</button>
getUserInfomation: function (e) {
if (e.detail.errMsg !== 'getUserInfo:ok') {
return wx.showToast({
title: '未授权,登录失败',
icon: 'none'
});
//也可引导去授权设置页
// openSetting();
}
wx.showLoading({
title: '登录中',
mask: true
});
wx.login({
success: loginCode => {
let code = loginCode.code;
wx.getUserInfo({
success: userInfo => {
api.wxLogin({
encryptedData: userInfo.encryptedData,
iv: userInfo.iv,
code: code,
device: app.globalData.systemInfo.model//提前获取
}, res => {
//登录成功后续操作
wx.hideLoading();
ap