@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,226 @@
|
|
|
1
|
+
// 微信公众号扫码登录 v2:直接抓取二维码原图(而非元素截图),放大并校验可解码性
|
|
2
|
+
import { launchStealth } from "./stealth.mjs";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { PNG } from "pngjs";
|
|
8
|
+
import jsQR from "jsqr";
|
|
9
|
+
|
|
10
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const qrOut = process.argv[2] || path.join(here, "qr.png");
|
|
12
|
+
const statusPath = process.argv[3] || path.join(here, "login-status.json");
|
|
13
|
+
const timeoutMin = Number(process.argv[4] || 12);
|
|
14
|
+
const write = (o) =>
|
|
15
|
+
fs.writeFileSync(statusPath, JSON.stringify({ at: new Date().toISOString(), ...o }, null, 2));
|
|
16
|
+
|
|
17
|
+
// 二维码原图是 jpg(472x472),页面里被缩到 122x122 显示;这里取原图并在浏览器里放大成 PNG
|
|
18
|
+
function savePng(pngBuf, out) {
|
|
19
|
+
fs.writeFileSync(out, pngBuf);
|
|
20
|
+
const png = PNG.sync.read(pngBuf);
|
|
21
|
+
const dec = jsQR(new Uint8Array(png.data), png.width, png.height);
|
|
22
|
+
return { size: `${png.width}x${png.height}`, decoded: dec ? dec.data : null };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
|
|
26
|
+
const page = ctx.pages()[0] || (await ctx.newPage());
|
|
27
|
+
write({ state: "STARTING" });
|
|
28
|
+
|
|
29
|
+
const cookiesHave = async () => {
|
|
30
|
+
const cs = await ctx.cookies("https://mp.weixin.qq.com").catch(() => []);
|
|
31
|
+
return cs.map((c) => c.name).filter((n) => ["slave_sid", "slave_user", "bizuin"].includes(n));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
async function grabQr() {
|
|
35
|
+
const res = await page
|
|
36
|
+
.evaluate(async (scale) => {
|
|
37
|
+
const img = document.querySelector('img[class*="qrcode"], img[src*="scanloginqrcode"]');
|
|
38
|
+
if (!img) return null;
|
|
39
|
+
const src = img.src;
|
|
40
|
+
if (!img.complete || !img.naturalWidth) return { src, png: null, natural: null };
|
|
41
|
+
const c = document.createElement("canvas");
|
|
42
|
+
c.width = img.naturalWidth * scale;
|
|
43
|
+
c.height = img.naturalHeight * scale;
|
|
44
|
+
const g = c.getContext("2d");
|
|
45
|
+
g.imageSmoothingEnabled = false;
|
|
46
|
+
g.fillStyle = "#fff";
|
|
47
|
+
g.fillRect(0, 0, c.width, c.height);
|
|
48
|
+
g.drawImage(img, 0, 0, c.width, c.height);
|
|
49
|
+
return {
|
|
50
|
+
src,
|
|
51
|
+
png: c.toDataURL("image/png").split(",")[1],
|
|
52
|
+
natural: `${img.naturalWidth}x${img.naturalHeight}`,
|
|
53
|
+
};
|
|
54
|
+
}, 2)
|
|
55
|
+
.catch(() => null);
|
|
56
|
+
return res;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let lastSrc = "";
|
|
60
|
+
let dumped = false;
|
|
61
|
+
const deadline = Date.now() + timeoutMin * 60 * 1000;
|
|
62
|
+
let state = "WAITING_SCAN";
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
await page.goto("https://mp.weixin.qq.com/", { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
66
|
+
} catch (e) {
|
|
67
|
+
write({ state: "GOTO_ERROR", error: e.message });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
while (Date.now() < deadline) {
|
|
71
|
+
const url = page.url();
|
|
72
|
+
if (url.includes("/cgi-bin/home") || url.includes("token=")) {
|
|
73
|
+
await page.waitForTimeout(2500);
|
|
74
|
+
const home = qrOut.replace(/\.png$/, "") + "-home.png";
|
|
75
|
+
await page.screenshot({ path: home }).catch(() => {});
|
|
76
|
+
try {
|
|
77
|
+
await ctx.storageState({ path: path.join(here, "session.json") });
|
|
78
|
+
} catch {}
|
|
79
|
+
write({
|
|
80
|
+
state: "LOGGED_IN",
|
|
81
|
+
url,
|
|
82
|
+
title: await page.title().catch(() => ""),
|
|
83
|
+
homeShot: home,
|
|
84
|
+
cookies: await cookiesHave(),
|
|
85
|
+
});
|
|
86
|
+
console.log("LOGGED_IN", url);
|
|
87
|
+
await ctx.close();
|
|
88
|
+
process.exit(0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!dumped) {
|
|
92
|
+
dumped = true;
|
|
93
|
+
const html = await page
|
|
94
|
+
.evaluate(() => {
|
|
95
|
+
const box =
|
|
96
|
+
document.querySelector(".login__type__container__scan") ||
|
|
97
|
+
document.querySelector('[class*="login__type__container"]');
|
|
98
|
+
return box ? box.outerHTML.slice(0, 4000) : "(no login container)";
|
|
99
|
+
})
|
|
100
|
+
.catch(() => "");
|
|
101
|
+
const refreshish = await page
|
|
102
|
+
.evaluate(() =>
|
|
103
|
+
Array.from(document.querySelectorAll(".login__type__container__scan *"))
|
|
104
|
+
.filter((e) => /失效|刷新|重新获取/.test(e.innerText || ""))
|
|
105
|
+
.map(
|
|
106
|
+
(e) =>
|
|
107
|
+
(e.className || "").toString() + " :: " + (e.innerText || "").trim().slice(0, 30),
|
|
108
|
+
)
|
|
109
|
+
.slice(0, 10),
|
|
110
|
+
)
|
|
111
|
+
.catch(() => []);
|
|
112
|
+
console.log(
|
|
113
|
+
"--- login container html ---\n" +
|
|
114
|
+
html +
|
|
115
|
+
"\n--- refresh candidates ---\n" +
|
|
116
|
+
JSON.stringify(refreshish),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const qr = await grabQr();
|
|
121
|
+
if (qr && qr.src !== lastSrc && qr.png) {
|
|
122
|
+
// 按内容 hash 命名,避免同样的文件名被看图工具缓存成旧图
|
|
123
|
+
const buf = Buffer.from(qr.png, "base64");
|
|
124
|
+
const hash = crypto.createHash("sha1").update(buf).digest("hex").slice(0, 8);
|
|
125
|
+
const file = qrOut.replace(/\.png$/, `-${hash}.png`);
|
|
126
|
+
if (!fs.existsSync(file)) {
|
|
127
|
+
fs.writeFileSync(file, buf);
|
|
128
|
+
for (const f of fs.readdirSync(path.dirname(file))) {
|
|
129
|
+
if (
|
|
130
|
+
/^wechat-mp-login-qr-[0-9a-f]{8}\.png$/.test(f) &&
|
|
131
|
+
path.join(path.dirname(file), f) !== file
|
|
132
|
+
) {
|
|
133
|
+
try {
|
|
134
|
+
fs.unlinkSync(path.join(path.dirname(file), f));
|
|
135
|
+
} catch {}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const info = savePng(buf, file);
|
|
140
|
+
lastSrc = qr.src;
|
|
141
|
+
state = "WAITING_SCAN";
|
|
142
|
+
write({ state, url, qrSrc: qr.src, qrFile: file, native: qr.natural, ...info });
|
|
143
|
+
console.log(
|
|
144
|
+
"QR_READY",
|
|
145
|
+
new Date().toISOString(),
|
|
146
|
+
path.basename(file),
|
|
147
|
+
JSON.stringify({ native: qr.natural, ...info }),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 轮询扫码状态
|
|
152
|
+
const ask = await page
|
|
153
|
+
.evaluate(async () => {
|
|
154
|
+
const img = document.querySelector('img[class*="qrcode"], img[src*="scanloginqrcode"]');
|
|
155
|
+
const m = img && (img.getAttribute("src") || "").match(/random=(\d+)/);
|
|
156
|
+
if (!m) return null;
|
|
157
|
+
try {
|
|
158
|
+
const r = await fetch(
|
|
159
|
+
`/cgi-bin/scanloginqrcode?action=ask&random=${m[1]}&lang=zh_CN&token=`,
|
|
160
|
+
{ credentials: "include" },
|
|
161
|
+
);
|
|
162
|
+
return { text: (await r.text()).slice(0, 300) };
|
|
163
|
+
} catch (e) {
|
|
164
|
+
return { error: e.message };
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
.catch(() => null);
|
|
168
|
+
if (ask) {
|
|
169
|
+
let st = null;
|
|
170
|
+
try {
|
|
171
|
+
st = JSON.parse(ask.text);
|
|
172
|
+
} catch {}
|
|
173
|
+
write({ state, url, qrFile: qrOut, ask: ask.text });
|
|
174
|
+
if (st && st.status !== undefined && st.status !== 0)
|
|
175
|
+
console.log("ASK status=" + st.status, ask.text.slice(0, 200));
|
|
176
|
+
if (st && ["1", "2", "4", "5"].includes(String(st.status)))
|
|
177
|
+
state = "SCANNED(status=" + st.status + ")";
|
|
178
|
+
if (st && ["3", "6", "7", "8"].includes(String(st.status))) {
|
|
179
|
+
state = "QR_EXPIRED(status=" + st.status + ")";
|
|
180
|
+
const clicked = await page
|
|
181
|
+
.evaluate(() => {
|
|
182
|
+
const cand = Array.from(
|
|
183
|
+
document.querySelectorAll(".login__type__container__scan *"),
|
|
184
|
+
).filter((e) => /失效|刷新|重新获取/.test(e.innerText || ""));
|
|
185
|
+
if (cand[0]) {
|
|
186
|
+
cand[0].click();
|
|
187
|
+
return (cand[0].innerText || "").trim().slice(0, 30);
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
})
|
|
191
|
+
.catch(() => null);
|
|
192
|
+
console.log("EXPIRED -> refresh click:", clicked);
|
|
193
|
+
lastSrc = "";
|
|
194
|
+
if (!clicked) {
|
|
195
|
+
await page.reload({ waitUntil: "domcontentloaded", timeout: 60000 }).catch(() => {});
|
|
196
|
+
console.log("EXPIRED -> reloaded page for a fresh QR");
|
|
197
|
+
}
|
|
198
|
+
await page.waitForTimeout(2500);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const bodyText = await page
|
|
203
|
+
.evaluate(() => (document.body.innerText || "").slice(0, 800))
|
|
204
|
+
.catch(() => "");
|
|
205
|
+
if (/选择(公众平台)?账号|选择公众号/.test(bodyText) && !/微信扫一扫/.test(bodyText)) {
|
|
206
|
+
const shotPath = qrOut.replace(/\.png$/, "") + "-chooser.png";
|
|
207
|
+
await page.screenshot({ path: shotPath }).catch(() => {});
|
|
208
|
+
write({ state: "ACCOUNT_CHOOSER", url, shot: shotPath, text: bodyText.slice(0, 400) });
|
|
209
|
+
console.log("CHOOSER:", bodyText.slice(0, 300).replace(/\n+/g, " | "));
|
|
210
|
+
const first = page
|
|
211
|
+
.locator('a[class*="account"], li[class*="account"], [class*="account__item"]')
|
|
212
|
+
.first();
|
|
213
|
+
if ((await first.count().catch(() => 0)) > 0) {
|
|
214
|
+
await first.click({ timeout: 5000 }).catch((e) => console.log("click failed", e.message));
|
|
215
|
+
await page.waitForTimeout(4000);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
await page.waitForTimeout(2000);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
write({ state: "TIMEOUT", url: page.url() });
|
|
224
|
+
console.log("TIMEOUT");
|
|
225
|
+
await ctx.close();
|
|
226
|
+
process.exit(1);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// 小程序后台信息采集:首页 / 基本设置(AppID) / 开发设置(上传密钥入口)
|
|
2
|
+
// 用法: node miniapp-info.mjs <outDir> <shotPrefix>
|
|
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 outDir = process.argv[2] || here;
|
|
10
|
+
const shotPrefix = process.argv[3] || path.join(outDir, "miniapp");
|
|
11
|
+
|
|
12
|
+
const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
|
|
13
|
+
const page = ctx.pages()[0] || (await ctx.newPage());
|
|
14
|
+
await page.goto("https://mp.weixin.qq.com/", { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
15
|
+
await page.waitForTimeout(7000);
|
|
16
|
+
console.log("home", page.url());
|
|
17
|
+
const token = (page.url().match(/token=(\d+)/) || [])[1];
|
|
18
|
+
console.log("token", token);
|
|
19
|
+
|
|
20
|
+
const grab = async (label, url) => {
|
|
21
|
+
await page
|
|
22
|
+
.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 })
|
|
23
|
+
.catch((e) => console.log(label, "goto err", e.message));
|
|
24
|
+
await page.waitForTimeout(7000);
|
|
25
|
+
const info = await page.evaluate(() => {
|
|
26
|
+
const vis = (e) => !!(e.offsetWidth || e.offsetHeight);
|
|
27
|
+
const all = document.body.innerText || "";
|
|
28
|
+
const appids = [...new Set(all.match(/wx[0-9a-f]{16}/g) || [])];
|
|
29
|
+
const links = Array.from(document.querySelectorAll("a[href]"))
|
|
30
|
+
.filter(vis)
|
|
31
|
+
.map((a) => ({ t: (a.innerText || "").trim().slice(0, 20), href: a.getAttribute("href") }))
|
|
32
|
+
.filter((l) => l.href && l.href !== "javascript:;")
|
|
33
|
+
.slice(0, 100);
|
|
34
|
+
const menu = Array.from(
|
|
35
|
+
document.querySelectorAll('[class*="menu__item"], [class*="menu-item"], [class*="nav"] a'),
|
|
36
|
+
)
|
|
37
|
+
.filter(vis)
|
|
38
|
+
.map((e) => (e.innerText || "").replace(/\s+/g, " ").trim())
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.slice(0, 60);
|
|
41
|
+
return {
|
|
42
|
+
url: location.href,
|
|
43
|
+
title: document.title,
|
|
44
|
+
appids,
|
|
45
|
+
links,
|
|
46
|
+
menu,
|
|
47
|
+
text: all.replace(/\s+/g, " ").slice(0, 2000),
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
await page.screenshot({ path: `${shotPrefix}-${label}.png` }).catch(() => {});
|
|
51
|
+
fs.writeFileSync(path.join(outDir, `miniapp-${label}.json`), JSON.stringify(info, null, 2));
|
|
52
|
+
console.log(`--- ${label} ${info.url}`);
|
|
53
|
+
console.log(" title", info.title, "appids", JSON.stringify(info.appids));
|
|
54
|
+
console.log(" menu", JSON.stringify(info.menu.slice(0, 30)));
|
|
55
|
+
console.log(" text", info.text.slice(0, 700));
|
|
56
|
+
return info;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
await grab("home", "https://mp.weixin.qq.com/wxamp/index/index?lang=zh_CN&token=" + token);
|
|
60
|
+
await grab("basic", `https://mp.weixin.qq.com/wxamp/basicprofile/index?lang=zh_CN&token=${token}`);
|
|
61
|
+
await grab(
|
|
62
|
+
"dev",
|
|
63
|
+
`https://mp.weixin.qq.com/wxamp/devprofile/get_profile?lang=zh_CN&token=${token}`,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
await ctx.close().catch(() => {});
|
|
67
|
+
process.exit(0);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// 在小程序后台打开指定页面并 dump 文本/按钮;用法: node miniapp-nav.mjs <path> [label] [outDir]
|
|
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 p = process.argv[2] || "/wxamp/index/index";
|
|
9
|
+
const label = process.argv[3] || "page";
|
|
10
|
+
const outDir = process.argv[4] || here;
|
|
11
|
+
|
|
12
|
+
const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
|
|
13
|
+
const page = ctx.pages()[0] || (await ctx.newPage());
|
|
14
|
+
await page
|
|
15
|
+
.goto("https://mp.weixin.qq.com/", { waitUntil: "commit", timeout: 60000 })
|
|
16
|
+
.catch((e) => console.log("home goto warn", e.message.split("\n")[0]));
|
|
17
|
+
await page.waitForTimeout(14000);
|
|
18
|
+
const token = (page.url().match(/token=(\d+)/) || [])[1];
|
|
19
|
+
console.log("home", page.url(), "token", token);
|
|
20
|
+
if (!token) {
|
|
21
|
+
console.log("NOT LOGGED IN");
|
|
22
|
+
await ctx.close().catch(() => {});
|
|
23
|
+
process.exit(2);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await page
|
|
27
|
+
.goto(`https://mp.weixin.qq.com${p}?token=${token}&lang=zh_CN`, {
|
|
28
|
+
waitUntil: "commit",
|
|
29
|
+
timeout: 60000,
|
|
30
|
+
})
|
|
31
|
+
.catch((e) => console.log("goto warn", e.message.split("\n")[0]));
|
|
32
|
+
await page.waitForTimeout(15000);
|
|
33
|
+
const info = await page.evaluate(() => {
|
|
34
|
+
const vis = (e) => !!(e.offsetWidth || e.offsetHeight);
|
|
35
|
+
const btns = Array.from(document.querySelectorAll('button,a,[role="button"]'))
|
|
36
|
+
.filter(vis)
|
|
37
|
+
.map((e) => ({
|
|
38
|
+
t: (e.innerText || "").replace(/\s+/g, " ").trim().slice(0, 24),
|
|
39
|
+
cls: (e.className || "").toString().slice(0, 70),
|
|
40
|
+
href: e.getAttribute && e.getAttribute("href"),
|
|
41
|
+
}))
|
|
42
|
+
.filter((b) => b.t && b.t.length < 24);
|
|
43
|
+
return {
|
|
44
|
+
url: location.href,
|
|
45
|
+
title: document.title,
|
|
46
|
+
text: (document.body.innerText || "").replace(/\s+/g, " ").slice(0, 2500),
|
|
47
|
+
btns: btns.slice(0, 60),
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
await page.screenshot({ path: path.join(outDir, `miniapp-${label}.png`) }).catch(() => {});
|
|
51
|
+
fs.writeFileSync(path.join(outDir, `miniapp-${label}.json`), JSON.stringify(info, null, 2));
|
|
52
|
+
console.log("URL", info.url);
|
|
53
|
+
console.log("TEXT", info.text);
|
|
54
|
+
console.log("BTNS", JSON.stringify(info.btns));
|
|
55
|
+
await ctx.close().catch(() => {});
|
|
56
|
+
process.exit(0);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wechat-mp-scripts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "微信小程序后台自动化脚本(登录/切号/密钥/IP 白名单/隐私指引/提审/撤回)的依赖清单",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"jpeg-js": "^0.4.4",
|
|
8
|
+
"jsqr": "^1.4.0",
|
|
9
|
+
"playwright": "^1.63.0",
|
|
10
|
+
"pngjs": "^7.0.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// 填写隐私指引 → 预览 → 确定并提交协议;如需扫码则出码等待
|
|
2
|
+
import { launchStealth } from "./stealth.mjs";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import crypto from "node:crypto";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { PNG } from "pngjs";
|
|
8
|
+
import jsQR from "jsqr";
|
|
9
|
+
|
|
10
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const outDir = process.argv[2] || here;
|
|
12
|
+
const contact = process.argv[3] || "liheng221994@qq.com";
|
|
13
|
+
const log = (...a) => console.log(new Date().toISOString(), ...a);
|
|
14
|
+
const PURPOSES = [
|
|
15
|
+
"用于账号注册、登录与身份校验",
|
|
16
|
+
"用于保存你生成或导出的图片到相册",
|
|
17
|
+
"用于按你所在位置提供本地化内容",
|
|
18
|
+
"用于识别你复制的文本并快速创建内容",
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
function upscale3x(png) {
|
|
22
|
+
const s = 3,
|
|
23
|
+
b = new PNG({ width: png.width * s, height: png.height * s });
|
|
24
|
+
for (let y = 0; y < b.height; y++)
|
|
25
|
+
for (let x = 0; x < b.width; x++) {
|
|
26
|
+
const si = (((y / s) | 0) * png.width + ((x / s) | 0)) << 2,
|
|
27
|
+
di = (y * b.width + x) << 2;
|
|
28
|
+
b.data[di] = png.data[si];
|
|
29
|
+
b.data[di + 1] = png.data[si + 1];
|
|
30
|
+
b.data[di + 2] = png.data[si + 2];
|
|
31
|
+
b.data[di + 3] = 255;
|
|
32
|
+
}
|
|
33
|
+
return b;
|
|
34
|
+
}
|
|
35
|
+
function deliverQr(pngBuf) {
|
|
36
|
+
const png = PNG.sync.read(pngBuf);
|
|
37
|
+
const big = upscale3x(png);
|
|
38
|
+
const dec = jsQR(new Uint8Array(big.data), big.width, big.height);
|
|
39
|
+
const hash = crypto
|
|
40
|
+
.createHash("sha1")
|
|
41
|
+
.update(dec ? dec.data : PNG.sync.write(big))
|
|
42
|
+
.digest("hex")
|
|
43
|
+
.slice(0, 8);
|
|
44
|
+
const file = path.join(outDir, `wechat-mp-priv-qr-${hash}.png`);
|
|
45
|
+
if (!fs.existsSync(file)) {
|
|
46
|
+
fs.writeFileSync(file, PNG.sync.write(big));
|
|
47
|
+
for (const f of fs.readdirSync(outDir))
|
|
48
|
+
if (/^wechat-mp-priv-qr-[0-9a-f]{8}\.png$/.test(f) && path.join(outDir, f) !== file) {
|
|
49
|
+
try {
|
|
50
|
+
fs.unlinkSync(path.join(outDir, f));
|
|
51
|
+
} catch {}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
file,
|
|
56
|
+
hash,
|
|
57
|
+
size: `${big.width}x${big.height}`,
|
|
58
|
+
decoded: dec ? dec.data.slice(0, 90) : null,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
|
|
63
|
+
const page = ctx.pages()[0] || (await ctx.newPage());
|
|
64
|
+
await page
|
|
65
|
+
.goto("https://mp.weixin.qq.com/", { waitUntil: "commit", timeout: 60000 })
|
|
66
|
+
.catch(() => {});
|
|
67
|
+
await page.waitForTimeout(15000);
|
|
68
|
+
const token = (page.url().match(/token=(\d+)/) || [])[1];
|
|
69
|
+
if (!token) {
|
|
70
|
+
log("NOT LOGGED IN");
|
|
71
|
+
await ctx.close().catch(() => {});
|
|
72
|
+
process.exit(2);
|
|
73
|
+
}
|
|
74
|
+
await page
|
|
75
|
+
.goto(
|
|
76
|
+
`https://mp.weixin.qq.com/wxamp/wadevelopcode/privacy?ver=1&id=0&wait=0&token=${token}&lang=zh_CN`,
|
|
77
|
+
{ waitUntil: "commit", timeout: 60000 },
|
|
78
|
+
)
|
|
79
|
+
.catch(() => {});
|
|
80
|
+
await page.waitForTimeout(22000);
|
|
81
|
+
|
|
82
|
+
const txt = () => page.evaluate(() => (document.body.innerText || "").replace(/\s+/g, " "));
|
|
83
|
+
const clickText = async (label, { last = true } = {}) => {
|
|
84
|
+
const p = await page.evaluate(
|
|
85
|
+
({ label, last }) => {
|
|
86
|
+
const els = Array.from(document.querySelectorAll("button,a,span,div,li")).filter(
|
|
87
|
+
(e) => e.offsetWidth && e.children.length === 0 && (e.innerText || "").trim() === label,
|
|
88
|
+
);
|
|
89
|
+
if (!els.length) return null;
|
|
90
|
+
const e = last ? els[els.length - 1] : els[0];
|
|
91
|
+
e.scrollIntoView({ block: "center" });
|
|
92
|
+
const r = e.getBoundingClientRect();
|
|
93
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
94
|
+
},
|
|
95
|
+
{ label, last },
|
|
96
|
+
);
|
|
97
|
+
if (!p) {
|
|
98
|
+
log("no elem", label);
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
await page.mouse.click(p.x, p.y);
|
|
102
|
+
await page.waitForTimeout(3000);
|
|
103
|
+
log("clicked", label);
|
|
104
|
+
return true;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// 1) 用途
|
|
108
|
+
const boxes = page.locator('input[placeholder="请填写用途"]');
|
|
109
|
+
for (let i = 0; i < (await boxes.count()); i++)
|
|
110
|
+
await boxes
|
|
111
|
+
.nth(i)
|
|
112
|
+
.fill(PURPOSES[i] || PURPOSES[0])
|
|
113
|
+
.catch(() => {});
|
|
114
|
+
|
|
115
|
+
// 2) 联系方式:定位「请选择」所在行,选中类型后填同行输入框
|
|
116
|
+
const anchorY = await page.evaluate(() => {
|
|
117
|
+
const e = Array.from(document.querySelectorAll("*")).find(
|
|
118
|
+
(x) => x.offsetWidth && x.children.length === 0 && (x.innerText || "").trim() === "请选择",
|
|
119
|
+
);
|
|
120
|
+
if (!e) return null;
|
|
121
|
+
e.scrollIntoView({ block: "center" });
|
|
122
|
+
return e.getBoundingClientRect().y;
|
|
123
|
+
});
|
|
124
|
+
log("anchor y", anchorY);
|
|
125
|
+
await page.waitForTimeout(800);
|
|
126
|
+
if (anchorY !== null) {
|
|
127
|
+
const p = await page.evaluate(() => {
|
|
128
|
+
const e = Array.from(document.querySelectorAll("*")).find(
|
|
129
|
+
(x) => x.offsetWidth && x.children.length === 0 && (x.innerText || "").trim() === "请选择",
|
|
130
|
+
);
|
|
131
|
+
if (!e) return null;
|
|
132
|
+
const r = e.getBoundingClientRect();
|
|
133
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
134
|
+
});
|
|
135
|
+
if (p) {
|
|
136
|
+
await page.mouse.click(p.x, p.y);
|
|
137
|
+
await page.waitForTimeout(2000);
|
|
138
|
+
}
|
|
139
|
+
const opt = await page.evaluate(() => {
|
|
140
|
+
const els = Array.from(document.querySelectorAll('li,[role="option"],span,div')).filter(
|
|
141
|
+
(x) => x.offsetWidth && x.children.length === 0 && (x.innerText || "").trim() === "邮箱",
|
|
142
|
+
);
|
|
143
|
+
if (!els.length) return null;
|
|
144
|
+
const r = els[els.length - 1].getBoundingClientRect();
|
|
145
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
146
|
+
});
|
|
147
|
+
if (opt) {
|
|
148
|
+
await page.mouse.click(opt.x, opt.y);
|
|
149
|
+
await page.waitForTimeout(2500);
|
|
150
|
+
log("picked 邮箱");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 填到与「请选择」同一行的输入框
|
|
154
|
+
// 用 placeholder=邮箱 精确定位联系方式输入框
|
|
155
|
+
const byPh = page.locator('input[placeholder="邮箱"]');
|
|
156
|
+
if (await byPh.count().catch(() => 0)) {
|
|
157
|
+
await byPh
|
|
158
|
+
.first()
|
|
159
|
+
.fill(contact)
|
|
160
|
+
.catch((e) => log("contact fill err", e.message.split("\n")[0]));
|
|
161
|
+
log("contact filled via placeholder");
|
|
162
|
+
}
|
|
163
|
+
const res = await page.evaluate(
|
|
164
|
+
({ y, v }) => {
|
|
165
|
+
const inputs = Array.from(
|
|
166
|
+
document.querySelectorAll("input[type=text],input:not([type])"),
|
|
167
|
+
).filter((e) => e.offsetWidth && !/请填写用途/.test(e.placeholder || ""));
|
|
168
|
+
const near = inputs.filter((i) => Math.abs(i.getBoundingClientRect().y - y) < 90);
|
|
169
|
+
if (!near.length)
|
|
170
|
+
return {
|
|
171
|
+
ok: false,
|
|
172
|
+
cands: inputs.map((i) => ({
|
|
173
|
+
y: Math.round(i.getBoundingClientRect().y),
|
|
174
|
+
ph: i.placeholder,
|
|
175
|
+
val: i.value,
|
|
176
|
+
})),
|
|
177
|
+
};
|
|
178
|
+
const t = near[0];
|
|
179
|
+
const setter = Object.getOwnPropertyDescriptor(
|
|
180
|
+
window.HTMLInputElement.prototype,
|
|
181
|
+
"value",
|
|
182
|
+
).set;
|
|
183
|
+
setter.call(t, v);
|
|
184
|
+
t.dispatchEvent(new Event("input", { bubbles: true }));
|
|
185
|
+
t.dispatchEvent(new Event("change", { bubbles: true }));
|
|
186
|
+
return { ok: true, val: t.value, ph: t.placeholder };
|
|
187
|
+
},
|
|
188
|
+
{ y: anchorY, v: contact },
|
|
189
|
+
);
|
|
190
|
+
log("contact fill", JSON.stringify(res));
|
|
191
|
+
}
|
|
192
|
+
// 2.5) 补 5.2「再次以 ___ 方式告知」那一栏(预览时会显示「待填写」)
|
|
193
|
+
const fifth = await page.evaluate(() => {
|
|
194
|
+
const inputs = Array.from(document.querySelectorAll("input[type=text],input:not([type])")).filter(
|
|
195
|
+
(e) =>
|
|
196
|
+
e.offsetWidth &&
|
|
197
|
+
!/请填写用途/.test(e.placeholder || "") &&
|
|
198
|
+
!/邮箱|电话|微信号|qq/.test(e.placeholder || ""),
|
|
199
|
+
);
|
|
200
|
+
const t = inputs[inputs.length - 1];
|
|
201
|
+
if (!t) return null;
|
|
202
|
+
const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
|
|
203
|
+
setter.call(t, "弹窗提示");
|
|
204
|
+
t.dispatchEvent(new Event("input", { bubbles: true }));
|
|
205
|
+
t.dispatchEvent(new Event("change", { bubbles: true }));
|
|
206
|
+
return { ph: t.placeholder || "", val: t.value, y: Math.round(t.getBoundingClientRect().y) };
|
|
207
|
+
});
|
|
208
|
+
log("5.2 填写", JSON.stringify(fifth));
|
|
209
|
+
await page.waitForTimeout(1200);
|
|
210
|
+
await page
|
|
211
|
+
.screenshot({ path: path.join(outDir, "pf2-before-preview.png"), fullPage: true })
|
|
212
|
+
.catch(() => {});
|
|
213
|
+
|
|
214
|
+
// 3) 预览 → 提交
|
|
215
|
+
await clickText("预览后提交协议");
|
|
216
|
+
await page.waitForTimeout(7000);
|
|
217
|
+
let t = await txt();
|
|
218
|
+
log("preview tail:", t.slice(-400));
|
|
219
|
+
const stillWarn = /联系方式待完善|部分进行完善/.test(t);
|
|
220
|
+
log("still warn", stillWarn);
|
|
221
|
+
await page
|
|
222
|
+
.screenshot({ path: path.join(outDir, "pf2-preview.png"), fullPage: true })
|
|
223
|
+
.catch(() => {});
|
|
224
|
+
|
|
225
|
+
if (!stillWarn) {
|
|
226
|
+
// 勾选「本小程序已对用户的信息处理进行了逐一、如实的说明…」
|
|
227
|
+
const cb = await page.evaluate(() => {
|
|
228
|
+
const el = Array.from(document.querySelectorAll("label,span,div,p"))
|
|
229
|
+
.filter(
|
|
230
|
+
(e) =>
|
|
231
|
+
e.offsetWidth &&
|
|
232
|
+
/本小程序已对用户的信息处理/.test(e.innerText || "") &&
|
|
233
|
+
(e.innerText || "").length < 120,
|
|
234
|
+
)
|
|
235
|
+
.pop();
|
|
236
|
+
if (!el) return null;
|
|
237
|
+
el.scrollIntoView({ block: "center" });
|
|
238
|
+
const r = el.getBoundingClientRect();
|
|
239
|
+
return { x: r.x + 10, y: r.y + r.height / 2 };
|
|
240
|
+
});
|
|
241
|
+
log("agree checkbox", JSON.stringify(cb));
|
|
242
|
+
if (cb) {
|
|
243
|
+
await page.mouse.click(cb.x, cb.y);
|
|
244
|
+
await page.waitForTimeout(1500);
|
|
245
|
+
}
|
|
246
|
+
const st = await page.evaluate(() =>
|
|
247
|
+
Array.from(document.querySelectorAll("input[type=checkbox]")).map((c) => ({
|
|
248
|
+
checked: c.checked,
|
|
249
|
+
vis: !!c.offsetParent,
|
|
250
|
+
})),
|
|
251
|
+
);
|
|
252
|
+
log("checkbox state", JSON.stringify(st));
|
|
253
|
+
await page
|
|
254
|
+
.screenshot({ path: path.join(outDir, "pf2-agreed.png"), fullPage: true })
|
|
255
|
+
.catch(() => {});
|
|
256
|
+
await clickText("确定并提交协议");
|
|
257
|
+
await page.waitForTimeout(8000);
|
|
258
|
+
t = await txt();
|
|
259
|
+
log("after submit url", page.url());
|
|
260
|
+
log("after submit tail", t.slice(-400));
|
|
261
|
+
await page
|
|
262
|
+
.screenshot({ path: path.join(outDir, "pf2-submitted.png"), fullPage: true })
|
|
263
|
+
.catch(() => {});
|
|
264
|
+
|
|
265
|
+
// 可能弹扫码
|
|
266
|
+
const el = await page.evaluateHandle(() => {
|
|
267
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
268
|
+
(e) => e.offsetWidth > 200 && e.offsetHeight > 120,
|
|
269
|
+
);
|
|
270
|
+
for (const d of ds)
|
|
271
|
+
for (const img of d.querySelectorAll("img")) {
|
|
272
|
+
if (img.getBoundingClientRect().width > 120) return img;
|
|
273
|
+
}
|
|
274
|
+
for (const d of ds)
|
|
275
|
+
for (const cv of d.querySelectorAll("canvas")) {
|
|
276
|
+
if (cv.getBoundingClientRect().width > 120) return cv;
|
|
277
|
+
}
|
|
278
|
+
return null;
|
|
279
|
+
});
|
|
280
|
+
const node = el.asElement();
|
|
281
|
+
if (node) {
|
|
282
|
+
const buf = await node.screenshot().catch(() => null);
|
|
283
|
+
if (buf) {
|
|
284
|
+
const info = deliverQr(buf);
|
|
285
|
+
log(
|
|
286
|
+
"QR_READY",
|
|
287
|
+
path.basename(info.file),
|
|
288
|
+
info.size,
|
|
289
|
+
info.decoded ? "decoded-ok" : "UNREADABLE",
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const dlg = await page.evaluate(() => {
|
|
294
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
295
|
+
(e) => e.offsetWidth > 200 && e.offsetHeight > 120,
|
|
296
|
+
);
|
|
297
|
+
return ds.map((d) => (d.innerText || "").replace(/\s+/g, " ").trim().slice(0, 200));
|
|
298
|
+
});
|
|
299
|
+
log("dialogs after submit", JSON.stringify(dlg));
|
|
300
|
+
}
|
|
301
|
+
await ctx.close().catch(() => {});
|
|
302
|
+
process.exit(0);
|