litian
2024-10-28 8d60f69402813488545502941785bf2d951e45bb
assets/js/login.js
@@ -2,9 +2,11 @@
  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",
    });
@@ -13,9 +15,9 @@
      success: (res) => {
        wx.getUserInfo({
          success: (infoRes) => {
            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 => {
@@ -42,22 +44,22 @@
              } 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()
                        //登录记录积分
                        app.MG.app.creatUserBehavior({
                        MG.app.creatUserBehavior({
                          refCode: "sign"
                        })
                      } else {
@@ -90,7 +92,7 @@
}
// 获取登录用户身份
const getUserInfo = (app, callback, token) => {
  app.MG.identity.getCurrentAppUser().then(res => {
  MG.identity.getCurrentAppUser().then(res => {
    // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认)
    if (res) {
      let defaultUser = {};
@@ -122,7 +124,7 @@
        defaultUser.phoneNumber = phoneNumber.credential
      }
      wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser));
      wx.setStorageSync(config.userInfoKey, JSON.stringify(defaultUser));
    }
    callback(token);
  });