方法封装如下:
getLoginPermission() {
//获取用户登录权限
var that = this;
//查看是否授权
uni.getSetting({
success: function(res) {
//微信登录接口
uni.login({
success: res => {
that.code = res.code;
//请求微信后台接口返回openid 和 sessionKey
uni.request({
url: that.public_ip + '/assets/login/wxLogin?code=' + res.code,
header: {
'content-type': 'application/x-www-form-urlencoded' //'application/json'
},
method: 'POST',
success: res => {
that.setUserInfoGlobal2(res.data.openid);
that.setUserInfoGlobal11(res.data.Appid);
that.setUserInfoGlobal3(res.data.session_key);
},
fail: res => {
uni.showModal({
content: '接口请求失败',
showCancel: false
});
},
complete: () => {}
});
}
});
}
});
},