微信小程序的登录流程
2020-08-11 23:36
435 查看
在小程序中
- 在wxml文件
通过button标签
<button open-type="getUserInfo" bindgetuserinfo="processLogin">允许</button>
- 在js文件
//引入auth.js const AUTH = require('../../utils/auth') processLogin(e) { // console.log('我的页面获取用户信息:',e.detail.userInfo) //this为该页面 //调用auth.js文件中的方法 AUTH.register(this); },
- 在auth.js文件里
//引入接口 const {login_wx,getwxre,checkToken } =require('../http/wxw/api') // 详细注册 //使用async 函数 是因为async后必定跟一个promise函数 //使用时可以使用.then()的方法 async function register(page) { //变量声明this解决this指向问题 let _this = this; wx.login({ success: function (res) { // 获取到code值 let code = res.code; // 微信登录接口返回的 code 参数,下面注册接口需要用到 wx.getUserInfo({ success: function (res) { //获取用户信息 console.log('utils文件夹auth文件用户信息再次获取',res) let iv = res.iv; let encryptedData = res.encryptedData; // 下面开始调用注册接口使用的是分装好的接口 //接口问题在上一个文章中提到 getwxre({ code: code, encryptedData: encryptedData, iv: iv, }).then(function (res) { //调用该页面的login方法 _this.login(page); }) } }) } }) } // 登录 async function login(page){ const _this = this wx.login({ success: function (res) { //下面是登录的接口需要wx.login的方法传入code值 login_wx(res.code).then(function (res) { //本地保存token信息和uid信息 wx.setStorageSync('token', res.data.token) wx.setStorageSync('uid', res.data.uid) if ( page ) { //使页面刷新 page.onShow() } }) } }) }
相关文章推荐
- 微信小程序 登录流程规范解读
- php实现微信小程序授权登录功能(实现流程)
- 微信小程序登录流程
- 微信小程序登录流程
- 微信小程序登录流程梳理
- 微信小程序中短信验证码登录全流程及代码
- 微信小程序开发(一) 微信登录流程
- 微信小程序登录流程
- 微信小程序的用户登录流程
- 微信小程序登录流程
- 微信小程序 登录流程规范
- 微信小程序中短信验证码登录全流程及代码
- 微信小程序Java登录流程(ssm实现具体功能和加解密隐私信息问题解决方案)
- 微信小程序登录流程整理
- 微信小程序开发之授权登录流程
- 微信小程序Java登录流程(ssm实现具体功能和加解密隐私信息问题解决方案)
- 微信小程序开发(一) 微信登录流程详解
- 微信小程序开发--微信登录流程
- 微信小程序中短信验证码登录全流程及代码
- 微信小程序登录流程