uniapp app端一键微信登录和小程序端一键微信登录 您所在的位置:网站首页 uniapp微信一键登录签名不对 uniapp app端一键微信登录和小程序端一键微信登录

uniapp app端一键微信登录和小程序端一键微信登录

2024-07-02 19:47| 来源: 网络整理| 查看: 265

微信快捷登录 微信端 app端

//小程序登录 begin登录 // 逻辑:登录 > 拿到code > 后端通过code获取sessionKey、openid(unionid)等

        wxLogin(e) {         let _this = this;           uni.login({ provider: 'weixin', success: function(res) { console.log(res); if (res.code) { let code = res.code; //将用户登录code传递到后台置换用户SessionKey、OpenId等信息 //...写用code置换SessionKey、OpenId的接口 // _this.$http.post("/api/user/login", {code:code}) // .then(res => { // let openId= res.openId; // _this.wxSubmit(openId) // }) // .catch(err => { // _this.$ant.toast('登录失败') // }); } else { uni.showToast({ title: '登录失败!', duration: 2000 }); console.log('登录失败!' + res.errMsg) } }, });         }

// app登录逻辑  app端能直接拿到openId

appLogin() { var that = this; uni.getProvider({ service: 'oauth', success: function(res) { console.log(res.provider); //支持微信、qq和微博等 if (~res.provider.indexOf('weixin')) { uni.login({ provider: 'weixin', success: function(loginRes) { console.log("App微信获取用户信息成功", loginRes); // 获取用户信息 uni.getUserInfo({ provider: 'weixin', success: function(infoRes) { console.log('-------获取微信用户所有-----'); console.log(infoRes.userInfo.openId); console.log(JSON.stringify(infoRes.userInfo)); // 提交信息 that.wxSubmit(infoRes.userInfo.openId) } }); // that.getApploginData(loginRes) //请求登录接口方法 }, fail: function(res) { console.log("App微信获取用户信息失败", res); } }) } } }); },

记录时间2021-07-13,亲测有效,有用的话,麻烦给点个赞。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有