| | |
| | | import { |
| | | setSessionGuid |
| | | } from "./userAction" |
| | | |
| | | const app = getApp(); |
| | | import MG from './middleGround/WebMiddleGroundApi'; |
| | | import config from './config'; |
| | | |
| | | export const loginInfo = (app, callback) => { |
| | | if (app.config.appId == 27) { |
| | | if (config.appId == 27) { |
| | | wx.navigateTo({ |
| | | url: "/pages/testLogin/index", |
| | | }); |
| | |
| | | success: (res) => { |
| | | wx.getUserInfo({ |
| | | success: (infoRes) => { |
| | | // debugger |
| | | app.MG.identity.checkWeChatAppAccount({ |
| | | MG.identity.checkWeChatAppAccount({ |
| | | code: res.code, |
| | | appCode: app.config.appRefCode, |
| | | appCode: config.appRefCode, |
| | | encryptedData: infoRes.encryptedData, |
| | | iv: infoRes.iv |
| | | }).then(loginRes => { |
| | |
| | | } else { |
| | | wx.login({ |
| | | success: (res) => { |
| | | app.MG.identity.loginByWeChatAppCode({ |
| | | MG.identity.loginByWeChatAppCode({ |
| | | code: res.code, |
| | | appRefCode: app.config.appRefCode, |
| | | appRefCode: config.appRefCode, |
| | | platform: "WeChatAppCustom", |
| | | encryptedData: infoRes.encryptedData, |
| | | iv: infoRes.iv |
| | | }).then(res => { |
| | | if (res && res.status == "Ok") { |
| | | // 储存token |
| | | wx.setStorageSync(app.config.tokenKey, res.token); |
| | | wx.setStorageSync(config.tokenKey, res.token); |
| | | // 获取用户信息 |
| | | getUserInfo(app, callback, res.token) |
| | | // 记录登录统计 |
| | | setSessionGuid() |
| | | //登录记录积分 |
| | | MG.app.creatUserBehavior({ |
| | | refCode: "sign" |
| | | }) |
| | | } else { |
| | | console.log(res); |
| | | callback(false) |
| | |
| | | }) |
| | | } |
| | | } |
| | | |
| | | // 获取登录用户身份 |
| | | const getUserInfo = (app, callback, token) => { |
| | | app.MG.identity.getCurrentAppUser().then(res => { |
| | | MG.identity.getCurrentAppUser().then(res => { |
| | | // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认) |
| | | if (res) { |
| | | let defaultUser = {}; |
| | |
| | | defaultUser.phoneNumber = phoneNumber.credential |
| | | } |
| | | |
| | | wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); |
| | | wx.setStorageSync(config.userInfoKey, JSON.stringify(defaultUser)); |
| | | } |
| | | callback(token); |
| | | }); |