Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Back/model/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=";
Expand Down
12 changes: 8 additions & 4 deletions Back/model/user.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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: "登录超时,请重新登录!" });
}
Expand All @@ -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 });
Expand Down
8 changes: 6 additions & 2 deletions Front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 12 additions & 5 deletions Front/src/web/user/userLoginWx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -89,7 +96,7 @@ export default {
},
beforeDestroy() {
this.onPage = false;
}
},
};
</script>
<style scoped>
Expand Down
Loading