Skip to content

Commit 000998d

Browse files
authored
Merge pull request #46 from werifu/master
fix the error of wxwork qrcode fetch
2 parents 343b027 + 132d1fb commit 000998d

File tree

5 files changed

+839
-348
lines changed

5 files changed

+839
-348
lines changed

Back/model/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const wxAppID = process.env.APPID as string;
2121
export const wxSECRET = process.env.WXSECRET as string;
2222
export const agentID = process.env.AGENTID as string;
2323

24+
export const ssoQRCodeURL = `https://sso.hustunique.com/qrcode/code`;
2425
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`;
2526
export const scanningURL =
2627
"https://open.work.weixin.qq.com/wwopen/sso/l/qrConnect?key=";

Back/model/user.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { prisma, User, UserCreateInput } from "../generated/prisma-client";
22
import fetch from "node-fetch";
3-
import { scanningURL, userIDURL, getQRCodeURL, pagesize } from "./consts";
3+
import { scanningURL, userIDURL, ssoQRCodeURL, pagesize } from "./consts";
44
import { Request, Response } from "express";
55
import {
66
addSaltPasswordOnce,
@@ -423,6 +423,9 @@ export const userScan = async function(req: Request, res: Response) {
423423
} else {
424424
res.json({ code: -1, msg: "登录失败!" });
425425
}
426+
} else if (status === "QRCODE_SCAN_NEVER") {
427+
// Havn't scanned the qrcode
428+
res.json({ code: -1, msg: "尚未扫码" });
426429
} else {
427430
res.json({ code: -2, msg: "登录超时,请重新登录!" });
428431
}
@@ -433,9 +436,10 @@ export const userScan = async function(req: Request, res: Response) {
433436

434437
export const userQRLogin = async function(_req: Request, res: Response) {
435438
try {
436-
const response = await fetch(getQRCodeURL);
437-
const html = await response.text();
438-
const key = html.match(/key ?: ?"\w+/)![0].replace(/key ?: ?"/, "");
439+
const response = await fetch(ssoQRCodeURL);
440+
const data = JSON.parse(await response.text());
441+
const qrcodeSrc: string = data.serviceResponse.authenticationSuccess.qrcodeSrc;
442+
const key = qrcodeSrc.match(/key=(\w+)/)![0].replace(/key=/, "");
439443
res.json({ code: 1, msg: key });
440444
} catch (err) {
441445
res.json({ code: -1, msg: err.message });

Front/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"vue": "^2.6.5",
1919
"vue-codemirror": "^4.0.6",
2020
"vue-router": "^3.0.1",
21-
"vuex": "^3.1.0"
21+
"vuex": "^3.1.0",
22+
"webpack-cli": "3"
2223
},
2324
"devDependencies": {
2425
"autoprefixer": "^7.1.2",
@@ -55,9 +56,12 @@
5556
"vue-template-compiler": "^2.6.5",
5657
"webpack": "^3.6.0",
5758
"webpack-bundle-analyzer": "^3.3.2",
58-
"webpack-dev-server": "^3.1.11",
59+
"webpack-dev-server": "2.7.1",
5960
"webpack-merge": "^4.1.0"
6061
},
62+
"optionalDependencies": {
63+
"fsevents": "*"
64+
},
6165
"engines": {
6266
"node": ">= 6.0.0",
6367
"npm": ">= 3.0.0"

Front/src/web/user/userLoginWx.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export default {
3030
};
3131
},
3232
methods: {
33+
async getStatusRaw() {
34+
return await this.$ajax.get(
35+
this.$urls.wxLoginGetStatus(this.key)
36+
);
37+
},
3338
async getKey() {
3439
const pageIntoTime = this.$store.state.wxGoPageTime;
3540
@@ -48,13 +53,15 @@ export default {
4853
this.key = key;
4954
this.keySrc = `https://open.work.weixin.qq.com/wwopen/sso/qrImg?key=${key}`;
5055
this.showLoading = false;
51-
const statusRaw = await this.$ajax.get(
52-
this.$urls.wxLoginGetStatus(this.key)
53-
);
56+
let statusRaw = await this.getStatusRaw();
5457
if (this.$store.state.wxGoPageTime !== pageIntoTime) {
5558
return;
5659
}
57-
60+
while (statusRaw.data.code === -1) {
61+
// like Sleep(500ms)
62+
await new Promise(resolve => setTimeout(resolve, 500));
63+
statusRaw = await this.getStatusRaw();
64+
}
5865
if (statusRaw.data.code === 1) {
5966
const response = statusRaw.data;
6067
const token = response.msg.token;
@@ -89,7 +96,7 @@ export default {
8996
},
9097
beforeDestroy() {
9198
this.onPage = false;
92-
}
99+
},
93100
};
94101
</script>
95102
<style scoped>

0 commit comments

Comments
 (0)