| | |
| | | // pages/index/bindInfo/index.js |
| | | import { setSessionGuid } from "../../assets/js/userAction" |
| | | const app = getApp(); |
| | | Page({ |
| | | |
| | |
| | | data: { |
| | | avatarUrl: "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0", |
| | | nickName: "", |
| | | wxCode: null, |
| | | redirectPage: "" |
| | | }, |
| | | |
| | | onChooseAvatar(res) { |
| | |
| | | app.MG.identity.loginByWeChatAppCode({ |
| | | code: res.code, |
| | | appRefCode: app.config.appRefCode, |
| | | platform: "weChatApp", |
| | | platform: "WeChatAppCustom", |
| | | icon: this.data.avatarUrl, |
| | | encryptedData: infoRes.encryptedData, |
| | | iv: infoRes.iv, |
| | | name: this.data.nickName, |
| | | }).then(res => { |
| | | if (res && res.status == "Ok") { |
| | | // 储存token |
| | | wx.setStorageSync(app.config.tokenKey, res.token); |
| | | // 获取用户信息 |
| | | this.getUserInfo() |
| | | // 记录登录统计 |
| | | // setSessionGuid() |
| | | } else { |
| | | wx.showToast({ |
| | | icon: "error", |
| | | title: res.message, |
| | | }); |
| | | } |
| | | }) |
| | | }, |
| | |
| | | // 获取登录用户身份 |
| | | getUserInfo() { |
| | | app.MG.identity.getCurrentAppUser().then(res => { |
| | | // console.log(res, "userInfo"); |
| | | // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认) |
| | | if (res) { |
| | | let defaultUser = {}; |
| | | // let secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword') |
| | | let WeChatInfo = res.infoList.find((item) => item.type === "WeChat"); |
| | | let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone') |
| | | |
| | |
| | | weChatId: WeChatInfo.id |
| | | } |
| | | } |
| | | |
| | | if (phoneNumber) { |
| | | defaultUser.phoneNumber = phoneNumber.credential |
| | | } |
| | | this.setData({ |
| | | userInfo: defaultUser, |
| | | loading: false |
| | | }) |
| | | wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo)); |
| | | wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); |
| | | } |
| | | wx.switchTab({ |
| | | url: '/pages/index/index' |
| | | wx.navigateTo({ |
| | | url: this.data.redirectPage ? this.data.redirectPage : '/pages/home/home' |
| | | }) |
| | | }); |
| | | }, |
| | |
| | | */ |
| | | onLoad(options) { |
| | | console.log(options, "options"); |
| | | console.log(decodeURIComponent(options.page)); |
| | | this.setData({ |
| | | wxCode: options.code |
| | | redirectPage: decodeURIComponent(options.page) |
| | | }) |
| | | }, |
| | | |