当前位置: 首页 > news >正文

微信小程序记录(持续更新)

1.登录相关

登录简单来说就是用uni.login获取登陆凭证code。然后调用后台登录接口传递给后台,后台解码再返回token等一系列信息给前端

参考地址:

微信小程序获取用户手机号码教程(前端+后端)_微信小程序获取手机号-CSDN博客

代码

login() {let _this = this;// 获取登录用户codeuni.login({provider: 'weixin',success: function(res) {console.log(res,'res')if (res.code) {let code = res.code;//微信授权的人员信息uni.setStorageSync("wxUserInfo", _this.userInfo);uni.request({url: $newApi.AuthLoginByWeixin,method: 'GET',data: {code: code,// userInfo: _this.userInfo,tenant:_this.tenant},header: {'content-type': 'application/json', //自定义请求头信息'tenant':_this.tenant,							},success: function(res) {console.log("授权登录", res);uni.setStorageSync("userInfo", res.data.userInfo);_this.openid = res.data.userInfo.openid;if (res.data.token && res.data.token != '') {uni.setStorageSync("token", res.data.token);}if (_this.pageName == '/pages/home/studentHome') {uni.switchTab({url: _this.pageName})} else {//存在sessionId则直接去扫码的页面,没有的话就去获取手机号码if (res.data.userInfo.sessionId && res.data.userInfo.sessionId.length > 0) {console.log("if", _this.pageName)uni.navigateTo({url: _this.pageName,success(res) {console.log(res)},fail(err) {console.log(err);uni.switchTab({url: _this.pageName})}})} else {console.log("else")// _this.updateUserInfo()}}},fail: (error) => {console.log("授权登录失败", error)},complete: (res) => {}});} else {uni.showToast({title: '登录失败!',duration: 2000});}},});},


http://www.mrgr.cn/news/10025.html

相关文章:

  • C++ 设计模式——外观模式
  • 新手学习打怪之编译安装LAMP和LNMP
  • Linux 软件编程 数据库
  • 分布式搜索引擎 -- 搜索结果处理以及RestClient查询文档
  • 提高客服响应率的快捷回复软件
  • 将Web应用部署到Tomcat根目录的三种方法
  • 拿下英语翻译!这四款在线翻译功不可没!
  • 【Python游戏】Joystick游戏手柄编程介绍
  • uni-app常用标签
  • 控制反转(IOC)——Spring第一个核心思想
  • Python画笔案例-012 绘制空心T字
  • 可视化大屏-实现自动滚动
  • 机器学习课程学习周报九
  • 浪潮服务器系统下重置BMC密码的方法
  • Java Web —— 第八天(登录功能)
  • 优质翻译对提升中国商品品牌信誉的影响
  • 贪心算法---跳跃游戏(2)
  • <数据集>骨折检测数据集<目标检测>
  • avue-crud 是基于 Vue.js 的一个高度封装的表格(CRUD)组件库
  • easyExcel 导入时,校验每个单元格数据