specific-ai-cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.en.md +177 -0
- package/README.ja.md +177 -0
- package/README.ko.md +177 -0
- package/README.md +174 -2
- package/README.zh-TW.md +177 -0
- package/assets/banner.txt +3 -0
- package/dist/cli/argv.js +98 -0
- package/dist/cli/commands/auth.js +11 -0
- package/dist/cli/commands/config.js +23 -0
- package/dist/cli/commands/doctor.js +134 -0
- package/dist/cli/commands/platforms.js +24 -0
- package/dist/cli/commands/version.js +4 -0
- package/dist/cli/confirm.js +22 -0
- package/dist/cli/dispatch.js +440 -0
- package/dist/cli/help.js +223 -0
- package/dist/cli/hints.js +60 -0
- package/dist/cli/main.js +18 -0
- package/dist/cli/output.js +66 -0
- package/dist/core/auth-handlers.js +41 -0
- package/dist/core/auth-store.js +119 -0
- package/dist/core/capabilities.js +163 -0
- package/dist/core/config.js +121 -0
- package/dist/core/cookies.js +164 -0
- package/dist/core/errors.js +37 -0
- package/dist/core/files.js +89 -0
- package/dist/core/fsutil.js +52 -0
- package/dist/core/hash.js +4 -0
- package/dist/core/http.js +331 -0
- package/dist/core/image.js +280 -0
- package/dist/core/log.js +40 -0
- package/dist/core/login.js +191 -0
- package/dist/core/mp4.js +130 -0
- package/dist/core/normalize.js +207 -0
- package/dist/core/options.js +110 -0
- package/dist/core/paths.js +38 -0
- package/dist/core/pb.js +59 -0
- package/dist/core/py.js +181 -0
- package/dist/core/rand.js +131 -0
- package/dist/core/registry.js +129 -0
- package/dist/core/schemas.js +41 -0
- package/dist/core/stream.js +104 -0
- package/dist/core/toolkit.js +35 -0
- package/dist/core/vm.js +73 -0
- package/dist/core/vocab.js +157 -0
- package/dist/platforms/_shared/impaas.js +410 -0
- package/dist/platforms/bilibili/index.js +216 -0
- package/dist/platforms/bilibili/web/api.js +806 -0
- package/dist/platforms/bilibili/web/client.js +311 -0
- package/dist/platforms/bilibili/web/commands.js +783 -0
- package/dist/platforms/bilibili/web/ddddocr.js +342 -0
- package/dist/platforms/bilibili/web/gaia.js +130 -0
- package/dist/platforms/bilibili/web/geetest-manual.js +154 -0
- package/dist/platforms/bilibili/web/geetest-vision.js +232 -0
- package/dist/platforms/bilibili/web/geetest.js +450 -0
- package/dist/platforms/bilibili/web/normalize.js +234 -0
- package/dist/platforms/bilibili/web/profile.js +135 -0
- package/dist/platforms/bilibili/web/resolve.js +112 -0
- package/dist/platforms/bilibili/web/sign.js +223 -0
- package/dist/platforms/bilibili/web/upos.js +102 -0
- package/dist/platforms/douyin/index.js +142 -0
- package/dist/platforms/douyin/web/api.js +863 -0
- package/dist/platforms/douyin/web/client.js +413 -0
- package/dist/platforms/douyin/web/commands.js +712 -0
- package/dist/platforms/douyin/web/creator.js +601 -0
- package/dist/platforms/douyin/web/crypto.js +247 -0
- package/dist/platforms/douyin/web/dtrait.js +190 -0
- package/dist/platforms/douyin/web/im.js +502 -0
- package/dist/platforms/douyin/web/image.js +5 -0
- package/dist/platforms/douyin/web/live.js +225 -0
- package/dist/platforms/douyin/web/mssdk.js +148 -0
- package/dist/platforms/douyin/web/normalize.js +326 -0
- package/dist/platforms/douyin/web/passport.js +1247 -0
- package/dist/platforms/douyin/web/profile.js +221 -0
- package/dist/platforms/douyin/web/proto.js +26 -0
- package/dist/platforms/douyin/web/resolve.js +88 -0
- package/dist/platforms/douyin/web/sign.js +436 -0
- package/dist/platforms/douyin/web/tos.js +78 -0
- package/dist/platforms/index.js +17 -0
- package/dist/platforms/jd/index.js +67 -0
- package/dist/platforms/jd/web/aks.js +115 -0
- package/dist/platforms/jd/web/api.js +549 -0
- package/dist/platforms/jd/web/chat.js +132 -0
- package/dist/platforms/jd/web/client.js +470 -0
- package/dist/platforms/jd/web/commands.js +557 -0
- package/dist/platforms/jd/web/jcap/helper.js +90 -0
- package/dist/platforms/jd/web/jcap/host.js +107 -0
- package/dist/platforms/jd/web/jcap/lsd.js +300 -0
- package/dist/platforms/jd/web/jcap/solver.js +995 -0
- package/dist/platforms/jd/web/jcap.js +150 -0
- package/dist/platforms/jd/web/js.js +420 -0
- package/dist/platforms/jd/web/login.js +775 -0
- package/dist/platforms/jd/web/normalize.js +297 -0
- package/dist/platforms/jd/web/profile.js +256 -0
- package/dist/platforms/jd/web/util.js +175 -0
- package/dist/platforms/jd/web/webm.js +133 -0
- package/dist/platforms/kuaishou/index.js +98 -0
- package/dist/platforms/kuaishou/web/api.js +694 -0
- package/dist/platforms/kuaishou/web/captcha-crypto.js +134 -0
- package/dist/platforms/kuaishou/web/captcha-fp.js +180 -0
- package/dist/platforms/kuaishou/web/captcha.js +273 -0
- package/dist/platforms/kuaishou/web/client.js +487 -0
- package/dist/platforms/kuaishou/web/commands.js +863 -0
- package/dist/platforms/kuaishou/web/gap.js +144 -0
- package/dist/platforms/kuaishou/web/gdfp.js +376 -0
- package/dist/platforms/kuaishou/web/gql.js +11 -0
- package/dist/platforms/kuaishou/web/live.js +125 -0
- package/dist/platforms/kuaishou/web/normalize.js +241 -0
- package/dist/platforms/kuaishou/web/oracle.js +329 -0
- package/dist/platforms/kuaishou/web/profile.js +259 -0
- package/dist/platforms/kuaishou/web/resolve.js +84 -0
- package/dist/platforms/kuaishou/web/session.js +592 -0
- package/dist/platforms/kuaishou/web/sign.js +568 -0
- package/dist/platforms/taobao/index.js +56 -0
- package/dist/platforms/taobao/web/api.js +96 -0
- package/dist/platforms/taobao/web/client.js +102 -0
- package/dist/platforms/taobao/web/commands.js +172 -0
- package/dist/platforms/taobao/web/im.js +68 -0
- package/dist/platforms/taobao/web/normalize.js +103 -0
- package/dist/platforms/taobao/web/profile.js +85 -0
- package/dist/platforms/taobao/web/resolve.js +51 -0
- package/dist/platforms/taobao/web/sign.js +35 -0
- package/dist/platforms/tiktok/index.js +120 -0
- package/dist/platforms/tiktok/web/api.js +1234 -0
- package/dist/platforms/tiktok/web/client.js +362 -0
- package/dist/platforms/tiktok/web/commands.js +821 -0
- package/dist/platforms/tiktok/web/im.js +133 -0
- package/dist/platforms/tiktok/web/jsrun.js +126 -0
- package/dist/platforms/tiktok/web/normalize.js +286 -0
- package/dist/platforms/tiktok/web/profile.js +169 -0
- package/dist/platforms/tiktok/web/resolve.js +156 -0
- package/dist/platforms/tiktok/web/sign.js +585 -0
- package/dist/platforms/tiktok/web/upload.js +805 -0
- package/dist/platforms/tiktok/web/wire.js +490 -0
- package/dist/platforms/weibo/index.js +91 -0
- package/dist/platforms/weibo/web/api.js +206 -0
- package/dist/platforms/weibo/web/client.js +155 -0
- package/dist/platforms/weibo/web/commands.js +202 -0
- package/dist/platforms/weibo/web/normalize.js +137 -0
- package/dist/platforms/weibo/web/profile.js +246 -0
- package/dist/platforms/weibo/web/resolve.js +60 -0
- package/dist/platforms/weibo/web/sign.js +85 -0
- package/dist/platforms/x/index.js +107 -0
- package/dist/platforms/x/web/api.js +443 -0
- package/dist/platforms/x/web/article.js +212 -0
- package/dist/platforms/x/web/client.js +202 -0
- package/dist/platforms/x/web/commands.js +363 -0
- package/dist/platforms/x/web/graphql.js +108 -0
- package/dist/platforms/x/web/normalize.js +235 -0
- package/dist/platforms/x/web/profile.js +99 -0
- package/dist/platforms/x/web/resolve.js +44 -0
- package/dist/platforms/x/web/transaction.js +171 -0
- package/dist/platforms/xhs/index.js +101 -0
- package/dist/platforms/xhs/web/api.js +278 -0
- package/dist/platforms/xhs/web/client.js +540 -0
- package/dist/platforms/xhs/web/commands.js +1046 -0
- package/dist/platforms/xhs/web/creator-api.js +609 -0
- package/dist/platforms/xhs/web/creator.js +203 -0
- package/dist/platforms/xhs/web/js.js +194 -0
- package/dist/platforms/xhs/web/login.js +230 -0
- package/dist/platforms/xhs/web/normalize.js +166 -0
- package/dist/platforms/xhs/web/profile.js +127 -0
- package/dist/platforms/xhs/web/push.js +361 -0
- package/dist/platforms/xhs/web/resolve.js +69 -0
- package/dist/platforms/xhs/web/state.js +368 -0
- package/dist/platforms/xianyu/index.js +59 -0
- package/dist/platforms/xianyu/web/api.js +312 -0
- package/dist/platforms/xianyu/web/client.js +134 -0
- package/dist/platforms/xianyu/web/commands.js +305 -0
- package/dist/platforms/xianyu/web/im.js +73 -0
- package/dist/platforms/xianyu/web/normalize.js +123 -0
- package/dist/platforms/xianyu/web/profile.js +146 -0
- package/dist/platforms/xianyu/web/resolve.js +48 -0
- package/dist/platforms/xianyu/web/sign.js +79 -0
- package/package.json +77 -4
- package/static/douyin/Live.proto +194 -0
- package/static/douyin/Request.proto +89 -0
- package/static/douyin/Response.proto +46 -0
- package/static/douyin/acrawler_runtime/ac_vm.js +2 -0
- package/static/douyin/acrawler_runtime/browser_window_shape.json +1 -0
- package/static/douyin/acrawler_runtime/canvas_actual_exact.json +1 -0
- package/static/douyin/acrawler_runtime/run_ac_node.js +1005 -0
- package/static/douyin/acrawler_runtime/runner_window_keys_baseline.txt +240 -0
- package/static/douyin/challenge_profile.json +801 -0
- package/static/douyin/challenge_template_runner.js +217 -0
- package/static/douyin/dtrait_profile.json +66 -0
- package/static/douyin/mstoken_common_profile.json +1 -0
- package/static/douyin/mstoken_profile.json +214 -0
- package/static/jd/h5st5_env.js +750 -0
- package/static/jd/h5st5_lib.js +5 -0
- package/static/jd/h5st5_server.js +49 -0
- package/static/jd/jcap/env/env_core.js +512 -0
- package/static/jd/jcap/env/run.js +1307 -0
- package/static/jd/jcap/run/jcap_ujb96b.js +39 -0
- package/static/jd/package.json +4 -0
- package/static/jd/pc_tk_lib.js +1 -0
- package/static/jd/pc_tk_server.js +63 -0
- package/static/jd/summer_cryptico_runner.js +50 -0
- package/static/jd/webm/env/run.js +453 -0
- package/static/jd/webm/run/jdwebm-riskhandle.js +49 -0
- package/static/kuaishou/bundles/weapon/kwf-0.0.2.2cee19b4b7dec496.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-0-0.0.1-obfuscated.4b7f3de1ab0ddcc2.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-1-0.0.1-obfuscated.346ebdb1c78df316.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-10-0.0.1-obfuscated.a33db41897b983af.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-11-0.0.1-obfuscated.5e0a90af726d8a7e.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-12-0.0.1-obfuscated.20ea29345706ec8c.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-13-0.0.1-obfuscated.6b74e9640ff18648.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-14-0.0.1-obfuscated.551e4429d156bf66.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-15-0.0.1-obfuscated.8625b087aaba4a60.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-16-0.0.1-obfuscated.d5ffa4020f3be99a.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-17-0.0.1-obfuscated.6d13e19b22f50a80.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-18-0.0.1-obfuscated.6d31405044166289.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-19-0.0.1-obfuscated.a9a8d925942f19e4.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-2-0.0.1-obfuscated.b849a136ae4a6b3e.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-3-0.0.1-obfuscated.f9e77ebf6186e2ac.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-4-0.0.1-obfuscated.2c3c155aa52ceb0e.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-5-0.0.1-obfuscated.4e553d17691b3c5a.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-6-0.0.1-obfuscated.f73ddd3ff13e1217.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-7-0.0.1-obfuscated.1628b8729beaab7e.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-8-0.0.1-obfuscated.6da6baef7aa81fff.js +1 -0
- package/static/kuaishou/bundles/weapon/kws-9-0.0.1-obfuscated.8645d55e5323b743.js +1 -0
- package/static/kuaishou/fixtures/current_follow_script_813.network-response +2 -0
- package/static/kuaishou/fixtures/live_ws_maps.json +61 -0
- package/static/kuaishou/fixtures/live_ws_proto.json +1342 -0
- package/static/kuaishou/js/cp-kwf.js +1 -0
- package/static/kuaishou/tools/kwf_oracle.js +799 -0
- package/static/kuaishou/tools/kws_oracle.js +885 -0
- package/static/kuaishou/tools/like_token_oracle.js +70 -0
- package/static/taobao/taobao_js_20260407.js +570 -0
- package/static/tiktok/Tiktok_Request.json +597 -0
- package/static/tiktok/package.json +3 -0
- package/static/tiktok/shop_bsid/core.js +1 -0
- package/static/tiktok/shop_bsid/env_core.js +512 -0
- package/static/tiktok/shop_bsid/loader.js +1 -0
- package/static/tiktok/shop_bsid/run.js +753 -0
- package/static/tiktok/shop_bsid/sign.js +100 -0
- package/static/tiktok/shop_bsid/webmssdk.js +1 -0
- package/static/tiktok/shop_bsid/webmssdk_ex.js +1 -0
- package/static/tiktok/signing/env/env_core.js +512 -0
- package/static/tiktok/signing/env/sign.js +455 -0
- package/static/tiktok/signing/sdk_config.json +230 -0
- package/static/tiktok/signing/source/webmssdk.js +1 -0
- package/static/tiktok/signing/source/webmssdk_ex.js +1 -0
- package/static/tiktok/signing/source/webmssdk_legacy.js +1 -0
- package/static/x/graphql.json +7777 -0
- package/static/x/transaction_l1.json +12 -0
- package/static/xhs/package.json +3 -0
- package/static/xhs/xhs_core/js/b1.js +210 -0
- package/static/xhs/xhs_core/js/mns.js +340 -0
- package/static/xhs/xhs_core/js/mns_0101_keystream.json +5 -0
- package/static/xhs/xhs_core/js/mns_keystreams.json +1 -0
- package/static/xhs/xhs_core/js/sign.js +225 -0
- package/static/xhs/xhs_core/js/websectiga_cli.js +220 -0
- package/static/xhs/xhs_core/js/websectiga_env.js +512 -0
- package/static/xhs/xhs_core/js/xs_common.js +79 -0
- package/static/xhs/xhs_creator/js/profile.js +115 -0
- package/static/xhs/xhs_creator/js/rap_fingerprint_creator.json +6 -0
- package/static/xhs/xhs_creator/js/reference_profile.json +282 -0
- package/static/xhs/xhs_creator/js/xhs_creator_sign.js +29 -0
- package/static/xhs/xhs_creator/js/xhs_creator_signature.js +23 -0
- package/static/xhs/xhs_pc/js/aes_decrypt.js +22 -0
- package/static/xhs/xhs_pc/js/aes_encrypt.js +30 -0
- package/static/xhs/xhs_pc/js/b1.js +9 -0
- package/static/xhs/xhs_pc/js/deflate.js +320 -0
- package/static/xhs/xhs_pc/js/mns.js +4 -0
- package/static/xhs/xhs_pc/js/profile.js +141 -0
- package/static/xhs/xhs_pc/js/rap.js +173 -0
- package/static/xhs/xhs_pc/js/rap_cli.js +30 -0
- package/static/xhs/xhs_pc/js/rap_crypto.js +73 -0
- package/static/xhs/xhs_pc/js/rap_fingerprint_template.json +8 -0
- package/static/xhs/xhs_pc/js/reference_profile.json +262 -0
- package/static/xhs/xhs_pc/js/sign.js +6 -0
- package/static/xhs/xhs_pc/js/web_ssk.js +82 -0
- package/static/xhs/xhs_pc/js/xs_common.js +4 -0
- package/static/xianyu/et_f.js +2 -0
- package/static/xianyu/gen_tfstk.js +410 -0
- package/static/xianyu/goofish_js_version_2.js +568 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash } from 'node:crypto';
|
|
2
|
+
import * as rand from '../../../core/rand.js';
|
|
3
|
+
/**
|
|
4
|
+
* passport 的 AKS 加密(上游 utils/aks.py,与登录页 aks.js / summer-cryptico 一致):
|
|
5
|
+
* `base64(公钥头 || SM2(C1C3C2, sm4Key) || iv || SM4-CBC(query))`。
|
|
6
|
+
* SM2 的实现照 gmssl(随机数 k 用 64 个十六进制字符),SM3 / SM4 用 node 自带的 OpenSSL。
|
|
7
|
+
*/
|
|
8
|
+
const P = BigInt('0xFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF');
|
|
9
|
+
const A = BigInt('0xFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC');
|
|
10
|
+
const G = [
|
|
11
|
+
BigInt('0x32c4ae2c1f1981195f9904466a39c9948fe30bbff2660be1715a4589334c74c7'),
|
|
12
|
+
BigInt('0xbc3736a2f4f6779c59bdcee36b692153d0a9877cc62a474002df32e52139f0a0'),
|
|
13
|
+
];
|
|
14
|
+
const mod = (x) => ((x % P) + P) % P;
|
|
15
|
+
function inv(x) {
|
|
16
|
+
let [a, b, u, v] = [mod(x), P, 1n, 0n];
|
|
17
|
+
while (a !== 0n) {
|
|
18
|
+
const q = b / a;
|
|
19
|
+
[a, b] = [b - q * a, a];
|
|
20
|
+
[u, v] = [v - q * u, u];
|
|
21
|
+
}
|
|
22
|
+
return mod(v);
|
|
23
|
+
}
|
|
24
|
+
function add(p, q) {
|
|
25
|
+
if (!p)
|
|
26
|
+
return q;
|
|
27
|
+
if (!q)
|
|
28
|
+
return p;
|
|
29
|
+
if (p[0] === q[0]) {
|
|
30
|
+
if (mod(p[1] + q[1]) === 0n)
|
|
31
|
+
return null;
|
|
32
|
+
const l = mod((3n * p[0] * p[0] + A) * inv(2n * p[1]));
|
|
33
|
+
const x = mod(l * l - 2n * p[0]);
|
|
34
|
+
return [x, mod(l * (p[0] - x) - p[1])];
|
|
35
|
+
}
|
|
36
|
+
const l = mod((q[1] - p[1]) * inv(q[0] - p[0]));
|
|
37
|
+
const x = mod(l * l - p[0] - q[0]);
|
|
38
|
+
return [x, mod(l * (p[0] - x) - p[1])];
|
|
39
|
+
}
|
|
40
|
+
function mul(k, p) {
|
|
41
|
+
let r = null;
|
|
42
|
+
let q = p;
|
|
43
|
+
while (k > 0n) {
|
|
44
|
+
if (k & 1n)
|
|
45
|
+
r = add(r, q);
|
|
46
|
+
q = add(q, q);
|
|
47
|
+
k >>= 1n;
|
|
48
|
+
}
|
|
49
|
+
return r;
|
|
50
|
+
}
|
|
51
|
+
const hex64 = (n) => n.toString(16).padStart(64, '0');
|
|
52
|
+
const sm3 = (data) => createHash('sm3').update(data).digest();
|
|
53
|
+
function kdf(z, klen) {
|
|
54
|
+
const out = [];
|
|
55
|
+
for (let ct = 1; out.length * 32 < klen; ct++) {
|
|
56
|
+
const c = Buffer.alloc(4);
|
|
57
|
+
c.writeUInt32BE(ct);
|
|
58
|
+
out.push(sm3(Buffer.concat([z, c])));
|
|
59
|
+
}
|
|
60
|
+
return Buffer.concat(out).subarray(0, klen);
|
|
61
|
+
}
|
|
62
|
+
/** gmssl `CryptSM2(public_key=pubHex, mode=1).encrypt(data)`:C1(64) || C3(32) || C2。 */
|
|
63
|
+
export function sm2Encrypt(publicHex, data) {
|
|
64
|
+
const pub = [BigInt('0x' + publicHex.slice(0, 64)), BigInt('0x' + publicHex.slice(64, 128))];
|
|
65
|
+
const k = BigInt('0x' + rand.string(64, '0123456789abcdef'));
|
|
66
|
+
const c1 = mul(k, G);
|
|
67
|
+
const s = mul(k, pub);
|
|
68
|
+
const x2 = Buffer.from(hex64(s[0]), 'hex');
|
|
69
|
+
const y2 = Buffer.from(hex64(s[1]), 'hex');
|
|
70
|
+
const t = kdf(Buffer.concat([x2, y2]), data.length);
|
|
71
|
+
const c2 = Buffer.from(data.map((b, i) => b ^ t[i]));
|
|
72
|
+
const c3 = sm3(Buffer.concat([x2, Buffer.from(data), y2]));
|
|
73
|
+
return Buffer.concat([Buffer.from(hex64(c1[0]) + hex64(c1[1]), 'hex'), c3, c2]);
|
|
74
|
+
}
|
|
75
|
+
export function sm4Encrypt(data, key, iv) {
|
|
76
|
+
const c = createCipheriv('sm4-cbc', key, iv);
|
|
77
|
+
return Buffer.concat([c.update(data), c.final()]);
|
|
78
|
+
}
|
|
79
|
+
export function sm4Decrypt(data, key, iv) {
|
|
80
|
+
const d = createDecipheriv('sm4-cbc', key, iv);
|
|
81
|
+
return Buffer.concat([d.update(data), d.final()]);
|
|
82
|
+
}
|
|
83
|
+
const STORAGE_KEY = Buffer.from('6c3d6878252e641b');
|
|
84
|
+
const STORAGE_IV = Buffer.from('5f5e5a247f544d771255134517043757', 'hex');
|
|
85
|
+
/** summer-cryptico 的 randomUnit8Array(1, 127, n)。 */
|
|
86
|
+
const randomUnits = (n) => Uint8Array.from({ length: n }, () => Math.floor(rand.random() * 127) + 1);
|
|
87
|
+
function loadSm4Key(state) {
|
|
88
|
+
try {
|
|
89
|
+
if (state.aksKey) {
|
|
90
|
+
const plain = sm4Decrypt(Buffer.from(state.aksKey, 'hex'), STORAGE_KEY, STORAGE_IV).toString('utf8');
|
|
91
|
+
if (/^[0-9a-f]{16}$/.test(plain))
|
|
92
|
+
return plain;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch { }
|
|
96
|
+
const key = Buffer.from(randomUnits(8)).toString('hex');
|
|
97
|
+
state.aksKey = sm4Encrypt(Buffer.from(key, 'utf8'), STORAGE_KEY, STORAGE_IV).toString('hex');
|
|
98
|
+
return key;
|
|
99
|
+
}
|
|
100
|
+
/** 把 jQuery 编码后的 query 串加密成 aksParamsU / aksParamsB(encrypt_query)。 */
|
|
101
|
+
export function encryptQuery(query, publicKeyB64, state) {
|
|
102
|
+
if (!query)
|
|
103
|
+
throw new Error('AKS query cannot be empty');
|
|
104
|
+
const raw = Buffer.from(publicKeyB64, 'base64');
|
|
105
|
+
if (raw.length < 65)
|
|
106
|
+
throw new Error('passport publicKey/init 返回值长度不足');
|
|
107
|
+
const header = raw.subarray(0, raw.length - 65);
|
|
108
|
+
const pub = raw.subarray(raw.length - 65);
|
|
109
|
+
const publicHex = pub[0] === 4 ? pub.subarray(1).toString('hex') : pub.toString('hex');
|
|
110
|
+
const sm4Key = loadSm4Key(state);
|
|
111
|
+
const iv = randomUnits(16);
|
|
112
|
+
const sm2 = sm2Encrypt(publicHex, Buffer.from(sm4Key, 'utf8'));
|
|
113
|
+
const sm4 = sm4Encrypt(Buffer.from(query, 'utf8'), Buffer.from(sm4Key, 'utf8'), iv);
|
|
114
|
+
return Buffer.concat([header, sm2, iv, sm4]).toString('base64');
|
|
115
|
+
}
|
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import { parseJsonp } from '../../../core/http.js';
|
|
2
|
+
import { unescapeHtml } from '../../../core/normalize.js';
|
|
3
|
+
import { jsonLoads, quote, urlencode } from '../../../core/py.js';
|
|
4
|
+
import * as rand from '../../../core/rand.js';
|
|
5
|
+
import { searchReferer } from './client.js';
|
|
6
|
+
import { solveCaptcha } from './jcap.js';
|
|
7
|
+
import { API_URL, APPID_DONGDONG, APPID_PC_ITEM, APPID_PC_SEARCH, basic, CHAT_ORIGIN, CHAT_REFERER, CLIENT_IMH5, CLIENT_PC_ITEM, CLIENT_PC_ITEM_V3, CLIENT_PC_SEARCH, CLIENT_WH5, ITEM_ORIGIN, ITEM_REFERER, ORDER_DD_NO_TIME, ORDER_DD_WITH_TIME, ORDER_PC_API, ORDER_PC_ITEM, ORDER_PC_ITEM_RELWORDS, ORDER_PC_SEARCH, ORDER_PC_SEARCH_PLAIN, ORDER_PC_SEARCH_RELWORDS, ORDER_URL, orderDoc, RP_CLIENT_CHAT, RP_CLIENT_ITEM, RP_CLIENT_SEARCH, SEARCH_ORIGIN, xhr, } from './profile.js';
|
|
8
|
+
import { areaOf, ITEM_URL_SKU, searchUuidOf, stripTags } from './util.js';
|
|
9
|
+
import { buildSearchPayload } from './webm.js';
|
|
10
|
+
/**
|
|
11
|
+
* 上游 jd_apis/jd_api.py 的 JdAPI,一个函数对应一个上游方法,字段与顺序照抄(对拍测试逐字节比较)。
|
|
12
|
+
* 返回平台原始 JSON。
|
|
13
|
+
*/
|
|
14
|
+
/** 免签名的纯查询接口在浏览器里不带这两个参数。 */
|
|
15
|
+
const UNSIGNED_DROP = ['loginType', 'x-api-eid-token'];
|
|
16
|
+
const itemPage = (sku) => (sku ? `https://item.jd.com/${sku}.html` : ITEM_REFERER);
|
|
17
|
+
// ================================================================ 会话活性
|
|
18
|
+
/** passport 的免签名探测(check_session):返回 [alive, 昵称或说明],以及原始响应。 */
|
|
19
|
+
export async function checkSession(jd) {
|
|
20
|
+
const h = basic('JSONP').referer('https://www.jd.com/');
|
|
21
|
+
const res = await jd.send({
|
|
22
|
+
url: 'https://passport.jd.com/loginservice.aspx',
|
|
23
|
+
query: [
|
|
24
|
+
['method', 'Login'],
|
|
25
|
+
['callback', 'jsonpLogin'],
|
|
26
|
+
],
|
|
27
|
+
headers: h.get(),
|
|
28
|
+
timeout: 15,
|
|
29
|
+
});
|
|
30
|
+
const data = parseJsonp(await res.text()) ?? {};
|
|
31
|
+
const identity = data.Identity && typeof data.Identity === 'object' ? data.Identity : null;
|
|
32
|
+
const alive = Boolean(identity?.IsAuthenticated);
|
|
33
|
+
return { alive, name: alive ? (identity?.Name ?? jd.pin) : null, data };
|
|
34
|
+
}
|
|
35
|
+
// ================================================================ 商品
|
|
36
|
+
/** 商品详情(pc_detailpage_wareBusiness)。 */
|
|
37
|
+
export function productDetail(jd, sku, area, num = '1', retry = 2) {
|
|
38
|
+
const body = { skuId: String(sku), area: area || areaOf(jd.cookies), num: String(num), clientSource: 'PC', userAgent: 'Windows', sfTime: '1,0,0' };
|
|
39
|
+
return jd.call('pc_detailpage_wareBusiness', {
|
|
40
|
+
body,
|
|
41
|
+
path: '/',
|
|
42
|
+
client: CLIENT_PC_ITEM,
|
|
43
|
+
appId: APPID_PC_ITEM,
|
|
44
|
+
extra: [['scval', String(sku)]],
|
|
45
|
+
referer: ITEM_REFERER,
|
|
46
|
+
refererPage: itemPage(sku),
|
|
47
|
+
rpClient: RP_CLIENT_ITEM,
|
|
48
|
+
origin: ITEM_ORIGIN,
|
|
49
|
+
method: 'GET',
|
|
50
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
51
|
+
order: ORDER_PC_ITEM,
|
|
52
|
+
retry,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** 商品评价(getLegoWareDetailComment)。 */
|
|
56
|
+
export function productComments(jd, sku, count = 5) {
|
|
57
|
+
const body = { shopType: '0', sku: Number(sku), commentNum: count, source: 'pc' };
|
|
58
|
+
return jd.call('getLegoWareDetailComment', {
|
|
59
|
+
body,
|
|
60
|
+
path: '/',
|
|
61
|
+
client: CLIENT_PC_ITEM_V3,
|
|
62
|
+
appId: APPID_PC_ITEM,
|
|
63
|
+
extra: [['build', '100000']],
|
|
64
|
+
referer: ITEM_REFERER,
|
|
65
|
+
refererPage: itemPage(sku),
|
|
66
|
+
rpClient: RP_CLIENT_ITEM,
|
|
67
|
+
origin: ITEM_ORIGIN,
|
|
68
|
+
method: 'GET',
|
|
69
|
+
order: ORDER_PC_ITEM,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** 商品页推荐优惠券(getRecommendCoupon)。 */
|
|
73
|
+
export function recommendCoupon(jd, sku, area) {
|
|
74
|
+
return jd.call('getRecommendCoupon', {
|
|
75
|
+
body: { client: 'pc' },
|
|
76
|
+
path: '/',
|
|
77
|
+
client: CLIENT_PC_ITEM_V3,
|
|
78
|
+
appId: APPID_PC_ITEM,
|
|
79
|
+
extra: [['area', area || areaOf(jd.cookies)]],
|
|
80
|
+
referer: ITEM_REFERER,
|
|
81
|
+
refererPage: itemPage(sku),
|
|
82
|
+
rpClient: RP_CLIENT_ITEM,
|
|
83
|
+
origin: ITEM_ORIGIN,
|
|
84
|
+
method: 'GET',
|
|
85
|
+
order: ORDER_PC_ITEM,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** 商品相关搜索词(relsearch):不签 h5st,也不带 t。 */
|
|
89
|
+
export function relatedSearch(jd, sku, num = 6) {
|
|
90
|
+
return jd.call('relsearch', {
|
|
91
|
+
body: {},
|
|
92
|
+
path: '/api',
|
|
93
|
+
client: CLIENT_PC_ITEM_V3,
|
|
94
|
+
sign: false,
|
|
95
|
+
withTime: false,
|
|
96
|
+
extra: [
|
|
97
|
+
['skuid', String(sku)],
|
|
98
|
+
['num', num],
|
|
99
|
+
['rettype', 'json'],
|
|
100
|
+
['type_name', 'relsearch'],
|
|
101
|
+
],
|
|
102
|
+
referer: ITEM_REFERER,
|
|
103
|
+
refererPage: itemPage(sku),
|
|
104
|
+
rpClient: RP_CLIENT_ITEM,
|
|
105
|
+
origin: ITEM_ORIGIN,
|
|
106
|
+
method: 'GET',
|
|
107
|
+
withUuid: true,
|
|
108
|
+
drop: UNSIGNED_DROP,
|
|
109
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
110
|
+
order: ORDER_PC_ITEM_RELWORDS,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// ================================================================ 搜索
|
|
114
|
+
function searchCall(jd, keyword, body, retry) {
|
|
115
|
+
return jd.call('pc_search_searchWare', {
|
|
116
|
+
body,
|
|
117
|
+
path: '/api',
|
|
118
|
+
client: CLIENT_PC_SEARCH,
|
|
119
|
+
appId: APPID_PC_SEARCH,
|
|
120
|
+
extra: [
|
|
121
|
+
['cthr', '1'],
|
|
122
|
+
['keyword', keyword],
|
|
123
|
+
],
|
|
124
|
+
referer: searchReferer(jd, keyword),
|
|
125
|
+
origin: SEARCH_ORIGIN,
|
|
126
|
+
method: 'GET',
|
|
127
|
+
retry,
|
|
128
|
+
appendTime: true,
|
|
129
|
+
order: ORDER_PC_SEARCH,
|
|
130
|
+
uuid: searchUuidOf(jd.cookies),
|
|
131
|
+
axios: true,
|
|
132
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 商品搜索(pc_search_searchWare):先跑 WebM 指纹;命中 605 时纯程序完成 JCAP、保存 x-rp-evtoken 后重试一次。
|
|
137
|
+
* sort 为上游取值:空=综合、sort_totalsales15_desc、sort_price_asc、sort_price_desc、sort_commentcount_desc。
|
|
138
|
+
*/
|
|
139
|
+
export async function search(jd, keyword, page = 1, options = {}) {
|
|
140
|
+
await ensureWebmToken(jd, keyword);
|
|
141
|
+
const body = {
|
|
142
|
+
enc: 'utf-8',
|
|
143
|
+
area: options.area || areaOf(jd.cookies),
|
|
144
|
+
page,
|
|
145
|
+
mode: '',
|
|
146
|
+
concise: false,
|
|
147
|
+
hoverPictures: false,
|
|
148
|
+
newAdvRepeat: false,
|
|
149
|
+
mixerParam: false,
|
|
150
|
+
new_interval: true,
|
|
151
|
+
s: (page - 1) * 30 + 1,
|
|
152
|
+
pageSize: 30,
|
|
153
|
+
};
|
|
154
|
+
if (options.sort)
|
|
155
|
+
body.sort = options.sort;
|
|
156
|
+
jd.searchKeyword = keyword;
|
|
157
|
+
const retry = options.retry ?? 2;
|
|
158
|
+
const result = await searchCall(jd, keyword, body, retry);
|
|
159
|
+
if ((options.autoVerify ?? true) && result && typeof result === 'object' && result.disposal) {
|
|
160
|
+
const verified = await solveSearchRisk(jd, result, keyword);
|
|
161
|
+
if (verified.code === 0) {
|
|
162
|
+
const retried = await searchCall(jd, keyword, body, retry);
|
|
163
|
+
if (retried && typeof retried === 'object')
|
|
164
|
+
retried._verification = verified;
|
|
165
|
+
return retried;
|
|
166
|
+
}
|
|
167
|
+
result._verification = verified;
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
/** 搜索热词(pc_search_hotwords):不签 h5st。 */
|
|
172
|
+
export function searchHotwords(jd) {
|
|
173
|
+
return jd.call('pc_search_hotwords', {
|
|
174
|
+
path: '/api',
|
|
175
|
+
client: CLIENT_PC_SEARCH,
|
|
176
|
+
sign: false,
|
|
177
|
+
referer: searchReferer(jd),
|
|
178
|
+
origin: SEARCH_ORIGIN,
|
|
179
|
+
refererPage: 'https://search.jd.com/Search',
|
|
180
|
+
rpClient: RP_CLIENT_SEARCH,
|
|
181
|
+
method: 'GET',
|
|
182
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
183
|
+
order: ORDER_PC_SEARCH_PLAIN,
|
|
184
|
+
drop: UNSIGNED_DROP,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/** 搜索页相关搜索词(pc_search_relwords)。 */
|
|
188
|
+
export function searchRelwords(jd, keyword = '', num = 10) {
|
|
189
|
+
return jd.call('pc_search_relwords', {
|
|
190
|
+
body: { keyword },
|
|
191
|
+
path: '/api',
|
|
192
|
+
client: CLIENT_PC_SEARCH,
|
|
193
|
+
sign: false,
|
|
194
|
+
extra: [
|
|
195
|
+
['keyword', keyword],
|
|
196
|
+
['num', num],
|
|
197
|
+
['rettype', 'json'],
|
|
198
|
+
['type_name', 'relsearch'],
|
|
199
|
+
],
|
|
200
|
+
referer: searchReferer(jd, keyword),
|
|
201
|
+
origin: SEARCH_ORIGIN,
|
|
202
|
+
refererPage: 'https://search.jd.com/Search',
|
|
203
|
+
rpClient: RP_CLIENT_SEARCH,
|
|
204
|
+
method: 'GET',
|
|
205
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
206
|
+
order: ORDER_PC_SEARCH_RELWORDS,
|
|
207
|
+
drop: UNSIGNED_DROP,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// ================================================================ 账号
|
|
211
|
+
/** 购物车数量(pcCart_jc_getCartNum):POST,body 留在 query。 */
|
|
212
|
+
export function cartNum(jd, area) {
|
|
213
|
+
const body = { serInfo: { area: area || areaOf(jd.cookies, true), 'user-key': '' }, cartExt: { specialId: 1 } };
|
|
214
|
+
return jd.call('pcCart_jc_getCartNum', {
|
|
215
|
+
body,
|
|
216
|
+
path: '/api',
|
|
217
|
+
client: CLIENT_PC_SEARCH,
|
|
218
|
+
appId: APPID_PC_ITEM,
|
|
219
|
+
referer: searchReferer(jd),
|
|
220
|
+
origin: SEARCH_ORIGIN,
|
|
221
|
+
refererPage: 'https://search.jd.com/Search',
|
|
222
|
+
rpClient: RP_CLIENT_SEARCH,
|
|
223
|
+
withUuid: false,
|
|
224
|
+
bodyInQuery: true,
|
|
225
|
+
order: ORDER_PC_API,
|
|
226
|
+
contentType: 'application/json',
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/** 浏览历史(pc_myjd_getBrowseHistory)。 */
|
|
230
|
+
export function browseHistory(jd, page = 1, pageSize = 20, area, retry = 2, sku = '') {
|
|
231
|
+
return jd.call('pc_myjd_getBrowseHistory', {
|
|
232
|
+
body: { pageNo: page, pageSize, tag: 1, source: 'pc_sx_history' },
|
|
233
|
+
path: '/',
|
|
234
|
+
client: CLIENT_PC_ITEM_V3,
|
|
235
|
+
appId: APPID_PC_ITEM,
|
|
236
|
+
extra: [['area', area || areaOf(jd.cookies)]],
|
|
237
|
+
referer: ITEM_REFERER,
|
|
238
|
+
refererPage: itemPage(sku),
|
|
239
|
+
rpClient: RP_CLIENT_ITEM,
|
|
240
|
+
origin: ITEM_ORIGIN,
|
|
241
|
+
method: 'GET',
|
|
242
|
+
order: ORDER_PC_ITEM,
|
|
243
|
+
retry,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/** 关注的商品(pc_follow_product_new)。 */
|
|
247
|
+
export function followProducts(jd, page = 1, pageSize = 1, area, retry = 2, sku = '') {
|
|
248
|
+
return jd.call('pc_follow_product_new', {
|
|
249
|
+
body: { pageNo: page, pageSize, tag: 1, source: 'pc_sx_follow_product' },
|
|
250
|
+
path: '/',
|
|
251
|
+
client: CLIENT_PC_ITEM_V3,
|
|
252
|
+
appId: APPID_PC_ITEM,
|
|
253
|
+
extra: [['area', area || areaOf(jd.cookies)]],
|
|
254
|
+
referer: ITEM_REFERER,
|
|
255
|
+
refererPage: itemPage(sku),
|
|
256
|
+
rpClient: RP_CLIENT_ITEM,
|
|
257
|
+
origin: ITEM_ORIGIN,
|
|
258
|
+
method: 'GET',
|
|
259
|
+
order: ORDER_PC_ITEM,
|
|
260
|
+
retry,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/** 订单列表(get_order_list):订单中心是 HTML 页面,逐个 `<tbody id="tb-<订单号>">` 解析。 */
|
|
264
|
+
export async function orderList(jd, page = 1, dateRange = '1') {
|
|
265
|
+
const res = await jd.send({
|
|
266
|
+
url: ORDER_URL,
|
|
267
|
+
headers: orderDoc().get(),
|
|
268
|
+
query: [
|
|
269
|
+
['search', '0'],
|
|
270
|
+
['d', dateRange],
|
|
271
|
+
['s', '4096'],
|
|
272
|
+
['page', page],
|
|
273
|
+
],
|
|
274
|
+
});
|
|
275
|
+
const html = (await res.text()) ?? '';
|
|
276
|
+
const head = html.slice(0, 2000);
|
|
277
|
+
if (head.includes('passport.jd.com') && head.includes('login')) {
|
|
278
|
+
return { orders: [], count: 0, page, _error: '被跳到登录页,登录态失效了' };
|
|
279
|
+
}
|
|
280
|
+
const orders = parseOrders(html);
|
|
281
|
+
return { orders, count: orders.length, page };
|
|
282
|
+
}
|
|
283
|
+
export function parseOrders(html) {
|
|
284
|
+
const clean = (s) => (s ? unescapeHtml(stripTags(s)).trim() : '');
|
|
285
|
+
const orders = [];
|
|
286
|
+
for (const match of html.matchAll(/<tbody id="tb-(\d+)"[^>]*>([\s\S]*?)<\/tbody>/g)) {
|
|
287
|
+
const [, orderId, chunk] = match;
|
|
288
|
+
const pick = (re) => clean(re.exec(chunk)?.[1]);
|
|
289
|
+
// 商品名与 SKU 从同一个 <a> 里取,空名的链接连同它的 SKU 一起去掉,两者不会错位
|
|
290
|
+
let links = [...chunk.matchAll(/<div class="p-name">\s*<a([^>]*)>([\s\S]*?)<\/a>/g)];
|
|
291
|
+
if (!links.length)
|
|
292
|
+
links = [...chunk.matchAll(/class="p-name"[^>]*>\s*<a([^>]*)>([\s\S]*?)<\/a>/g)];
|
|
293
|
+
const products = links
|
|
294
|
+
.map((m) => ({ name: clean(m[2]), sku: ITEM_URL_SKU.exec(/href="([^"]*)"/.exec(m[1])?.[1] ?? '')?.[1] ?? null }))
|
|
295
|
+
.filter((p) => p.name)
|
|
296
|
+
.slice(0, 10);
|
|
297
|
+
const amountRaw = pick(/<div class="amount"[^>]*>([\s\S]*?)<\/div>/);
|
|
298
|
+
const lines = amountRaw.split(/\r?\n|\r/).map((l) => l.trim()).filter(Boolean);
|
|
299
|
+
const order = {
|
|
300
|
+
orderId,
|
|
301
|
+
time: pick(/<span class="dealtime"[^>]*>([\s\S]*?)<\/span>/),
|
|
302
|
+
consignee: pick(/<div class="consignee[^"]*"[^>]*>\s*<span class="txt">([\s\S]*?)<\/span>/),
|
|
303
|
+
amount: lines[0] ?? amountRaw,
|
|
304
|
+
payType: lines[1] ?? '',
|
|
305
|
+
status: pick(/<span class="order-status[^"]*"[^>]*>([\s\S]*?)<\/span>/),
|
|
306
|
+
products: products.map((p) => p.name),
|
|
307
|
+
url: `https://details.jd.com/normal/item.action?orderid=${orderId}`,
|
|
308
|
+
};
|
|
309
|
+
Object.defineProperty(order, 'skus', { value: products.map((p) => p.sku), enumerable: false });
|
|
310
|
+
orders.push(order);
|
|
311
|
+
}
|
|
312
|
+
return orders;
|
|
313
|
+
}
|
|
314
|
+
// ================================================================ 咚咚
|
|
315
|
+
const CHAT = { referer: CHAT_REFERER, origin: CHAT_ORIGIN, refererPage: CHAT_REFERER, rpClient: RP_CLIENT_CHAT, withUuid: false };
|
|
316
|
+
/** 咚咚 aid(getAidInfo),拿到后记进会话。 */
|
|
317
|
+
export async function aidInfo(jd) {
|
|
318
|
+
const body = {
|
|
319
|
+
aidClientType: 'comet',
|
|
320
|
+
aidClientVersion: 'comet -v1.0.0',
|
|
321
|
+
appId: 'im.customer',
|
|
322
|
+
os: 'comet',
|
|
323
|
+
entry: '',
|
|
324
|
+
reqSrc: 's_comet',
|
|
325
|
+
siteId: -1,
|
|
326
|
+
customerAppId: 'im.customer',
|
|
327
|
+
};
|
|
328
|
+
const res = await jd.call('getAidInfo', { body, client: CLIENT_IMH5, appId: APPID_DONGDONG, ...CHAT, withTime: true, order: ORDER_DD_WITH_TIME });
|
|
329
|
+
if (res && typeof res === 'object' && res.aid)
|
|
330
|
+
jd.setChatInfo({ aid: res.aid, app_id: 'im.customer', client_type: 'comet' });
|
|
331
|
+
else
|
|
332
|
+
jd.ctx.log.debug('getAidInfo 未返回 aid');
|
|
333
|
+
return res;
|
|
334
|
+
}
|
|
335
|
+
/** 咚咚会话初始化(getChatInfo):商家信息、会话类型、客服身份。 */
|
|
336
|
+
export function chatInfo(jd, venderId = '1', pid = '', orderId = '', shopId = '', groupId = '', entry = '') {
|
|
337
|
+
const body = {
|
|
338
|
+
lang: 'zh_CN',
|
|
339
|
+
venderId: String(venderId),
|
|
340
|
+
groupId,
|
|
341
|
+
pid,
|
|
342
|
+
ppid: '',
|
|
343
|
+
shopId,
|
|
344
|
+
siteId: -1,
|
|
345
|
+
entry,
|
|
346
|
+
orderId,
|
|
347
|
+
reqSrc: 's_comet',
|
|
348
|
+
cAppId: '',
|
|
349
|
+
bbtf: '',
|
|
350
|
+
uniformBizInfo: {},
|
|
351
|
+
customerAppId: 'im.customer',
|
|
352
|
+
};
|
|
353
|
+
return jd.call('getChatInfo', { body, client: CLIENT_WH5, appId: APPID_DONGDONG, ...CHAT, withTime: false, order: ORDER_DD_NO_TIME });
|
|
354
|
+
}
|
|
355
|
+
/** 历史会话(getChatSessionLog)。 */
|
|
356
|
+
export function chatSessionLog(jd) {
|
|
357
|
+
const body = { reqSrc: 's_comet', appId: 'im.customer', showMsg: 1, lastMsg: 1, uniformBizInfo: {}, siteId: -1, customerAppId: 'im.customer' };
|
|
358
|
+
return jd.call('getChatSessionLog', { body, client: CLIENT_IMH5, appId: APPID_DONGDONG, ...CHAT, withTime: true, order: ORDER_DD_WITH_TIME });
|
|
359
|
+
}
|
|
360
|
+
/** 咚咚历史消息(queryLastLogs)。 */
|
|
361
|
+
export function queryLastLogs(jd, venderId = '1', num = 10, startTimestamp = 0, reverse = true) {
|
|
362
|
+
const pin = jd.pin ?? '';
|
|
363
|
+
const chat = jd.chat;
|
|
364
|
+
const body = {
|
|
365
|
+
terminal: { version: 'wh5', pullType: 1 },
|
|
366
|
+
aid: chat.aid ?? '',
|
|
367
|
+
uid: { app: 'im.customer', pin, clientType: chat.client_type || 'comet', art: '' },
|
|
368
|
+
customer: pin,
|
|
369
|
+
venderId: String(venderId),
|
|
370
|
+
startTimeStamp: startTimestamp,
|
|
371
|
+
reverse: Boolean(reverse),
|
|
372
|
+
num,
|
|
373
|
+
siteId: -1,
|
|
374
|
+
customerAppId: 'im.customer',
|
|
375
|
+
};
|
|
376
|
+
return jd.call('queryLastLogs', { body, path: '/api', client: CLIENT_IMH5, appId: APPID_DONGDONG, ...CHAT, withTime: true, order: ORDER_DD_WITH_TIME });
|
|
377
|
+
}
|
|
378
|
+
// ================================================================ WebM 指纹与搜索风控(605)
|
|
379
|
+
const WEBM_VERSION = '6.0.0-exact-1';
|
|
380
|
+
/**
|
|
381
|
+
* 跑官方 jdwebm.js 生成 `shshshfpb`(ensure_webm_token):先取加密的采集配置,再把采集结果交给 wsgw_getinfo。
|
|
382
|
+
* 有效期内直接复用。
|
|
383
|
+
*/
|
|
384
|
+
export async function ensureWebmToken(jd, keyword = '', force = false) {
|
|
385
|
+
let fpa = String(jd.cookie('shshshfpa') ?? '');
|
|
386
|
+
const fpx = String(jd.cookie('shshshfpx') ?? '');
|
|
387
|
+
if (!fpa) {
|
|
388
|
+
const raw = rand.hex(16);
|
|
389
|
+
fpa = `${raw.slice(0, 8)}-${raw.slice(8, 12)}-${raw.slice(12, 16)}-${raw.slice(16, 20)}-${raw.slice(20)}-${rand.nowSeconds()}`;
|
|
390
|
+
jd.update([['shshshfpa', fpa]]);
|
|
391
|
+
}
|
|
392
|
+
if (!fpx)
|
|
393
|
+
jd.update([['shshshfpx', fpa]]);
|
|
394
|
+
const pageUrl = searchReferer(jd, keyword);
|
|
395
|
+
const storage = jd.localStorageFor(pageUrl);
|
|
396
|
+
const validUntil = Number.parseInt(storage.hf_time ?? '0', 10) || 0;
|
|
397
|
+
const current = String(jd.cookie('shshshfpb') ?? '');
|
|
398
|
+
if (current && !force && storage.__jdapis_webm_runtime__ === WEBM_VERSION && validUntil > rand.now()) {
|
|
399
|
+
return { code: 0, cached: true, token_length: current.length };
|
|
400
|
+
}
|
|
401
|
+
const now = rand.now();
|
|
402
|
+
let configData = '';
|
|
403
|
+
try {
|
|
404
|
+
const h = xhr({ accept: 'application/json' }).referer(pageUrl).origin(SEARCH_ORIGIN);
|
|
405
|
+
const res = await jd.send({
|
|
406
|
+
url: `${API_URL}/`,
|
|
407
|
+
headers: h.get(),
|
|
408
|
+
query: [
|
|
409
|
+
['appid', 'risk_h5_info'],
|
|
410
|
+
['functionId', 'getCustomCtrl'],
|
|
411
|
+
['t', String(now)],
|
|
412
|
+
['body', '{"domain":".jd.com"}'],
|
|
413
|
+
],
|
|
414
|
+
});
|
|
415
|
+
const r = (await res.json());
|
|
416
|
+
if (r?.code === 0)
|
|
417
|
+
configData = String(r.data ?? '');
|
|
418
|
+
}
|
|
419
|
+
catch (err) {
|
|
420
|
+
jd.ctx.log.warn(`WebM 控制配置获取失败:${err.name}`);
|
|
421
|
+
}
|
|
422
|
+
let result;
|
|
423
|
+
try {
|
|
424
|
+
const runtimeStorage = { ...storage };
|
|
425
|
+
if (force) {
|
|
426
|
+
delete runtimeStorage.hf_time;
|
|
427
|
+
delete runtimeStorage.__jdapis_webm_runtime__;
|
|
428
|
+
}
|
|
429
|
+
const payload = await buildSearchPayload(jd, pageUrl, configData, runtimeStorage);
|
|
430
|
+
const h = xhr({ form: true, accept: 'application/json' }).referer(pageUrl).origin(SEARCH_ORIGIN);
|
|
431
|
+
const res = await jd.send({
|
|
432
|
+
method: 'POST',
|
|
433
|
+
url: `${API_URL}/`,
|
|
434
|
+
headers: h.get(),
|
|
435
|
+
form: [
|
|
436
|
+
['appid', 'risk_h5'],
|
|
437
|
+
['functionId', 'wsgw_getinfo'],
|
|
438
|
+
['t', String(rand.now())],
|
|
439
|
+
['body', JSON.stringify(payload)],
|
|
440
|
+
],
|
|
441
|
+
});
|
|
442
|
+
result = await res.json();
|
|
443
|
+
}
|
|
444
|
+
catch (err) {
|
|
445
|
+
jd.ctx.log.warn(`WebM 指纹初始化失败:${err.message}`);
|
|
446
|
+
return { code: -1, error: err.name };
|
|
447
|
+
}
|
|
448
|
+
const token = String(result?.whwswswws ?? '');
|
|
449
|
+
if (result?.code === 0 && token) {
|
|
450
|
+
jd.update([['shshshfpb', token]]);
|
|
451
|
+
const runtimeStorage = jd.localStorageFor(pageUrl);
|
|
452
|
+
runtimeStorage.__jdapis_webm_runtime__ = WEBM_VERSION;
|
|
453
|
+
let interval = Number.parseInt(String(result.interval ?? ''), 10);
|
|
454
|
+
interval = Number.isFinite(interval) && interval ? Math.max(1, interval) : 24 * 60;
|
|
455
|
+
runtimeStorage.hf_time = String(rand.now() + interval * 60_000);
|
|
456
|
+
jd.replaceLocalStorage(pageUrl, runtimeStorage);
|
|
457
|
+
return { code: 0, cached: false, token_length: token.length };
|
|
458
|
+
}
|
|
459
|
+
jd.ctx.log.warn(`WebM 指纹初始化未返回令牌:code=${result?.code}`);
|
|
460
|
+
return { code: result?.code ?? null, cached: false, token_length: 0 };
|
|
461
|
+
}
|
|
462
|
+
/** 605 处置里的风险页上下文 URL(verification_url)。 */
|
|
463
|
+
export function verificationUrl(res, referer) {
|
|
464
|
+
const disposal = res?.disposal ?? {};
|
|
465
|
+
let ev;
|
|
466
|
+
try {
|
|
467
|
+
ev = jsonLoads(disposal.evContent || '{}');
|
|
468
|
+
}
|
|
469
|
+
catch {
|
|
470
|
+
return '';
|
|
471
|
+
}
|
|
472
|
+
if (!ev.evUrl)
|
|
473
|
+
return '';
|
|
474
|
+
return (ev.evUrl +
|
|
475
|
+
'?' +
|
|
476
|
+
urlencode([
|
|
477
|
+
['returnurl', referer],
|
|
478
|
+
['rqhost', API_URL],
|
|
479
|
+
['rpid', disposal.rpId ?? ''],
|
|
480
|
+
['evtype', ev.evType ?? '2'],
|
|
481
|
+
['evapi', ev.evApi ?? ''],
|
|
482
|
+
['source', '1'],
|
|
483
|
+
['forceCurrentView', '1'],
|
|
484
|
+
['evsid', ev.evSid || ''],
|
|
485
|
+
]));
|
|
486
|
+
}
|
|
487
|
+
/** 风险页 eid 取自 unionwsws(_risk_page_eid)。 */
|
|
488
|
+
function riskPageEid(jd) {
|
|
489
|
+
const value = String(jd.cookie('unionwsws') ?? '');
|
|
490
|
+
if (!value)
|
|
491
|
+
return '';
|
|
492
|
+
try {
|
|
493
|
+
const parsed = jsonLoads(decodeURIComponent(value));
|
|
494
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? String(parsed.devicefinger ?? '') : '';
|
|
495
|
+
}
|
|
496
|
+
catch {
|
|
497
|
+
return '';
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const JS_SAFE = "~()*!.'-";
|
|
501
|
+
/** 搜索 605:createSid → JCAP → checkToken,成功后保存 x-rp-evtoken(solve_search_risk)。 */
|
|
502
|
+
export async function solveSearchRisk(jd, response, keyword = '', attempts = 3) {
|
|
503
|
+
const disposal = response?.disposal;
|
|
504
|
+
if (!disposal || typeof disposal !== 'object')
|
|
505
|
+
return { code: -1, stage: 'disposal' };
|
|
506
|
+
let event;
|
|
507
|
+
try {
|
|
508
|
+
event = jsonLoads(disposal.evContent || '{}');
|
|
509
|
+
}
|
|
510
|
+
catch {
|
|
511
|
+
return { code: -1, stage: 'disposal' };
|
|
512
|
+
}
|
|
513
|
+
const pageUrl = verificationUrl(response, searchReferer(jd, keyword));
|
|
514
|
+
if (!pageUrl || !disposal.rpId)
|
|
515
|
+
return { code: -1, stage: 'disposal' };
|
|
516
|
+
await ensureWebmToken(jd, keyword);
|
|
517
|
+
const common = {
|
|
518
|
+
requestId: disposal.rpId || '',
|
|
519
|
+
evApi: quote(String(event.evApi ?? ''), JS_SAFE),
|
|
520
|
+
evType: String(event.evType || '2'),
|
|
521
|
+
shshshfpx: jd.cookie('shshshfpx') || '',
|
|
522
|
+
eid: riskPageEid(jd),
|
|
523
|
+
evSid: event.evSid || '',
|
|
524
|
+
};
|
|
525
|
+
try {
|
|
526
|
+
const created = await jd.riskPost(pageUrl, 'createSid', common);
|
|
527
|
+
const sid = String(created?.data ?? '');
|
|
528
|
+
if (created?.code !== 0 || !sid)
|
|
529
|
+
return { code: created?.code ?? null, stage: 'createSid' };
|
|
530
|
+
const token = await solveCaptcha(jd, { sessionId: sid, account: '', pageUrl, attempts });
|
|
531
|
+
let pin = jd.cookie('pwdt_id') || jd.cookie('pin') || jd.cookie('pt_pin') || '';
|
|
532
|
+
if (pin.includes('*'))
|
|
533
|
+
pin = '';
|
|
534
|
+
const checked = await jd.riskPost(pageUrl, 'checkToken', { sid, token: quote(token, JS_SAFE), ...common, pin });
|
|
535
|
+
const evToken = String(checked?.data ?? '');
|
|
536
|
+
if (checked?.code !== 0 || !evToken)
|
|
537
|
+
return { code: checked?.code ?? null, stage: 'checkToken' };
|
|
538
|
+
jd.update([['x-rp-evtoken', evToken]]);
|
|
539
|
+
return { code: 0, stage: 'complete', token_length: evToken.length };
|
|
540
|
+
}
|
|
541
|
+
catch (err) {
|
|
542
|
+
const out = { code: -1, stage: 'jcap', error: err.name, message: err.message };
|
|
543
|
+
const m = /"sCode":(\d+)/.exec(String(err.message));
|
|
544
|
+
if (m)
|
|
545
|
+
out.service_subcode = Number(m[1]);
|
|
546
|
+
jd.ctx.log.warn(`纯程序搜索验证未通过:${err.message}`);
|
|
547
|
+
return out;
|
|
548
|
+
}
|
|
549
|
+
}
|