diff --git a/Back/model/consts.ts b/Back/model/consts.ts index 75066c5..f2c8680 100644 --- a/Back/model/consts.ts +++ b/Back/model/consts.ts @@ -21,6 +21,7 @@ export const wxAppID = process.env.APPID as string; export const wxSECRET = process.env.WXSECRET as string; export const agentID = process.env.AGENTID as string; +export const ssoQRCodeURL = `https://sso.hustunique.com/qrcode/code`; export const getQRCodeURL = `https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=${wxAppID}&agentid=${agentID}&redirect_uri=https%3A%2F%2Fopen.hustunique.com%2Fauth&state=api`; export const scanningURL = "https://open.work.weixin.qq.com/wwopen/sso/l/qrConnect?key="; diff --git a/Back/model/user.ts b/Back/model/user.ts index 44d7afe..bb29958 100644 --- a/Back/model/user.ts +++ b/Back/model/user.ts @@ -1,6 +1,6 @@ import { prisma, User, UserCreateInput } from "../generated/prisma-client"; import fetch from "node-fetch"; -import { scanningURL, userIDURL, getQRCodeURL, pagesize } from "./consts"; +import { scanningURL, userIDURL, ssoQRCodeURL, pagesize } from "./consts"; import { Request, Response } from "express"; import { addSaltPasswordOnce, @@ -423,6 +423,9 @@ export const userScan = async function(req: Request, res: Response) { } else { res.json({ code: -1, msg: "登录失败!" }); } + } else if (status === "QRCODE_SCAN_NEVER") { + // Havn't scanned the qrcode + res.json({ code: -1, msg: "尚未扫码" }); } else { res.json({ code: -2, msg: "登录超时,请重新登录!" }); } @@ -433,9 +436,10 @@ export const userScan = async function(req: Request, res: Response) { export const userQRLogin = async function(_req: Request, res: Response) { try { - const response = await fetch(getQRCodeURL); - const html = await response.text(); - const key = html.match(/key ?: ?"\w+/)![0].replace(/key ?: ?"/, ""); + const response = await fetch(ssoQRCodeURL); + const data = JSON.parse(await response.text()); + const qrcodeSrc: string = data.serviceResponse.authenticationSuccess.qrcodeSrc; + const key = qrcodeSrc.match(/key=(\w+)/)![0].replace(/key=/, ""); res.json({ code: 1, msg: key }); } catch (err) { res.json({ code: -1, msg: err.message }); diff --git a/Front/package.json b/Front/package.json index af7f7e0..9bfb57b 100644 --- a/Front/package.json +++ b/Front/package.json @@ -18,7 +18,8 @@ "vue": "^2.6.5", "vue-codemirror": "^4.0.6", "vue-router": "^3.0.1", - "vuex": "^3.1.0" + "vuex": "^3.1.0", + "webpack-cli": "3" }, "devDependencies": { "autoprefixer": "^7.1.2", @@ -55,9 +56,12 @@ "vue-template-compiler": "^2.6.5", "webpack": "^3.6.0", "webpack-bundle-analyzer": "^3.3.2", - "webpack-dev-server": "^3.1.11", + "webpack-dev-server": "2.7.1", "webpack-merge": "^4.1.0" }, + "optionalDependencies": { + "fsevents": "*" + }, "engines": { "node": ">= 6.0.0", "npm": ">= 3.0.0" diff --git a/Front/src/web/user/userLoginWx.vue b/Front/src/web/user/userLoginWx.vue index 7871e94..8b513bd 100644 --- a/Front/src/web/user/userLoginWx.vue +++ b/Front/src/web/user/userLoginWx.vue @@ -30,6 +30,11 @@ export default { }; }, methods: { + async getStatusRaw() { + return await this.$ajax.get( + this.$urls.wxLoginGetStatus(this.key) + ); + }, async getKey() { const pageIntoTime = this.$store.state.wxGoPageTime; @@ -48,13 +53,15 @@ export default { this.key = key; this.keySrc = `https://open.work.weixin.qq.com/wwopen/sso/qrImg?key=${key}`; this.showLoading = false; - const statusRaw = await this.$ajax.get( - this.$urls.wxLoginGetStatus(this.key) - ); + let statusRaw = await this.getStatusRaw(); if (this.$store.state.wxGoPageTime !== pageIntoTime) { return; } - + while (statusRaw.data.code === -1) { + // like Sleep(500ms) + await new Promise(resolve => setTimeout(resolve, 500)); + statusRaw = await this.getStatusRaw(); + } if (statusRaw.data.code === 1) { const response = statusRaw.data; const token = response.msg.token; @@ -89,7 +96,7 @@ export default { }, beforeDestroy() { this.onPage = false; - } + }, };