uniAPP·拉取微信QQ授权登陆获取js_code
uniAPP·拉取微信QQ授权登陆获取js_code
后端请求地址:
//微信接口 地址:https://api.weixin.qq.com/sns/jscode2session appid:wxxxxxx secret:xxxxxx grant_type:authorization_code js_code:xxxxx //QQ接口 地址:https://api.q.qq.com/sns/jscode2session appid: 123xxxx secret: xxxx grant_type:authorization_code js_code:xxxx
以下缺一不可:
getUserInfoWX() { return new Promise((resolve, reject) => { wx.getUserProfile({ lang: 'zh_CN', desc: '用户登录', success: (res) => { resolve(res.userInfo) }, fail: (err) => { reject(err) } }) }) }, getLoginWX() { return new Promise((resolve, reject) => { wx.login({ success(res) { resolve(res.code) }, fail: (err) => { reject(err) } }) }) },
Login(e) { //小程序 拉起授权提示 var thiss = this let userInfo = this.getUserInfoWX(); let wxCode = this.getLoginWX(); Promise.all([userInfo, wxCode]).then((res) => { console.log("获取权限成功1:", res) }).catch(err => { console.log("获取权限成功2:", res) }) //APP 获取授权后的 js——code uni.login({ //provider: 'weixin', success: function(loginRes) { console.log(loginRes.authResult); // 获取用户信息 uni.getUserInfo({ // provider: 'weixin', success: function(infoRes) { console.log('昵称:', infoRes.userInfo.nickName); console.log("code:", loginRes.code); } }); } }); },
1,105 Views