@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.
Files changed (42) hide show
  1. package/LICENSE +201 -0
  2. package/icon.svg +7 -0
  3. package/package.json +17 -3
  4. package/plugin.json +9 -0
  5. package/skills/wechat-miniprogram/SKILL.md +148 -0
  6. package/skills/wechat-miniprogram/scripts/add-ip2.mjs +358 -0
  7. package/skills/wechat-miniprogram/scripts/auto-submit.mjs +170 -0
  8. package/skills/wechat-miniprogram/scripts/check-session.mjs +40 -0
  9. package/skills/wechat-miniprogram/scripts/login2.mjs +226 -0
  10. package/skills/wechat-miniprogram/scripts/miniapp-info.mjs +67 -0
  11. package/skills/wechat-miniprogram/scripts/miniapp-nav.mjs +56 -0
  12. package/skills/wechat-miniprogram/scripts/package.json +12 -0
  13. package/skills/wechat-miniprogram/scripts/privacy-fill2.mjs +302 -0
  14. package/skills/wechat-miniprogram/scripts/probe-key-qr.mjs +147 -0
  15. package/skills/wechat-miniprogram/scripts/probe-privacy.mjs +73 -0
  16. package/skills/wechat-miniprogram/scripts/probe-privcheck.mjs +129 -0
  17. package/skills/wechat-miniprogram/scripts/probe-switch3.mjs +104 -0
  18. package/skills/wechat-miniprogram/scripts/reset-key2.mjs +259 -0
  19. package/skills/wechat-miniprogram/scripts/stealth.mjs +92 -0
  20. package/skills/wechat-miniprogram/scripts/submit-review4.mjs +186 -0
  21. package/skills/wechat-miniprogram/scripts/to-miniapp.mjs +136 -0
  22. package/skills/wechat-miniprogram/scripts/withdraw2.mjs +229 -0
  23. package/skills/wechat-miniprogram/templates/miniprogram-todo/README.md +46 -0
  24. package/skills/wechat-miniprogram/templates/miniprogram-todo/app.js +14 -0
  25. package/skills/wechat-miniprogram/templates/miniprogram-todo/app.json +12 -0
  26. package/skills/wechat-miniprogram/templates/miniprogram-todo/app.wxss +13 -0
  27. package/skills/wechat-miniprogram/templates/miniprogram-todo/package.json +14 -0
  28. package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.js +33 -0
  29. package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.json +4 -0
  30. package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.wxml +24 -0
  31. package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.wxss +49 -0
  32. package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.js +145 -0
  33. package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.json +4 -0
  34. package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.wxml +55 -0
  35. package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.wxss +173 -0
  36. package/skills/wechat-miniprogram/templates/miniprogram-todo/preview.js +53 -0
  37. package/skills/wechat-miniprogram/templates/miniprogram-todo/project.config.json +25 -0
  38. package/skills/wechat-miniprogram/templates/miniprogram-todo/sitemap.json +9 -0
  39. package/skills/wechat-miniprogram/templates/miniprogram-todo/tools/test-page.js +123 -0
  40. package/skills/wechat-miniprogram/templates/miniprogram-todo/tools/validate.js +103 -0
  41. package/skills/wechat-miniprogram/templates/miniprogram-todo/upload.js +49 -0
  42. package/README.md +0 -3
