@adelie/wechat-miniprogram 0.0.0-stage → 0.5.0
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/LICENSE +201 -0
- package/icon.svg +7 -0
- package/package.json +17 -3
- package/plugin.json +9 -0
- package/skills/wechat-miniprogram/SKILL.md +148 -0
- package/skills/wechat-miniprogram/scripts/add-ip2.mjs +358 -0
- package/skills/wechat-miniprogram/scripts/auto-submit.mjs +170 -0
- package/skills/wechat-miniprogram/scripts/check-session.mjs +40 -0
- package/skills/wechat-miniprogram/scripts/login2.mjs +226 -0
- package/skills/wechat-miniprogram/scripts/miniapp-info.mjs +67 -0
- package/skills/wechat-miniprogram/scripts/miniapp-nav.mjs +56 -0
- package/skills/wechat-miniprogram/scripts/package.json +12 -0
- package/skills/wechat-miniprogram/scripts/privacy-fill2.mjs +302 -0
- package/skills/wechat-miniprogram/scripts/probe-key-qr.mjs +147 -0
- package/skills/wechat-miniprogram/scripts/probe-privacy.mjs +73 -0
- package/skills/wechat-miniprogram/scripts/probe-privcheck.mjs +129 -0
- package/skills/wechat-miniprogram/scripts/probe-switch3.mjs +104 -0
- package/skills/wechat-miniprogram/scripts/reset-key2.mjs +259 -0
- package/skills/wechat-miniprogram/scripts/stealth.mjs +92 -0
- package/skills/wechat-miniprogram/scripts/submit-review4.mjs +186 -0
- package/skills/wechat-miniprogram/scripts/to-miniapp.mjs +136 -0
- package/skills/wechat-miniprogram/scripts/withdraw2.mjs +229 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/README.md +46 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/app.js +14 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/app.json +12 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/app.wxss +13 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/package.json +14 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.js +33 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.json +4 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.wxml +24 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.wxss +49 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.js +145 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.json +4 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.wxml +55 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.wxss +173 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/preview.js +53 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/project.config.json +25 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/sitemap.json +9 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/tools/test-page.js +123 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/tools/validate.js +103 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/upload.js +49 -0
- package/README.md +0 -3
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// 编辑 IP 白名单:出管理员验证二维码 → 等扫码 → 在第二步填入 IP → 保存 → 复核
|
|
2
|
+
// 用法: node add-ip2.mjs <qrPrefix> <statusPath> <ip列表逗号分隔> [超时分钟]
|
|
3
|
+
import { launchStealth } from "./stealth.mjs";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import crypto from "node:crypto";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { PNG } from "pngjs";
|
|
9
|
+
import jsQR from "jsqr";
|
|
10
|
+
|
|
11
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const qrPrefix = process.argv[2];
|
|
13
|
+
const statusPath = process.argv[3];
|
|
14
|
+
const ips = (process.argv[4] || "")
|
|
15
|
+
.split(",")
|
|
16
|
+
.map((s) => s.trim())
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
const timeoutMin = Number(process.argv[5] || 20);
|
|
19
|
+
const outDir = path.dirname(qrPrefix);
|
|
20
|
+
const base = path.basename(qrPrefix).replace(/\.png$/, "");
|
|
21
|
+
const write = (o) =>
|
|
22
|
+
fs.writeFileSync(statusPath, JSON.stringify({ at: new Date().toISOString(), ...o }, null, 2));
|
|
23
|
+
const log = (...a) => console.log(new Date().toISOString(), ...a);
|
|
24
|
+
|
|
25
|
+
function upscale3x(png) {
|
|
26
|
+
const s = 3,
|
|
27
|
+
b = new PNG({ width: png.width * s, height: png.height * s });
|
|
28
|
+
for (let y = 0; y < b.height; y++)
|
|
29
|
+
for (let x = 0; x < b.width; x++) {
|
|
30
|
+
const si = (((y / s) | 0) * png.width + ((x / s) | 0)) << 2,
|
|
31
|
+
di = (y * b.width + x) << 2;
|
|
32
|
+
b.data[di] = png.data[si];
|
|
33
|
+
b.data[di + 1] = png.data[si + 1];
|
|
34
|
+
b.data[di + 2] = png.data[si + 2];
|
|
35
|
+
b.data[di + 3] = 255;
|
|
36
|
+
}
|
|
37
|
+
return b;
|
|
38
|
+
}
|
|
39
|
+
function deliverQr(pngBuf) {
|
|
40
|
+
const png = PNG.sync.read(pngBuf);
|
|
41
|
+
const big = upscale3x(png);
|
|
42
|
+
const dec = jsQR(new Uint8Array(big.data), big.width, big.height);
|
|
43
|
+
const hash = crypto
|
|
44
|
+
.createHash("sha1")
|
|
45
|
+
.update(dec ? dec.data : PNG.sync.write(big))
|
|
46
|
+
.digest("hex")
|
|
47
|
+
.slice(0, 8);
|
|
48
|
+
const file = path.join(outDir, `${base}-${hash}.png`);
|
|
49
|
+
if (!fs.existsSync(file)) {
|
|
50
|
+
fs.writeFileSync(file, PNG.sync.write(big));
|
|
51
|
+
const re = new RegExp(`^${base}-[0-9a-f]{8}\\.png$`);
|
|
52
|
+
for (const f of fs.readdirSync(outDir))
|
|
53
|
+
if (re.test(f) && path.join(outDir, f) !== file) {
|
|
54
|
+
try {
|
|
55
|
+
fs.unlinkSync(path.join(outDir, f));
|
|
56
|
+
} catch {}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
file,
|
|
61
|
+
hash,
|
|
62
|
+
size: `${big.width}x${big.height}`,
|
|
63
|
+
decoded: dec ? dec.data.slice(0, 100) : null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
|
|
68
|
+
const page = ctx.pages()[0] || (await ctx.newPage());
|
|
69
|
+
await page.goto("https://mp.weixin.qq.com/", { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
70
|
+
await page.waitForTimeout(10000);
|
|
71
|
+
const token = (page.url().match(/token=(\d+)/) || [])[1];
|
|
72
|
+
if (!token) {
|
|
73
|
+
write({ state: "NOT_LOGGED_IN" });
|
|
74
|
+
log("NOT LOGGED IN");
|
|
75
|
+
await ctx.close().catch(() => {});
|
|
76
|
+
process.exit(2);
|
|
77
|
+
}
|
|
78
|
+
await page
|
|
79
|
+
.goto(`https://mp.weixin.qq.com/wxamp/devprofile/get_profile?token=${token}&lang=zh_CN`, {
|
|
80
|
+
waitUntil: "commit",
|
|
81
|
+
timeout: 60000,
|
|
82
|
+
})
|
|
83
|
+
.catch(() => {});
|
|
84
|
+
await page.waitForTimeout(12000);
|
|
85
|
+
|
|
86
|
+
const dlgText = () =>
|
|
87
|
+
page.evaluate(() => {
|
|
88
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
89
|
+
(e) => e.offsetWidth > 200 && e.offsetHeight > 150,
|
|
90
|
+
);
|
|
91
|
+
return ds
|
|
92
|
+
.map((e) => (e.innerText || "").replace(/\s+/g, " ").trim())
|
|
93
|
+
.filter(Boolean)
|
|
94
|
+
.join(" || ")
|
|
95
|
+
.slice(0, 500);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const openDialog = async () => {
|
|
99
|
+
const btn = await page.evaluate(() => {
|
|
100
|
+
const label = Array.from(document.querySelectorAll("*")).find(
|
|
101
|
+
(e) => e.children.length === 0 && (e.innerText || "").trim() === "IP白名单",
|
|
102
|
+
);
|
|
103
|
+
let n = label;
|
|
104
|
+
for (let i = 0; i < 8 && n; i++) {
|
|
105
|
+
n = n.parentElement;
|
|
106
|
+
if (!n) break;
|
|
107
|
+
const c = Array.from(n.querySelectorAll("a,button,span,div")).filter(
|
|
108
|
+
(e) => e.children.length === 0 && (e.innerText || "").trim() === "编辑",
|
|
109
|
+
);
|
|
110
|
+
if (c[0]) {
|
|
111
|
+
const r = c[0].getBoundingClientRect();
|
|
112
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
});
|
|
117
|
+
if (!btn) return false;
|
|
118
|
+
await page.mouse.click(btn.x, btn.y);
|
|
119
|
+
await page.waitForTimeout(4000);
|
|
120
|
+
return true;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const grabQr = async () => {
|
|
124
|
+
const el = await page.evaluateHandle(() => {
|
|
125
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
126
|
+
(e) => e.offsetWidth > 200 && e.offsetHeight > 150,
|
|
127
|
+
);
|
|
128
|
+
for (const d of ds)
|
|
129
|
+
for (const img of d.querySelectorAll("img")) {
|
|
130
|
+
const r = img.getBoundingClientRect();
|
|
131
|
+
if (r.width > 120) return img;
|
|
132
|
+
}
|
|
133
|
+
for (const d of ds)
|
|
134
|
+
for (const cv of d.querySelectorAll("canvas")) {
|
|
135
|
+
const r = cv.getBoundingClientRect();
|
|
136
|
+
if (r.width > 120) return cv;
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
});
|
|
140
|
+
const node = el.asElement();
|
|
141
|
+
if (!node) return null;
|
|
142
|
+
const buf = await node.screenshot().catch(() => null);
|
|
143
|
+
return buf ? deliverQr(buf) : null;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
if (!(await openDialog())) {
|
|
147
|
+
write({ state: "NO_EDIT_BTN" });
|
|
148
|
+
log("no edit btn");
|
|
149
|
+
await ctx.close().catch(() => {});
|
|
150
|
+
process.exit(3);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let t = await dlgText();
|
|
154
|
+
log("dialog:", t);
|
|
155
|
+
let qrInfo = null,
|
|
156
|
+
lastQrAt = 0;
|
|
157
|
+
const deadline = Date.now() + timeoutMin * 60 * 1000;
|
|
158
|
+
let scanned = false;
|
|
159
|
+
|
|
160
|
+
let tick = 0;
|
|
161
|
+
while (Date.now() < deadline && !scanned) {
|
|
162
|
+
t = await dlgText();
|
|
163
|
+
tick++;
|
|
164
|
+
if (tick % 8 === 0) {
|
|
165
|
+
log("tick dialog:", t.slice(0, 220));
|
|
166
|
+
await page.screenshot({ path: path.join(outDir, `${base}-live.png`) }).catch(() => {});
|
|
167
|
+
}
|
|
168
|
+
// 注意:进到第二步后步骤条里仍然有「身份确认」字样,不能拿它判断;只看"请扫码/请在手机上确认"是否消失
|
|
169
|
+
if (!/请使用管理员微信扫描|请在手机上进行确认/.test(t)) {
|
|
170
|
+
scanned = true;
|
|
171
|
+
log("STEP_READY:", t.slice(0, 160));
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
if (/失效|过期|刷新|重新获取/.test(t)) {
|
|
175
|
+
const r = await page
|
|
176
|
+
.evaluate(() => {
|
|
177
|
+
const ds = Array.from(
|
|
178
|
+
document.querySelectorAll('[class*="dialog"],[class*="modal"]'),
|
|
179
|
+
).filter((e) => e.offsetWidth > 200);
|
|
180
|
+
for (const d of ds)
|
|
181
|
+
for (const e of d.querySelectorAll("a,button,span,div")) {
|
|
182
|
+
if (e.children.length === 0 && /刷新|重新获取/.test((e.innerText || "").trim())) {
|
|
183
|
+
const r = e.getBoundingClientRect();
|
|
184
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
})
|
|
189
|
+
.catch(() => null);
|
|
190
|
+
if (r) {
|
|
191
|
+
await page.mouse.click(r.x, r.y);
|
|
192
|
+
await page.waitForTimeout(3000);
|
|
193
|
+
}
|
|
194
|
+
qrInfo = null;
|
|
195
|
+
lastQrAt = 0;
|
|
196
|
+
}
|
|
197
|
+
if (!qrInfo || Date.now() - lastQrAt > 15000) {
|
|
198
|
+
const info = await grabQr();
|
|
199
|
+
if (info) {
|
|
200
|
+
const changed = !qrInfo || info.decoded !== qrInfo.decoded;
|
|
201
|
+
qrInfo = info;
|
|
202
|
+
lastQrAt = Date.now();
|
|
203
|
+
if (changed) {
|
|
204
|
+
log(
|
|
205
|
+
"QR_READY",
|
|
206
|
+
path.basename(info.file),
|
|
207
|
+
info.size,
|
|
208
|
+
info.decoded ? "decoded-ok" : "UNREADABLE",
|
|
209
|
+
);
|
|
210
|
+
write({ state: "WAIT_SCAN", ...info, dialog: t });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
await page.waitForTimeout(2000);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!scanned) {
|
|
218
|
+
write({ state: "TIMEOUT" });
|
|
219
|
+
log("TIMEOUT");
|
|
220
|
+
await ctx.close().catch(() => {});
|
|
221
|
+
process.exit(4);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
await page.waitForTimeout(4000);
|
|
225
|
+
t = await dlgText();
|
|
226
|
+
log("step2 dialog:", t);
|
|
227
|
+
write({ state: "STEP2", dialog: t });
|
|
228
|
+
await page.screenshot({ path: path.join(outDir, `${base}-step2.png`) }).catch(() => {});
|
|
229
|
+
|
|
230
|
+
const step2 = await page.evaluate(() => {
|
|
231
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
232
|
+
(e) => e.offsetWidth > 200 && e.offsetHeight > 150,
|
|
233
|
+
);
|
|
234
|
+
const out = { inputs: [], btns: [] };
|
|
235
|
+
for (const d of ds) {
|
|
236
|
+
for (const i of d.querySelectorAll("input,textarea")) {
|
|
237
|
+
const r = i.getBoundingClientRect();
|
|
238
|
+
if (r.width)
|
|
239
|
+
out.inputs.push({
|
|
240
|
+
tag: i.tagName,
|
|
241
|
+
ph: i.placeholder || "",
|
|
242
|
+
val: i.value || "",
|
|
243
|
+
rect: `${Math.round(r.x)},${Math.round(r.y)}`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
for (const b of d.querySelectorAll("button,a,span,div")) {
|
|
247
|
+
if (b.children.length === 0) {
|
|
248
|
+
const tx = (b.innerText || "").trim();
|
|
249
|
+
if (tx && tx.length <= 10) {
|
|
250
|
+
const r = b.getBoundingClientRect();
|
|
251
|
+
if (r.width) out.btns.push({ t: tx, rect: `${Math.round(r.x)},${Math.round(r.y)}` });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
});
|
|
258
|
+
log("step2 struct", JSON.stringify(step2));
|
|
259
|
+
|
|
260
|
+
// 若没有输入框,先点「添加」
|
|
261
|
+
if (step2.inputs.length === 0) {
|
|
262
|
+
const add = await page.evaluate(() => {
|
|
263
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
264
|
+
(e) => e.offsetWidth > 200,
|
|
265
|
+
);
|
|
266
|
+
for (const d of ds)
|
|
267
|
+
for (const e of d.querySelectorAll("a,button,span,div")) {
|
|
268
|
+
if (
|
|
269
|
+
e.children.length === 0 &&
|
|
270
|
+
/^(添加|新增|添加IP|新建)$/.test((e.innerText || "").trim())
|
|
271
|
+
) {
|
|
272
|
+
const r = e.getBoundingClientRect();
|
|
273
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
});
|
|
278
|
+
if (add) {
|
|
279
|
+
await page.mouse.click(add.x, add.y);
|
|
280
|
+
await page.waitForTimeout(2500);
|
|
281
|
+
log("clicked 添加");
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 填入 IP(多行/多框都支持)
|
|
286
|
+
const setVals = await page.evaluate((list) => {
|
|
287
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
288
|
+
(e) => e.offsetWidth > 200,
|
|
289
|
+
);
|
|
290
|
+
const boxes = [];
|
|
291
|
+
for (const d of ds)
|
|
292
|
+
for (const i of d.querySelectorAll("input,textarea"))
|
|
293
|
+
if (i.getBoundingClientRect().width) boxes.push(i);
|
|
294
|
+
if (!boxes.length) return 0;
|
|
295
|
+
if (boxes.length === 1) {
|
|
296
|
+
const i = boxes[0];
|
|
297
|
+
i.focus();
|
|
298
|
+
i.value = list.join("\n");
|
|
299
|
+
i.dispatchEvent(new Event("input", { bubbles: true }));
|
|
300
|
+
i.dispatchEvent(new Event("change", { bubbles: true }));
|
|
301
|
+
return 1;
|
|
302
|
+
}
|
|
303
|
+
list.forEach((v, k) => {
|
|
304
|
+
const i = boxes[k];
|
|
305
|
+
if (!i) return;
|
|
306
|
+
i.focus();
|
|
307
|
+
i.value = v;
|
|
308
|
+
i.dispatchEvent(new Event("input", { bubbles: true }));
|
|
309
|
+
i.dispatchEvent(new Event("change", { bubbles: true }));
|
|
310
|
+
});
|
|
311
|
+
return boxes.length;
|
|
312
|
+
}, ips);
|
|
313
|
+
log("setVals boxes", setVals, JSON.stringify(ips));
|
|
314
|
+
await page.waitForTimeout(1500);
|
|
315
|
+
await page.screenshot({ path: path.join(outDir, `${base}-filled.png`) }).catch(() => {});
|
|
316
|
+
|
|
317
|
+
const save = await page.evaluate(() => {
|
|
318
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
319
|
+
(e) => e.offsetWidth > 200,
|
|
320
|
+
);
|
|
321
|
+
for (const d of ds)
|
|
322
|
+
for (const e of d.querySelectorAll("button,a,span,div")) {
|
|
323
|
+
if (
|
|
324
|
+
e.children.length === 0 &&
|
|
325
|
+
/^(保存|确定|确认|提交|完成)$/.test((e.innerText || "").trim())
|
|
326
|
+
) {
|
|
327
|
+
const r = e.getBoundingClientRect();
|
|
328
|
+
if (r.width)
|
|
329
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2, t: (e.innerText || "").trim() };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return null;
|
|
333
|
+
});
|
|
334
|
+
log("save btn", JSON.stringify(save));
|
|
335
|
+
if (save) {
|
|
336
|
+
await page.mouse.click(save.x, save.y);
|
|
337
|
+
await page.waitForTimeout(5000);
|
|
338
|
+
}
|
|
339
|
+
await page.screenshot({ path: path.join(outDir, `${base}-saved.png`) }).catch(() => {});
|
|
340
|
+
log("after save dialog:", await dlgText());
|
|
341
|
+
|
|
342
|
+
// 复核:重新打开开发设置页
|
|
343
|
+
await page
|
|
344
|
+
.goto(`https://mp.weixin.qq.com/wxamp/devprofile/get_profile?token=${token}&lang=zh_CN`, {
|
|
345
|
+
waitUntil: "commit",
|
|
346
|
+
timeout: 60000,
|
|
347
|
+
})
|
|
348
|
+
.catch(() => {});
|
|
349
|
+
await page.waitForTimeout(12000);
|
|
350
|
+
const verify = await page.evaluate(() => {
|
|
351
|
+
const t = (document.body.innerText || "").replace(/\s+/g, " ");
|
|
352
|
+
const i = t.indexOf("IP白名单");
|
|
353
|
+
return t.slice(i, i + 120);
|
|
354
|
+
});
|
|
355
|
+
log("VERIFY:", verify);
|
|
356
|
+
write({ state: "DONE", saved: !!save, ips, verify });
|
|
357
|
+
await ctx.close().catch(() => {});
|
|
358
|
+
process.exit(0);
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// 自动检查:隐私指引审核状态 + 代码是否已提交审核;隐私指引通过后自动重试提交代码审核
|
|
2
|
+
// 用法: node auto-submit.mjs [关键词] [状态文件]
|
|
3
|
+
import { launchStealth } from "./stealth.mjs";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const keyword = process.argv[2] || "待办清单";
|
|
10
|
+
const statusPath = process.argv[3] || path.join(here, "auto-submit-status.json");
|
|
11
|
+
const log = (...a) => console.log(new Date().toISOString(), ...a);
|
|
12
|
+
const out = { at: new Date().toISOString() };
|
|
13
|
+
|
|
14
|
+
const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
|
|
15
|
+
const page = ctx.pages()[0] || (await ctx.newPage());
|
|
16
|
+
await page
|
|
17
|
+
.goto("https://mp.weixin.qq.com/", { waitUntil: "commit", timeout: 60000 })
|
|
18
|
+
.catch(() => {});
|
|
19
|
+
await page.waitForTimeout(15000);
|
|
20
|
+
const token = (page.url().match(/token=(\d+)/) || [])[1];
|
|
21
|
+
if (!token) {
|
|
22
|
+
out.state = "NOT_LOGGED_IN";
|
|
23
|
+
fs.writeFileSync(statusPath, JSON.stringify(out, null, 2));
|
|
24
|
+
log("NOT LOGGED IN");
|
|
25
|
+
await ctx.close().catch(() => {});
|
|
26
|
+
process.exit(2);
|
|
27
|
+
}
|
|
28
|
+
const txt = () => page.evaluate(() => (document.body.innerText || "").replace(/\s+/g, " "));
|
|
29
|
+
|
|
30
|
+
// 1) 隐私指引状态
|
|
31
|
+
await page
|
|
32
|
+
.goto(`https://mp.weixin.qq.com/wxamp/basicprofile/index?token=${token}&lang=zh_CN`, {
|
|
33
|
+
waitUntil: "commit",
|
|
34
|
+
timeout: 60000,
|
|
35
|
+
})
|
|
36
|
+
.catch(() => {});
|
|
37
|
+
await page.waitForTimeout(16000);
|
|
38
|
+
const basic = await txt();
|
|
39
|
+
const pi = basic.indexOf("用户隐私保护指引");
|
|
40
|
+
out.privacyLine = basic.slice(pi, pi + 60);
|
|
41
|
+
out.privacyOk =
|
|
42
|
+
/审核通过|已更新|已通过/.test(basic.slice(pi, pi + 30)) ||
|
|
43
|
+
!/未更新|审核中|未通过|审核不通过/.test(basic.slice(pi, pi + 30));
|
|
44
|
+
log("隐私指引:", out.privacyLine);
|
|
45
|
+
|
|
46
|
+
// 2) 版本管理状态
|
|
47
|
+
await page
|
|
48
|
+
.goto(`https://mp.weixin.qq.com/wxamp/wacodepage/getcodepage?token=${token}&lang=zh_CN`, {
|
|
49
|
+
waitUntil: "commit",
|
|
50
|
+
timeout: 60000,
|
|
51
|
+
})
|
|
52
|
+
.catch(() => {});
|
|
53
|
+
await page.waitForTimeout(16000);
|
|
54
|
+
const ver = await txt();
|
|
55
|
+
const hasReview = /审核版本\s*版本号/.test(ver);
|
|
56
|
+
out.hasReviewVersion = hasReview;
|
|
57
|
+
out.versionsLine = ver.slice(ver.indexOf("线上版本"), ver.indexOf("线上版本") + 420);
|
|
58
|
+
log("版本:", out.versionsLine);
|
|
59
|
+
log("已有审核版本:", hasReview);
|
|
60
|
+
|
|
61
|
+
function summarize(reason) {
|
|
62
|
+
out.state = reason;
|
|
63
|
+
fs.writeFileSync(statusPath, JSON.stringify(out, null, 2));
|
|
64
|
+
log("STATE", reason);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (hasReview) {
|
|
68
|
+
summarize("ALREADY_IN_REVIEW");
|
|
69
|
+
await ctx.close().catch(() => {});
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}
|
|
72
|
+
if (!out.privacyOk) {
|
|
73
|
+
summarize("WAITING_PRIVACY");
|
|
74
|
+
await ctx.close().catch(() => {});
|
|
75
|
+
process.exit(0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 3) 隐私通过且无审核版本 → 提交代码审核
|
|
79
|
+
const findBtn = () =>
|
|
80
|
+
page.evaluate((kw) => {
|
|
81
|
+
const marker = Array.from(document.querySelectorAll("*")).find(
|
|
82
|
+
(e) => e.children.length === 0 && (e.innerText || "").includes(kw),
|
|
83
|
+
);
|
|
84
|
+
const btns = Array.from(document.querySelectorAll("button,a")).filter(
|
|
85
|
+
(e) => e.offsetWidth && (e.innerText || "").trim() === "提交审核",
|
|
86
|
+
);
|
|
87
|
+
if (!btns.length) return null;
|
|
88
|
+
const my = marker ? marker.getBoundingClientRect().y : 0;
|
|
89
|
+
const chosen = btns
|
|
90
|
+
.map((b) => ({ b, y: b.getBoundingClientRect().y }))
|
|
91
|
+
.filter((o) => o.y > my - 40)
|
|
92
|
+
.sort((a, b) => a.y - b.y)[0];
|
|
93
|
+
const b = chosen ? chosen.b : btns[0];
|
|
94
|
+
b.scrollIntoView({ block: "center" });
|
|
95
|
+
const r = b.getBoundingClientRect();
|
|
96
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
97
|
+
}, keyword);
|
|
98
|
+
|
|
99
|
+
let opened = false;
|
|
100
|
+
for (let i = 0; i < 3 && !opened; i++) {
|
|
101
|
+
const p = await findBtn();
|
|
102
|
+
if (!p) break;
|
|
103
|
+
await page.mouse.click(p.x, p.y);
|
|
104
|
+
for (let w = 0; w < 12; w++) {
|
|
105
|
+
await page.waitForTimeout(1000);
|
|
106
|
+
if (/确认提交审核/.test(await txt())) {
|
|
107
|
+
opened = true;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!opened) {
|
|
113
|
+
summarize("SUBMIT_BTN_FAILED");
|
|
114
|
+
await ctx.close().catch(() => {});
|
|
115
|
+
process.exit(4);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (const t of ["已仔细阅读", "已阅读并了解平台审核规则"]) {
|
|
119
|
+
const c = await page.evaluate((t) => {
|
|
120
|
+
const el = Array.from(document.querySelectorAll("label,span,div,p"))
|
|
121
|
+
.filter(
|
|
122
|
+
(e) => e.offsetWidth && (e.innerText || "").includes(t) && (e.innerText || "").length < 120,
|
|
123
|
+
)
|
|
124
|
+
.pop();
|
|
125
|
+
if (!el) return null;
|
|
126
|
+
const r = el.getBoundingClientRect();
|
|
127
|
+
return { x: r.x + 12, y: r.y + r.height / 2 };
|
|
128
|
+
}, t);
|
|
129
|
+
if (c) {
|
|
130
|
+
await page.mouse.click(c.x, c.y);
|
|
131
|
+
await page.waitForTimeout(700);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const clickText = async (label) => {
|
|
135
|
+
const p = await page.evaluate((label) => {
|
|
136
|
+
const els = Array.from(document.querySelectorAll("button,a,span,div")).filter(
|
|
137
|
+
(e) => e.offsetWidth && e.children.length === 0 && (e.innerText || "").trim() === label,
|
|
138
|
+
);
|
|
139
|
+
if (!els.length) return null;
|
|
140
|
+
els[els.length - 1].scrollIntoView({ block: "center" });
|
|
141
|
+
const r = els[els.length - 1].getBoundingClientRect();
|
|
142
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
143
|
+
}, label);
|
|
144
|
+
if (!p) return false;
|
|
145
|
+
await page.mouse.click(p.x, p.y);
|
|
146
|
+
await page.waitForTimeout(4500);
|
|
147
|
+
log("clicked", label);
|
|
148
|
+
return true;
|
|
149
|
+
};
|
|
150
|
+
await clickText("下一步");
|
|
151
|
+
await clickText("继续提交");
|
|
152
|
+
await page.waitForTimeout(12000);
|
|
153
|
+
await page
|
|
154
|
+
.screenshot({ path: path.join(here, "auto-submit-final.png"), fullPage: true })
|
|
155
|
+
.catch(() => {});
|
|
156
|
+
|
|
157
|
+
// 复核是否进了审核
|
|
158
|
+
await page
|
|
159
|
+
.goto(`https://mp.weixin.qq.com/wxamp/wacodepage/getcodepage?token=${token}&lang=zh_CN`, {
|
|
160
|
+
waitUntil: "commit",
|
|
161
|
+
timeout: 60000,
|
|
162
|
+
})
|
|
163
|
+
.catch(() => {});
|
|
164
|
+
await page.waitForTimeout(15000);
|
|
165
|
+
const ver2 = await txt();
|
|
166
|
+
out.versionsAfter = ver2.slice(ver2.indexOf("线上版本"), ver2.indexOf("线上版本") + 420);
|
|
167
|
+
out.submitted = /审核版本\s*版本号/.test(ver2);
|
|
168
|
+
summarize(out.submitted ? "SUBMITTED" : "SUBMIT_NO_EFFECT");
|
|
169
|
+
await ctx.close().catch(() => {});
|
|
170
|
+
process.exit(0);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// 复用已持久化的 profile 验证登录态是否还在,并回报账号信息
|
|
2
|
+
import { launchStealth } from "./stealth.mjs";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const shot = process.argv[2] || path.join(here, "home.png");
|
|
9
|
+
const infoOut = process.argv[3] || path.join(here, "session-check.json");
|
|
10
|
+
|
|
11
|
+
const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
|
|
12
|
+
const page = ctx.pages()[0] || (await ctx.newPage());
|
|
13
|
+
await page.goto("https://mp.weixin.qq.com/", { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
14
|
+
await page.waitForTimeout(7000);
|
|
15
|
+
|
|
16
|
+
const info = await page.evaluate(() => {
|
|
17
|
+
const t = (s) => {
|
|
18
|
+
const e = document.querySelector(s);
|
|
19
|
+
return e ? (e.innerText || "").trim().slice(0, 60) : null;
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
title: document.title,
|
|
23
|
+
nickname:
|
|
24
|
+
t(".weui-desktop-account__nickname") || t(".account__nickname") || t('[class*="nickname"]'),
|
|
25
|
+
menus: Array.from(document.querySelectorAll(".weui-desktop-menu__link, .weui-desktop-menu a"))
|
|
26
|
+
.map((e) => (e.innerText || "").trim())
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.slice(0, 30),
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
await page.screenshot({ path: shot }).catch(() => {});
|
|
32
|
+
const out = {
|
|
33
|
+
url: page.url(),
|
|
34
|
+
loggedIn: page.url().includes("/cgi-bin/home") || page.url().includes("token="),
|
|
35
|
+
...info,
|
|
36
|
+
shot,
|
|
37
|
+
};
|
|
38
|
+
fs.writeFileSync(infoOut, JSON.stringify(out, null, 2));
|
|
39
|
+
console.log(JSON.stringify(out, null, 2));
|
|
40
|
+
await ctx.close();
|