wechat-mp-controller 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -2
- package/dist/utils.d.ts +2 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export class WeChatMpController {
|
|
|
8
8
|
return controller;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
const WAIT_TIMEOUT = 30 * 1000;
|
|
11
12
|
export class Controller {
|
|
12
13
|
_isLogin = false;
|
|
13
14
|
async init(options) {
|
|
@@ -18,6 +19,18 @@ export class Controller {
|
|
|
18
19
|
...options
|
|
19
20
|
});
|
|
20
21
|
this.page = await this.browser.newPage();
|
|
22
|
+
this.getLoginQrCodeTask = new Promise(resolve => {
|
|
23
|
+
const listener = res => {
|
|
24
|
+
if (res.url().includes('/scanloginqrcode?action=getqrcode')) {
|
|
25
|
+
resolve(res);
|
|
26
|
+
this.page?.off('response', listener);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
this.page?.on('response', listener);
|
|
30
|
+
setTimeout(() => {
|
|
31
|
+
this.page?.off('response', listener);
|
|
32
|
+
}, WAIT_TIMEOUT);
|
|
33
|
+
});
|
|
21
34
|
await this.page.goto(`https://mp.weixin.qq.com/`);
|
|
22
35
|
this._isLogin = await Promise.race([this.page.waitForSelector(`.login__type__container__scan__qrcode`).then(() => false), this.page.waitForSelector('#menuBar .menu').then(() => true)]);
|
|
23
36
|
return;
|
|
@@ -43,8 +56,8 @@ export class Controller {
|
|
|
43
56
|
break;
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
|
-
const
|
|
47
|
-
const buffer = await
|
|
59
|
+
const loginQrCodeRes = await this.getLoginQrCodeTask;
|
|
60
|
+
const buffer = await loginQrCodeRes.buffer();
|
|
48
61
|
const loginLink = await analyzeQrCodeImgBuffer(buffer);
|
|
49
62
|
let _qrcode = '';
|
|
50
63
|
await new Promise(resolve => {
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { Jimp } from 'jimp';
|
|
2
|
+
export declare const analyzeQrCodeImgBuffer: (buffer: Parameters<typeof Jimp.read>[0]) => Promise<string>;
|
|
2
3
|
export declare const wait: (duration: number) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wechat-mp-controller",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"author": "ArcherCube",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"jimp": "^1.6.0",
|
|
33
|
+
"node-fetch": "^3.3.2",
|
|
33
34
|
"puppeteer-core": "^24.22.0",
|
|
34
35
|
"qrcode-reader": "^1.0.4",
|
|
35
36
|
"qrcode-terminal": "^0.12.0"
|