@@ -0,0 +1,259 @@
1
+ // 重置「小程序代码上传密钥」:出管理员验证二维码 → 等用户扫码 → 等密钥下载落盘
2
+ // 用法: node reset-key2.mjs <qrOutPrefix> <statusPath> <keyOutPath> [超时分钟]
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] || path.join(here, "key-qr.png");
13
+ const statusPath = process.argv[3] || path.join(here, "reset-key-status.json");
14
+ const keyOut = process.argv[4] || path.join(here, "mp-upload-key.key");
15
+ const timeoutMin = Number(process.argv[5] || 12);
16
+ const outDir = path.dirname(qrPrefix);
17
+ const base = path.basename(qrPrefix).replace(/\.png$/, "");
18
+ const write = (o) =>
19
+ fs.writeFileSync(statusPath, JSON.stringify({ at: new Date().toISOString(), ...o }, null, 2));
20
+ const log = (...a) => console.log(new Date().toISOString(), ...a);
21
+
22
+ function upscale3x(png) {
23
+ const s = 3;
24
+ const b = new PNG({ width: png.width * s, height: png.height * s });
25
+ for (let y = 0; y < b.height; y++)
26
+ for (let x = 0; x < b.width; x++) {
27
+ const si = (((y / s) | 0) * png.width + ((x / s) | 0)) << 2,
28
+ di = (y * b.width + x) << 2;
29
+ b.data[di] = png.data[si];
30
+ b.data[di + 1] = png.data[si + 1];
31
+ b.data[di + 2] = png.data[si + 2];
32
+ b.data[di + 3] = 255;
33
+ }
34
+ return b;
35
+ }
36
+
37
+ function deliverQr(pngBuf) {
38
+ const png = PNG.sync.read(pngBuf);
39
+ const big = upscale3x(png);
40
+ const buf = PNG.sync.write(big);
41
+ const dec = jsQR(new Uint8Array(big.data), big.width, big.height);
42
+ // 用「解码内容」做 hash:同一张码反复截图得到同一个文件名,不会把用户手上的文件删掉
43
+ const hash = crypto
44
+ .createHash("sha1")
45
+ .update(dec ? dec.data : buf)
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, buf);
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
+ let downloaded = null;
70
+ page.on("download", async (d) => {
71
+ try {
72
+ await d.saveAs(keyOut);
73
+ downloaded = keyOut;
74
+ log("DOWNLOAD saved", keyOut, fs.statSync(keyOut).size);
75
+ write({ state: "KEY_DOWNLOADED", keyOut });
76
+ } catch (e) {
77
+ log("download err", e.message);
78
+ }
79
+ });
80
+
81
+ await page.goto("https://mp.weixin.qq.com/", { waitUntil: "domcontentloaded", timeout: 60000 });
82
+ await page.waitForTimeout(10000);
83
+ const token = (page.url().match(/token=(\d+)/) || [])[1];
84
+ if (!token) {
85
+ write({ state: "NOT_LOGGED_IN" });
86
+ log("NOT LOGGED IN");
87
+ await ctx.close().catch(() => {});
88
+ process.exit(2);
89
+ }
90
+ await page.goto(`https://mp.weixin.qq.com/wxamp/devprofile/get_profile?token=${token}&lang=zh_CN`, {
91
+ waitUntil: "domcontentloaded",
92
+ timeout: 60000,
93
+ });
94
+ await page.waitForTimeout(9000);
95
+
96
+ const clickReset = async () => {
97
+ const btn = await page.evaluate(() => {
98
+ const label = Array.from(document.querySelectorAll("*")).find(
99
+ (e) => e.children.length === 0 && (e.innerText || "").trim() === "小程序代码上传密钥",
100
+ );
101
+ let n = label;
102
+ for (let i = 0; i < 8 && n; i++) {
103
+ n = n.parentElement;
104
+ if (!n) break;
105
+ const c = Array.from(n.querySelectorAll("a,button,span,div")).filter(
106
+ (e) => e.children.length === 0 && (e.innerText || "").trim() === "重置",
107
+ );
108
+ if (c[0]) {
109
+ const r = c[0].getBoundingClientRect();
110
+ return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
111
+ }
112
+ }
113
+ return null;
114
+ });
115
+ if (!btn) return false;
116
+ await page.mouse.click(btn.x, btn.y);
117
+ await page.waitForTimeout(4000);
118
+ return true;
119
+ };
120
+
121
+ const dlgText = () =>
122
+ page.evaluate(() => {
123
+ const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
124
+ (e) => e.offsetWidth > 200 && e.offsetHeight > 150,
125
+ );
126
+ return ds
127
+ .map((e) => (e.innerText || "").replace(/\s+/g, " ").trim())
128
+ .filter(Boolean)
129
+ .join(" || ")
130
+ .slice(0, 400);
131
+ });
132
+
133
+ if (!(await clickReset())) {
134
+ write({ state: "NO_RESET_BTN" });
135
+ log("no reset btn");
136
+ await ctx.close().catch(() => {});
137
+ process.exit(3);
138
+ }
139
+
140
+ const grabQr = async () => {
141
+ // 1) 可见 dialog 内的 img
142
+ const el = await page.evaluateHandle(() => {
143
+ const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
144
+ (e) => e.offsetWidth > 200 && e.offsetHeight > 150,
145
+ );
146
+ for (const d of ds)
147
+ for (const img of d.querySelectorAll("img")) {
148
+ const r = img.getBoundingClientRect();
149
+ if (r.width > 120 && r.height > 120) return img;
150
+ }
151
+ for (const d of ds)
152
+ for (const cv of d.querySelectorAll("canvas")) {
153
+ const r = cv.getBoundingClientRect();
154
+ if (r.width > 120 && r.height > 120) return cv;
155
+ }
156
+ return null;
157
+ });
158
+ const node = el.asElement();
159
+ if (!node) return null;
160
+ const buf = await node.screenshot().catch(() => null);
161
+ if (!buf) return null;
162
+ return deliverQr(buf);
163
+ };
164
+
165
+ let lastText = "";
166
+ let qrInfo = null;
167
+ const deadline = Date.now() + timeoutMin * 60 * 1000;
168
+ let lastQrAt = 0;
169
+
170
+ while (Date.now() < deadline) {
171
+ if (downloaded) break;
172
+ const t = await dlgText();
173
+
174
+ if (t !== lastText) {
175
+ lastText = t;
176
+ log("dialog:", t);
177
+ if (/失效|过期|刷新|重新获取/.test(t)) {
178
+ log("QR expired -> refresh");
179
+ const r = await page
180
+ .evaluate(() => {
181
+ const ds = Array.from(
182
+ document.querySelectorAll('[class*="dialog"],[class*="modal"]'),
183
+ ).filter((e) => e.offsetWidth > 200);
184
+ for (const d of ds)
185
+ for (const e of d.querySelectorAll("a,button,span,div")) {
186
+ const tx = (e.innerText || "").trim();
187
+ if (e.children.length === 0 && /刷新|重新获取|点击刷新/.test(tx)) {
188
+ const r = e.getBoundingClientRect();
189
+ window.__qrRefresh = { x: r.x + r.width / 2, y: r.y + r.height / 2 };
190
+ return window.__qrRefresh;
191
+ }
192
+ }
193
+ return null;
194
+ })
195
+ .catch(() => null);
196
+ if (r) {
197
+ await page.mouse.click(r.x, r.y);
198
+ await page.waitForTimeout(3000);
199
+ }
200
+ qrInfo = null;
201
+ lastQrAt = 0;
202
+ }
203
+ }
204
+
205
+ if (!qrInfo || Date.now() - lastQrAt > 15000) {
206
+ const info = await grabQr();
207
+ if (info) {
208
+ const changed = !qrInfo || info.decoded !== qrInfo.decoded;
209
+ qrInfo = info;
210
+ lastQrAt = Date.now();
211
+ // 只有码真的换了才落盘并打印
212
+ if (changed) {
213
+ log(
214
+ "QR_READY",
215
+ path.basename(info.file),
216
+ info.size,
217
+ info.decoded ? "decoded-ok" : "UNREADABLE",
218
+ );
219
+ write({ state: "WAIT_SCAN", ...info, dialog: t });
220
+ }
221
+ }
222
+ }
223
+
224
+ // 扫码后:找下载按钮
225
+ const dl = await page
226
+ .evaluate(() => {
227
+ const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
228
+ (e) => e.offsetWidth > 200 && e.offsetHeight > 150,
229
+ );
230
+ for (const d of ds)
231
+ for (const e of d.querySelectorAll("a,button,span,div")) {
232
+ const tx = (e.innerText || "").trim();
233
+ if (e.children.length === 0 && /^(下载|下载密钥|重新下载)$/.test(tx)) {
234
+ const r = e.getBoundingClientRect();
235
+ if (r.width > 0) return { x: r.x + r.width / 2, y: r.y + r.height / 2, t: tx };
236
+ }
237
+ }
238
+ return null;
239
+ })
240
+ .catch(() => null);
241
+ if (dl) {
242
+ log("click 下载", dl.t);
243
+ await page.mouse.click(dl.x, dl.y);
244
+ await page.waitForTimeout(5000);
245
+ }
246
+
247
+ await page.waitForTimeout(2500);
248
+ }
249
+
250
+ await page.screenshot({ path: path.join(outDir, `${base}-final.png`) }).catch(() => {});
251
+ if (downloaded) {
252
+ log("DONE", keyOut);
253
+ write({ state: "DONE", keyOut });
254
+ } else {
255
+ log("TIMEOUT");
256
+ write({ state: "TIMEOUT", url: page.url() });
257
+ }
258
+ await ctx.close().catch(() => {});
259
+ process.exit(0);
@@ -0,0 +1,92 @@
1
+ // 反检测上下文:无头 Chromium 最常见的暴露点是 UA 里的 HeadlessChrome 与若干 navigator 特征
2
+ import { chromium } from "playwright";
3
+ import path from "node:path";
4
+
5
+ const UA =
6
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36";
7
+
8
+ export async function launchStealth(profileDir, { headless = true } = {}) {
9
+ const ctx = await chromium.launchPersistentContext(profileDir, {
10
+ headless,
11
+ userAgent: UA,
12
+ locale: "zh-CN",
13
+ timezoneId: "Asia/Shanghai",
14
+ viewport: { width: 1440, height: 900 },
15
+ deviceScaleFactor: 1,
16
+ args: ["--disable-blink-features=AutomationControlled", "--lang=zh-CN"],
17
+ });
18
+ await ctx.addInitScript(() => {
19
+ Object.defineProperty(navigator, "webdriver", { get: () => undefined });
20
+ Object.defineProperty(navigator, "languages", { get: () => ["zh-CN", "zh", "en"] });
21
+ Object.defineProperty(navigator, "plugins", {
22
+ get: () => [1, 2, 3].map((i) => ({ name: `Plugin ${i}` })),
23
+ });
24
+ window.chrome = window.chrome || { runtime: {} };
25
+ const patch = (proto) => {
26
+ if (!proto) return;
27
+ const orig = proto.getParameter;
28
+ proto.getParameter = function (p) {
29
+ if (p === 37445) return "Google Inc. (Intel)";
30
+ if (p === 37446)
31
+ return "ANGLE (Intel, Intel(R) UHD Graphics 630 Direct3D11 vs_5_0 ps_5_0, D3D11)";
32
+ return orig.call(this, p);
33
+ };
34
+ };
35
+ try {
36
+ patch(window.WebGLRenderingContext && window.WebGLRenderingContext.prototype);
37
+ } catch {}
38
+ try {
39
+ patch(window.WebGL2RenderingContext && window.WebGL2RenderingContext.prototype);
40
+ } catch {}
41
+ });
42
+ return ctx;
43
+ }
44
+
45
+ // 人类化拖动:加速—匀速—减速,带纵向抖动,末端微调后停顿再松手
46
+ export async function dragSlider(
47
+ page,
48
+ {
49
+ handleSel = ".aliyunCaptcha-sliding-slider",
50
+ trackSel = ".aliyunCaptcha-sliding-text-box",
51
+ } = {},
52
+ ) {
53
+ const handle = page.locator(handleSel).first();
54
+ const track = page.locator(trackSel).first();
55
+ const hb = await handle.boundingBox();
56
+ const tb = await track.boundingBox();
57
+ if (!hb || !tb) return false;
58
+ const y = hb.y + hb.height / 2;
59
+ const sx = hb.x + hb.width / 2;
60
+ const ex = tb.x + tb.width - hb.width / 2;
61
+
62
+ await page.mouse.move(sx - 25 + Math.random() * 20, y + (Math.random() - 0.5) * 12);
63
+ await page.waitForTimeout(120 + Math.random() * 180);
64
+ await page.mouse.move(sx, y, { steps: 3 });
65
+ await page.waitForTimeout(90 + Math.random() * 120);
66
+ await page.mouse.down();
67
+ await page.waitForTimeout(150 + Math.random() * 200);
68
+
69
+ const dist = ex - sx;
70
+ const steps = 30 + Math.floor(Math.random() * 12);
71
+ let done = 0;
72
+ for (let i = 1; i <= steps; i++) {
73
+ const t = i / steps;
74
+ // 慢起—快中—慢收
75
+ const eased =
76
+ t < 0.2 ? (t / 0.2) ** 2 * 0.06 + t * 0.14 : t > 0.85 ? 1 - ((1 - t) / 0.15) * 0.05 : t;
77
+ const target = Math.min(1, eased) * dist;
78
+ const jitter = (Math.random() - 0.5) * 1.4;
79
+ done = target;
80
+ await page.mouse.move(sx + target, y + jitter);
81
+ await page.waitForTimeout(9 + Math.random() * 17);
82
+ if (Math.random() < 0.12) await page.waitForTimeout(40 + Math.random() * 90);
83
+ }
84
+ // 末端微调
85
+ await page.mouse.move(sx + dist + 3, y, { steps: 2 });
86
+ await page.waitForTimeout(90);
87
+ await page.mouse.move(sx + dist, y);
88
+ await page.waitForTimeout(180 + Math.random() * 150);
89
+ await page.mouse.up();
90
+ void done;
91
+ return true;
92
+ }
@@ -0,0 +1,186 @@
1
+ // 提交审核:须知 → 下一步 → 安全测试提醒「继续提交」→ dump 审核信息表单/结果
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 outDir = process.argv[2] || here;
9
+ const label = process.argv[3] || "submit4";
10
+ const keyword = process.argv[4] || "待办清单";
11
+ const stopAfter = process.argv[5] || ""; // 例如 'continue' 表示到「继续提交」为止不点
12
+ const log = (...a) => console.log(new Date().toISOString(), ...a);
13
+
14
+ const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
15
+ const page = ctx.pages()[0] || (await ctx.newPage());
16
+ await page.goto("https://mp.weixin.qq.com/", { waitUntil: "domcontentloaded", timeout: 60000 });
17
+ await page.waitForTimeout(10000);
18
+ const token = (page.url().match(/token=(\d+)/) || [])[1];
19
+ if (!token) {
20
+ log("NOT LOGGED IN");
21
+ await ctx.close().catch(() => {});
22
+ process.exit(2);
23
+ }
24
+ await page
25
+ .goto(`https://mp.weixin.qq.com/wxamp/wacodepage/getcodepage?token=${token}&lang=zh_CN`, {
26
+ waitUntil: "commit",
27
+ timeout: 60000,
28
+ })
29
+ .catch(() => {});
30
+ await page.waitForTimeout(12000);
31
+
32
+ const bodyText = () => page.evaluate(() => (document.body.innerText || "").replace(/\s+/g, " "));
33
+
34
+ // 打开须知
35
+ const findBtn = () =>
36
+ page.evaluate((kw) => {
37
+ const marker = Array.from(document.querySelectorAll("*")).find(
38
+ (e) => e.children.length === 0 && (e.innerText || "").includes(kw),
39
+ );
40
+ const btns = Array.from(document.querySelectorAll("button,a")).filter(
41
+ (e) => e.offsetWidth && (e.innerText || "").trim() === "提交审核",
42
+ );
43
+ if (!btns.length) return null;
44
+ const my = marker ? marker.getBoundingClientRect().y : 0;
45
+ const chosen = btns
46
+ .map((b) => ({ b, y: b.getBoundingClientRect().y }))
47
+ .filter((o) => o.y > my - 40)
48
+ .sort((a, b) => a.y - b.y)[0];
49
+ const b = chosen ? chosen.b : btns[0];
50
+ b.scrollIntoView({ block: "center" });
51
+ const r = b.getBoundingClientRect();
52
+ return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
53
+ }, keyword);
54
+
55
+ let opened = false;
56
+ for (let i = 0; i < 3 && !opened; i++) {
57
+ const p = await findBtn();
58
+ if (!p) break;
59
+ await page.mouse.click(p.x, p.y);
60
+ for (let w = 0; w < 12; w++) {
61
+ await page.waitForTimeout(1000);
62
+ if (/确认提交审核/.test(await bodyText())) {
63
+ opened = true;
64
+ break;
65
+ }
66
+ }
67
+ }
68
+ if (!opened) {
69
+ log("FAILED TO OPEN");
70
+ await ctx.close().catch(() => {});
71
+ process.exit(4);
72
+ }
73
+ log("notice opened");
74
+
75
+ // 勾选两个确认项
76
+ for (const t of ["已仔细阅读", "已阅读并了解平台审核规则"]) {
77
+ const c = await page.evaluate((t) => {
78
+ const el = Array.from(document.querySelectorAll("label,span,div,p"))
79
+ .filter(
80
+ (e) => e.offsetWidth && (e.innerText || "").includes(t) && (e.innerText || "").length < 120,
81
+ )
82
+ .pop();
83
+ if (!el) return null;
84
+ const r = el.getBoundingClientRect();
85
+ return { x: r.x + 12, y: r.y + r.height / 2 };
86
+ }, t);
87
+ if (c) {
88
+ await page.mouse.click(c.x, c.y);
89
+ await page.waitForTimeout(700);
90
+ }
91
+ }
92
+ log(
93
+ "checked",
94
+ JSON.stringify(
95
+ await page.evaluate(() =>
96
+ Array.from(document.querySelectorAll("input[type=checkbox]"))
97
+ .filter((c) => c.offsetParent)
98
+ .map((c) => c.checked),
99
+ ),
100
+ ),
101
+ );
102
+
103
+ const clickText = async (txt) => {
104
+ const p = await page.evaluate((txt) => {
105
+ const e = Array.from(document.querySelectorAll("button,a,span,div,label"))
106
+ .filter((x) => x.offsetWidth && x.children.length === 0 && (x.innerText || "").trim() === txt)
107
+ .pop();
108
+ if (!e) return null;
109
+ e.scrollIntoView({ block: "center" });
110
+ const r = e.getBoundingClientRect();
111
+ return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
112
+ }, txt);
113
+ if (!p) {
114
+ log("no btn", txt);
115
+ return false;
116
+ }
117
+ await page.mouse.click(p.x, p.y);
118
+ await page.waitForTimeout(4000);
119
+ log("clicked", txt);
120
+ return true;
121
+ };
122
+
123
+ await clickText("下一步");
124
+ log("after 下一步:", (await bodyText()).slice(-260));
125
+ await page.screenshot({ path: path.join(outDir, `miniapp-${label}-safety.png`) }).catch(() => {});
126
+
127
+ if (stopAfter !== "continue") {
128
+ await clickText("继续提交");
129
+ // 抓一下提交后的即时提示(toast 很快就消失)
130
+ for (let i = 0; i < 16; i++) {
131
+ const tip = await page
132
+ .evaluate(() => {
133
+ const out = [];
134
+ for (const e of document.querySelectorAll(
135
+ '[class*="toast"],[class*="tip"],[class*="message"],[class*="dialog"],[class*="warn"],[class*="error"]',
136
+ )) {
137
+ if (!e.offsetWidth) continue;
138
+ const t = (e.innerText || "").replace(/\s+/g, " ").trim();
139
+ if (t) out.push(t.slice(0, 200));
140
+ }
141
+ return [...new Set(out)];
142
+ })
143
+ .catch(() => []);
144
+ if (tip.length) log("tip@" + i, JSON.stringify(tip));
145
+ await page.waitForTimeout(500);
146
+ }
147
+ await page.waitForTimeout(4000);
148
+ log("after 继续提交 url:", page.url());
149
+ log("after 继续提交 text:", (await bodyText()).slice(0, 1800));
150
+ await page
151
+ .screenshot({ path: path.join(outDir, `miniapp-${label}-after.png`), fullPage: true })
152
+ .catch(() => {});
153
+ }
154
+
155
+ const info = await page.evaluate(() => {
156
+ const vis = (e) => !!(e.offsetWidth || e.offsetHeight);
157
+ const btns = [
158
+ ...new Set(
159
+ Array.from(document.querySelectorAll('button,a,[role="button"],label'))
160
+ .filter(vis)
161
+ .map((e) => (e.innerText || "").replace(/\s+/g, " ").trim().slice(0, 30))
162
+ .filter((t) => t && t.length <= 30),
163
+ ),
164
+ ];
165
+ const inputs = Array.from(document.querySelectorAll("input,textarea"))
166
+ .filter(vis)
167
+ .map((e) => ({
168
+ tag: e.tagName,
169
+ type: e.type || "",
170
+ ph: e.placeholder || "",
171
+ val: (e.value || "").slice(0, 30),
172
+ }));
173
+ return {
174
+ url: location.href,
175
+ text: (document.body.innerText || "").replace(/\s+/g, " ").slice(0, 3000),
176
+ btns,
177
+ inputs,
178
+ };
179
+ });
180
+ fs.writeFileSync(path.join(outDir, `miniapp-${label}-state.json`), JSON.stringify(info, null, 2));
181
+ log("STATE URL", info.url);
182
+ log("STATE TEXT:", info.text.slice(0, 1500));
183
+ log("STATE BTNS:", JSON.stringify(info.btns.slice(0, 50)));
184
+ log("STATE INPUTS:", JSON.stringify(info.inputs.slice(0, 25)));
185
+ await ctx.close().catch(() => {});
186
+ process.exit(0);
@@ -0,0 +1,136 @@
1
+ // 从公众号后台切到指定小程序后台,并 dump 落地页(URL/标题/AppID/侧边菜单/链接)
2
+ // 用法: node to-miniapp.mjs "lmliheng" <out.json> <shot.png>
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] || "lmliheng";
10
+ const out = process.argv[3] || "/tmp/to-miniapp.json";
11
+ const shot = process.argv[4] || "/tmp/to-miniapp.png";
12
+
13
+ const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
14
+ let page = ctx.pages()[0] || (await ctx.newPage());
15
+ page.on("framenavigated", (f) => {
16
+ if (f === page.mainFrame()) console.log("NAV", f.url());
17
+ });
18
+ ctx.on("page", (p) => {
19
+ console.log("NEW PAGE", p.url());
20
+ });
21
+
22
+ await page.goto("https://mp.weixin.qq.com/", { waitUntil: "domcontentloaded", timeout: 60000 });
23
+ await page.waitForTimeout(8000);
24
+ console.log("start url", page.url());
25
+
26
+ // 如果已经是小程序后台,直接 dump
27
+ const isMini = /\/wxamp\//.test(page.url());
28
+ if (!isMini) {
29
+ await page
30
+ .click(".mp_account_box", { timeout: 8000 })
31
+ .catch((e) => console.log("open err", e.message.split("\n")[0]));
32
+ await page.waitForTimeout(1500);
33
+ const target = page.locator("li.account_box-panel-item", { hasText: "切换账号" }).first();
34
+ const box = await target.boundingBox().catch(() => null);
35
+ if (box) await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
36
+ else
37
+ await target
38
+ .click({ timeout: 5000, force: true })
39
+ .catch((e) => console.log("click1 err", e.message.split("\n")[0]));
40
+ await page.waitForTimeout(4000);
41
+
42
+ // 弹窗结构 dump(便于排错)
43
+ const dlg = await page.evaluate(() => {
44
+ const d = document.querySelector(".switch-account-dialog");
45
+ if (!d) return null;
46
+ return Array.from(d.querySelectorAll("*"))
47
+ .filter((e) => e.children.length === 0 && (e.innerText || "").trim())
48
+ .map((e) => ({
49
+ cls: (e.className || "").toString().slice(0, 80),
50
+ t: (e.innerText || "").trim().slice(0, 30),
51
+ parentCls: (e.parentElement.className || "").toString().slice(0, 80),
52
+ }));
53
+ });
54
+ console.log("dialog leaves", JSON.stringify(dlg));
55
+
56
+ // 弹窗内的小程序行:找精确文本的最小节点,点它的矩形中心
57
+ const row = page.getByText(keyword, { exact: true }).first();
58
+ let rb = await row.boundingBox().catch(() => null);
59
+ if (!rb) {
60
+ // 退一步:点该文本所在的可点击祖先
61
+ rb = await page
62
+ .evaluate((kw) => {
63
+ const els = Array.from(document.querySelectorAll(".switch-account-dialog *")).filter(
64
+ (e) => (e.innerText || "").trim() === kw,
65
+ );
66
+ if (!els[0]) return null;
67
+ let n = els[0];
68
+ for (
69
+ let i = 0;
70
+ i < 4 && n.parentElement && n.parentElement.closest(".switch-account-dialog");
71
+ i++
72
+ )
73
+ n = n.parentElement;
74
+ const r = n.getBoundingClientRect();
75
+ return { x: r.x, y: r.y, width: r.width, height: r.height };
76
+ }, keyword)
77
+ .catch(() => null);
78
+ }
79
+ console.log("row box", JSON.stringify(rb));
80
+ if (rb) await page.mouse.click(rb.x + Math.min(60, rb.width / 2), rb.y + rb.height / 2);
81
+ else
82
+ await row
83
+ .click({ timeout: 5000, force: true })
84
+ .catch((e) => console.log("click2 err", e.message.split("\n")[0]));
85
+ await page.waitForTimeout(10000);
86
+ // 可能开了新标签页
87
+ const pages = ctx.pages();
88
+ console.log("pages now", JSON.stringify(pages.map((p) => p.url())));
89
+ const mini = pages.find((p) => /\/wxamp\//.test(p.url()));
90
+ if (mini) {
91
+ await mini.bringToFront().catch(() => {});
92
+ page = mini;
93
+ }
94
+ console.log("after switch url", page.url());
95
+ const afterText = await page
96
+ .evaluate(() => (document.body.innerText || "").replace(/\s+/g, " ").slice(0, 600))
97
+ .catch(() => "");
98
+ console.log("after switch text:", afterText);
99
+ await page.screenshot({ path: shot.replace(/\.png$/, "-after-switch.png") }).catch(() => {});
100
+ }
101
+
102
+ const info = await page.evaluate(() => {
103
+ const vis = (e) => !!(e.offsetWidth || e.offsetHeight);
104
+ const all = document.body.innerText || "";
105
+ const appids = [...new Set(all.match(/wx[0-9a-f]{16}/g) || [])];
106
+ const links = Array.from(document.querySelectorAll("a[href]"))
107
+ .filter(vis)
108
+ .map((a) => ({ t: (a.innerText || "").trim().slice(0, 16), href: a.getAttribute("href") }))
109
+ .filter((l) => l.href && l.href !== "javascript:;");
110
+ const menu = Array.from(
111
+ document.querySelectorAll(
112
+ '.weui-desktop-menu__item, .weui-desktop-sub-menu__item, [class*="menu__item"]',
113
+ ),
114
+ )
115
+ .filter(vis)
116
+ .map((e) => (e.innerText || "").replace(/\s+/g, " ").trim())
117
+ .filter(Boolean);
118
+ return {
119
+ url: location.href,
120
+ title: document.title,
121
+ appids,
122
+ links: links.slice(0, 80),
123
+ menu,
124
+ text: all.replace(/\s+/g, " ").slice(0, 1500),
125
+ };
126
+ });
127
+ await page.screenshot({ path: shot, fullPage: false }).catch(() => {});
128
+ fs.writeFileSync(out, JSON.stringify(info, null, 2));
129
+ console.log("URL", info.url);
130
+ console.log("TITLE", info.title);
131
+ console.log("APPIDS", JSON.stringify(info.appids));
132
+ console.log("MENU", JSON.stringify(info.menu.slice(0, 40)));
133
+ console.log("LINKS", JSON.stringify(info.links.slice(0, 40)));
134
+ console.log("TEXT", info.text.slice(0, 800));
135
+ await ctx.close().catch(() => {});
136
+ process.exit(0);