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,312 @@
|
|
|
1
|
+
import { SpecificAIError } from '../../../core/errors.js';
|
|
2
|
+
import { jsonDumps, pyStr, quote } from '../../../core/py.js';
|
|
3
|
+
import * as rand from '../../../core/rand.js';
|
|
4
|
+
import {} from './client.js';
|
|
5
|
+
import { API_HEADERS, APP_KEY, H5API, IM_APP_KEY, LOCATION_HEADERS, merge, PASSPORT, PASSPORT_HEADERS, SESSION_HEADERS, TOKEN_HEADERS, UA, UPLOAD_HEADERS, UPLOAD_URL, } from './profile.js';
|
|
6
|
+
import { generateSign } from './sign.js';
|
|
7
|
+
const IM_SPM = { spmCnt: 'a21ybx.im.0.0', spmPre: 'a21ybx.item.want.1.12523da6waCtUp', logId: '12523da6waCtUp' };
|
|
8
|
+
function query(api, t, sign, o) {
|
|
9
|
+
const q = [
|
|
10
|
+
['jsv', '2.7.2'],
|
|
11
|
+
['appKey', APP_KEY],
|
|
12
|
+
['t', t],
|
|
13
|
+
];
|
|
14
|
+
if (!o.signLast)
|
|
15
|
+
q.push(['sign', sign]);
|
|
16
|
+
q.push(['v', o.v ?? '1.0'], ['type', 'originaljson'], ['accountSite', 'xianyu'], ['dataType', 'json'], ['timeout', '20000'], ['api', api], ['sessionOption', 'AutoLoginOnly'], ['spm_cnt', o.spmCnt], ['spm_pre', o.spmPre], ['log_id', o.logId]);
|
|
17
|
+
if (o.signLast)
|
|
18
|
+
q.push(['sign', sign]);
|
|
19
|
+
return q;
|
|
20
|
+
}
|
|
21
|
+
/** 签名的 mtop POST:`t` 是秒数乘 1000(上游 `str(int(time.time()) * 1000)`),表单只有一个 data 字段。 */
|
|
22
|
+
function signed(x, api, dataVal, headers, o) {
|
|
23
|
+
return x.mtop((token) => {
|
|
24
|
+
const t = String(rand.nowSeconds() * 1000);
|
|
25
|
+
return {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
url: `${H5API}/${api}/${o.v ?? '1.0'}/`,
|
|
28
|
+
query: query(api, t, generateSign(t, token, dataVal), o),
|
|
29
|
+
headers,
|
|
30
|
+
form: [['data', dataVal]],
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// ================================================================ XianyuApis
|
|
35
|
+
/** 私信的 accessToken(上游 get_token)。 */
|
|
36
|
+
export function getToken(x) {
|
|
37
|
+
const dataVal = '{"appKey":"' + IM_APP_KEY + '","deviceId":"' + x.deviceId + '"}';
|
|
38
|
+
return signed(x, 'mtop.taobao.idlemessage.pc.login.token', dataVal, TOKEN_HEADERS, {
|
|
39
|
+
spmCnt: 'a21ybx.im.0.0',
|
|
40
|
+
spmPre: 'a21ybx.item.want.1.14ad3da6ALVq3n',
|
|
41
|
+
logId: '14ad3da6ALVq3n',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** 当前登录用户,同时续期 cookie(上游 refresh_token,常驻进程每 10 分钟调一次)。 */
|
|
45
|
+
export function refreshToken(x) {
|
|
46
|
+
return signed(x, 'mtop.taobao.idlemessage.pc.loginuser.get', '{}', API_HEADERS, { ...IM_SPM, signLast: true });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 商品详情(上游 get_item_info)。上游这个请求本身不带请求头,只有 session 上的 User-Agent
|
|
50
|
+
* (扫码登录、游客的 session 来自 build_initial_cookies)。实测游客带上 Origin / Referer / sec-ch-ua
|
|
51
|
+
* 这组浏览器头反而会被风控(RGV587),照上游只发 UA。
|
|
52
|
+
*/
|
|
53
|
+
export function itemInfo(x, itemId) {
|
|
54
|
+
return signed(x, 'mtop.taobao.idle.pc.detail', '{"itemId":"' + itemId + '"}', SESSION_HEADERS, IM_SPM);
|
|
55
|
+
}
|
|
56
|
+
function imageInfo(image) {
|
|
57
|
+
return {
|
|
58
|
+
extraInfo: { isH: 'false', isT: 'false', raw: 'false' },
|
|
59
|
+
isQrCode: false,
|
|
60
|
+
url: image.url,
|
|
61
|
+
heightSize: image.height,
|
|
62
|
+
widthSize: image.width,
|
|
63
|
+
major: true,
|
|
64
|
+
type: 0,
|
|
65
|
+
status: 'done',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** 按标题和图片推荐类目与属性(上游 get_public_channel)。 */
|
|
69
|
+
export function publicChannel(x, title, images) {
|
|
70
|
+
const data = {
|
|
71
|
+
title,
|
|
72
|
+
lockCpv: false,
|
|
73
|
+
multiSKU: false,
|
|
74
|
+
publishScene: 'mainPublish',
|
|
75
|
+
scene: 'newPublishChoice',
|
|
76
|
+
description: title,
|
|
77
|
+
imageInfos: images.map(imageInfo),
|
|
78
|
+
uniqueCode: '1775905618164677',
|
|
79
|
+
};
|
|
80
|
+
return signed(x, 'mtop.taobao.idle.kgraph.property.recommend', jsonDumps(data, { separators: [',', ':'] }), API_HEADERS, {
|
|
81
|
+
v: '2.0',
|
|
82
|
+
spmCnt: 'a21ybx.publish.0.0',
|
|
83
|
+
spmPre: 'a21ybx.item.sidebar.1.67321598K9Vgx8',
|
|
84
|
+
logId: '67321598K9Vgx8',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** 发布地址:上游写死了一个坐标,取返回的第一个常用地址(上游 get_default_location)。 */
|
|
88
|
+
export function defaultLocation(x) {
|
|
89
|
+
return signed(x, 'mtop.taobao.idle.local.poi.get', '{"longitude":118.78248347393424,"latitude":31.91629189813543}', LOCATION_HEADERS, {
|
|
90
|
+
spmCnt: 'a21ybx.publish.0.0',
|
|
91
|
+
spmPre: 'a21ybx.item.sidebar.1.38262218ame5nr',
|
|
92
|
+
logId: '38262218ame5nr',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** 上传图片(上游 upload_media)。content type 上游固定写 image/png。 */
|
|
96
|
+
export async function uploadMedia(x, file) {
|
|
97
|
+
const res = await x.http.json({
|
|
98
|
+
method: 'POST',
|
|
99
|
+
url: UPLOAD_URL,
|
|
100
|
+
query: [
|
|
101
|
+
['floderId', '0'],
|
|
102
|
+
['appkey', 'xy_chat'],
|
|
103
|
+
['_input_charset', 'utf-8'],
|
|
104
|
+
],
|
|
105
|
+
headers: UPLOAD_HEADERS,
|
|
106
|
+
multipart: [{ name: 'file', filename: file.filename, contentType: 'image/png', data: file.data }],
|
|
107
|
+
});
|
|
108
|
+
if (!res?.object?.url)
|
|
109
|
+
throw new SpecificAIError('UPSTREAM', `上传失败:${res?.message ?? res?.errorMessage ?? '响应里没有 object.url'}`, { detail: res });
|
|
110
|
+
return res;
|
|
111
|
+
}
|
|
112
|
+
/** 发布闲置(上游 public):先传图,再按标题推荐类目、取默认地址,最后提交。 */
|
|
113
|
+
export async function publish(x, input) {
|
|
114
|
+
const data = {
|
|
115
|
+
freebies: false,
|
|
116
|
+
itemTypeStr: 'b',
|
|
117
|
+
quantity: '1',
|
|
118
|
+
simpleItem: 'true',
|
|
119
|
+
imageInfoDOList: [],
|
|
120
|
+
itemTextDTO: { desc: input.desc, title: input.desc, titleDescSeparate: false },
|
|
121
|
+
itemLabelExtList: [],
|
|
122
|
+
itemPriceDTO: {},
|
|
123
|
+
userRightsProtocols: [{ enable: false, serviceCode: 'SKILL_PLAY_NO_MIND' }],
|
|
124
|
+
itemPostFeeDTO: { canFreeShipping: false, supportFreight: false, onlyTakeSelf: false },
|
|
125
|
+
itemAddrDTO: {},
|
|
126
|
+
defaultPrice: false,
|
|
127
|
+
itemCatDTO: {},
|
|
128
|
+
uniqueCode: '1775897582791680',
|
|
129
|
+
sourceId: 'pcMainPublish',
|
|
130
|
+
bizcode: 'pcMainPublish',
|
|
131
|
+
publishScene: 'pcMainPublish',
|
|
132
|
+
};
|
|
133
|
+
const images = [];
|
|
134
|
+
for (const file of input.images) {
|
|
135
|
+
const obj = (await uploadMedia(x, file)).object;
|
|
136
|
+
const [width, height] = String(obj.pix).split('x').map((s) => Math.trunc(Number(s)));
|
|
137
|
+
const image = { url: obj.url, height: height, width: width };
|
|
138
|
+
images.push(image);
|
|
139
|
+
data.imageInfoDOList.push(imageInfo(image));
|
|
140
|
+
}
|
|
141
|
+
const fee = data.itemPostFeeDTO;
|
|
142
|
+
if (input.shipping === 'free') {
|
|
143
|
+
fee.canFreeShipping = true;
|
|
144
|
+
fee.supportFreight = true;
|
|
145
|
+
}
|
|
146
|
+
else if (input.shipping === 'distance') {
|
|
147
|
+
fee.supportFreight = true;
|
|
148
|
+
fee.templateId = '-100';
|
|
149
|
+
}
|
|
150
|
+
else if (input.shipping === 'fixed') {
|
|
151
|
+
fee.supportFreight = true;
|
|
152
|
+
fee.postPriceInCent = String(Math.trunc(input.postage * 100));
|
|
153
|
+
fee.templateId = '0';
|
|
154
|
+
}
|
|
155
|
+
else
|
|
156
|
+
fee.templateId = '0';
|
|
157
|
+
// 上游写在顶层,不是 itemPostFeeDTO 里(照抄)
|
|
158
|
+
if (input.pickup)
|
|
159
|
+
data.onlyTakeSelf = true;
|
|
160
|
+
if (input.price) {
|
|
161
|
+
if (input.price.current > 0)
|
|
162
|
+
data.itemPriceDTO.priceInCent = String(Math.trunc(input.price.current * 100));
|
|
163
|
+
if (input.price.original > 0)
|
|
164
|
+
data.itemPriceDTO.origPriceInCent = String(Math.trunc(input.price.original * 100));
|
|
165
|
+
}
|
|
166
|
+
else
|
|
167
|
+
data.defaultPrice = true;
|
|
168
|
+
const channel = (await publicChannel(x, input.desc, images)).data;
|
|
169
|
+
for (const card of channel.cardList ?? []) {
|
|
170
|
+
const cd = card.cardData;
|
|
171
|
+
for (const value of cd.valuesList ?? []) {
|
|
172
|
+
if (!value.isClicked)
|
|
173
|
+
continue;
|
|
174
|
+
data.itemLabelExtList.push({
|
|
175
|
+
channelCateName: value.catName,
|
|
176
|
+
valueId: null,
|
|
177
|
+
channelCateId: value.channelCatId,
|
|
178
|
+
valueName: null,
|
|
179
|
+
tbCatId: value.tbCatId,
|
|
180
|
+
subPropertyId: null,
|
|
181
|
+
labelType: 'common',
|
|
182
|
+
subValueId: null,
|
|
183
|
+
labelId: null,
|
|
184
|
+
propertyName: cd.propertyName,
|
|
185
|
+
isUserClick: '1',
|
|
186
|
+
isUserCancel: null,
|
|
187
|
+
from: 'newPublishChoice',
|
|
188
|
+
propertyId: cd.propertyId,
|
|
189
|
+
labelFrom: 'newPublish',
|
|
190
|
+
text: value.catName,
|
|
191
|
+
properties: `${pyStr(cd.propertyId)}##${pyStr(cd.propertyName)}:${pyStr(value.channelCatId)}##${pyStr(value.catName)}`,
|
|
192
|
+
});
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const cat = channel.categoryPredictResult;
|
|
197
|
+
data.itemCatDTO = { catId: pyStr(cat.catId), catName: pyStr(cat.catName), channelCatId: pyStr(cat.channelCatId), tbCatId: pyStr(cat.tbCatId) };
|
|
198
|
+
const loc = (await defaultLocation(x)).data.commonAddresses[0];
|
|
199
|
+
data.itemAddrDTO = {
|
|
200
|
+
area: loc.area,
|
|
201
|
+
city: loc.city,
|
|
202
|
+
divisionId: loc.divisionId,
|
|
203
|
+
gps: `${pyStr(loc.longitude)},${pyStr(loc.latitude)}`,
|
|
204
|
+
poiId: loc.poiId,
|
|
205
|
+
poiName: loc.poi,
|
|
206
|
+
prov: loc.prov,
|
|
207
|
+
};
|
|
208
|
+
return signed(x, 'mtop.idle.pc.idleitem.publish', jsonDumps(data, { separators: [',', ':'] }), API_HEADERS, {
|
|
209
|
+
spmCnt: 'a21ybx.publish.0.0',
|
|
210
|
+
spmPre: 'a21ybx.home.sidebar.1.46413da6EPl7v5',
|
|
211
|
+
logId: '46413da6EPl7v5',
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
// ================================================================ 扫码登录(上游 qrcode_login)
|
|
215
|
+
const BIZ_PARAMS = `taobaoBizLoginFrom=web&renderRefer=${quote('https://www.goofish.com/')}`;
|
|
216
|
+
const MINI_LOGIN = `${PASSPORT}/mini_login.htm`;
|
|
217
|
+
const passportHeaders = (extra) => merge(SESSION_HEADERS, merge(PASSPORT_HEADERS, extra));
|
|
218
|
+
/** 加载 mini_login 页面,拿 passport 域的 XSRF-TOKEN 等 cookie。 */
|
|
219
|
+
export function miniLogin(x) {
|
|
220
|
+
return x.http.request({
|
|
221
|
+
url: MINI_LOGIN,
|
|
222
|
+
query: [
|
|
223
|
+
['lang', 'zh_cn'],
|
|
224
|
+
['appName', 'xianyu'],
|
|
225
|
+
['appEntrance', 'web'],
|
|
226
|
+
['styleType', 'vertical'],
|
|
227
|
+
['bizParams', ''],
|
|
228
|
+
['notLoadSsoView', 'false'],
|
|
229
|
+
['notKeepLogin', 'false'],
|
|
230
|
+
['isMobile', 'false'],
|
|
231
|
+
['qrCodeFirst', 'false'],
|
|
232
|
+
['stie', '77'],
|
|
233
|
+
['rnd', '0.6842814084442211'],
|
|
234
|
+
],
|
|
235
|
+
headers: passportHeaders([
|
|
236
|
+
['Referer', 'https://www.goofish.com/'],
|
|
237
|
+
['sec-fetch-site', 'same-site'],
|
|
238
|
+
['sec-fetch-dest', 'iframe'],
|
|
239
|
+
['sec-fetch-mode', 'navigate'],
|
|
240
|
+
]),
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
function loginParams(csrf, cookie2) {
|
|
244
|
+
return [
|
|
245
|
+
['appName', 'xianyu'],
|
|
246
|
+
['fromSite', '77'],
|
|
247
|
+
['appEntrance', 'web'],
|
|
248
|
+
['_csrf_token', csrf],
|
|
249
|
+
['umidToken', ''],
|
|
250
|
+
['hsiz', cookie2],
|
|
251
|
+
['bizParams', BIZ_PARAMS],
|
|
252
|
+
['mainPage', 'false'],
|
|
253
|
+
['isMobile', 'false'],
|
|
254
|
+
['lang', 'zh_CN'],
|
|
255
|
+
['returnUrl', ''],
|
|
256
|
+
['umidTag', 'SERVER'],
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
/** 生成二维码。 */
|
|
260
|
+
export async function qrGenerate(x, csrf, cookie2) {
|
|
261
|
+
const res = await x.http.json({
|
|
262
|
+
url: `${PASSPORT}/newlogin/qrcode/generate.do`,
|
|
263
|
+
query: loginParams(csrf, cookie2),
|
|
264
|
+
headers: passportHeaders([['Referer', MINI_LOGIN]]),
|
|
265
|
+
});
|
|
266
|
+
const data = res?.content?.data;
|
|
267
|
+
if (!data?.codeContent)
|
|
268
|
+
throw new SpecificAIError('UPSTREAM', '生成二维码失败', { detail: res });
|
|
269
|
+
return data;
|
|
270
|
+
}
|
|
271
|
+
const postHeaders = () => passportHeaders([
|
|
272
|
+
['Content-Type', 'application/x-www-form-urlencoded'],
|
|
273
|
+
['Origin', PASSPORT],
|
|
274
|
+
['Referer', MINI_LOGIN],
|
|
275
|
+
]);
|
|
276
|
+
/** 查询扫码状态:NEW / SCANNED / CONFIRMED / EXPIRED。 */
|
|
277
|
+
export async function qrQuery(x, csrf, cookie2, cna, qr) {
|
|
278
|
+
const res = await x.http.json({
|
|
279
|
+
method: 'POST',
|
|
280
|
+
url: `${PASSPORT}/newlogin/qrcode/query.do?appName=xianyu&fromSite=77`,
|
|
281
|
+
form: [
|
|
282
|
+
...loginParams(csrf, cookie2),
|
|
283
|
+
['navlanguage', 'en'],
|
|
284
|
+
['navUserAgent', UA],
|
|
285
|
+
['navPlatform', 'Win32'],
|
|
286
|
+
['isIframe', 'true'],
|
|
287
|
+
['documentReferer', 'https://www.goofish.com/'],
|
|
288
|
+
['defaultView', 'sms'],
|
|
289
|
+
['deviceId', cna],
|
|
290
|
+
['t', pyStr(qr.t)],
|
|
291
|
+
['ck', qr.ck],
|
|
292
|
+
],
|
|
293
|
+
headers: postHeaders(),
|
|
294
|
+
});
|
|
295
|
+
return res?.content?.data ?? {};
|
|
296
|
+
}
|
|
297
|
+
/** 用扫码确认后的 token 完成登录。 */
|
|
298
|
+
export function loginByToken(x, token, cna) {
|
|
299
|
+
return x.http.request({
|
|
300
|
+
method: 'POST',
|
|
301
|
+
url: `${PASSPORT}/login_token/login.do`,
|
|
302
|
+
query: [
|
|
303
|
+
['token', token],
|
|
304
|
+
['subFlow', 'DIALOG_CHECK_LOGIN_RPC'],
|
|
305
|
+
['nextCode', '0018'],
|
|
306
|
+
['bizScene', 'qrcode'],
|
|
307
|
+
['confirm', 'true'],
|
|
308
|
+
],
|
|
309
|
+
form: [['deviceId', cna]],
|
|
310
|
+
headers: postHeaders(),
|
|
311
|
+
});
|
|
312
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { SpecificAIError } from '../../../core/errors.js';
|
|
2
|
+
import { parseJson } from '../../../core/http.js';
|
|
3
|
+
import { unquote } from '../../../core/py.js';
|
|
4
|
+
import * as rand from '../../../core/rand.js';
|
|
5
|
+
import { authError, httpClient } from '../../../core/toolkit.js';
|
|
6
|
+
import { APP_KEY, BROWSER, COOKIE_DOMAIN, H5API, merge, MTOP_HEADERS, SESSION_HEADERS, userUrl } from './profile.js';
|
|
7
|
+
import { generateDeviceId, genTfstk } from './sign.js';
|
|
8
|
+
/** 令牌过期 / 为空:响应的 Set-Cookie 已经带来新的 `_m_h5_tk`,换新令牌重签一次。 */
|
|
9
|
+
const TOKEN_RE = /FAIL_SYS_TOKEN_EXOIRED|FAIL_SYS_TOKEN_EMPTY|FAIL_SYS_TOKEN_ILLEGAL|令牌过期|令牌为空/;
|
|
10
|
+
const SESSION_RE = /FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED|FAIL_SYS_LOGIN|未登录|请重新登录|请登录/;
|
|
11
|
+
const CAPTCHA_RE = /RGV587_ERROR|FAIL_SYS_USER_VALIDATE/;
|
|
12
|
+
const LIMIT_RE = /FAIL_SYS_TRAFFIC_LIMIT|FAIL_SYS_FLOWLIMIT/;
|
|
13
|
+
export class Xianyu {
|
|
14
|
+
ctx;
|
|
15
|
+
http;
|
|
16
|
+
jar;
|
|
17
|
+
constructor(ctx) {
|
|
18
|
+
this.ctx = ctx;
|
|
19
|
+
this.http = httpClient(ctx, { browser: BROWSER, os: 'windows' });
|
|
20
|
+
this.jar = this.http.jar;
|
|
21
|
+
}
|
|
22
|
+
/** 当前账号的用户 ID(cookie `unb`)。 */
|
|
23
|
+
get myId() {
|
|
24
|
+
return this.jar.get('unb') ?? '';
|
|
25
|
+
}
|
|
26
|
+
/** 昵称(cookie `tracknick`,可能是 URL 编码或 `\uXXXX` 转义过的)。 */
|
|
27
|
+
get nick() {
|
|
28
|
+
const raw = this.jar.get('tracknick');
|
|
29
|
+
if (!raw)
|
|
30
|
+
return null;
|
|
31
|
+
const s = unquote(raw);
|
|
32
|
+
return s.replace(/\\u([0-9a-fA-F]{4})/g, (_, h) => String.fromCharCode(parseInt(h, 16)));
|
|
33
|
+
}
|
|
34
|
+
me() {
|
|
35
|
+
return { id: this.myId, name: this.nick, url: userUrl(this.myId) };
|
|
36
|
+
}
|
|
37
|
+
/** 私信用的设备 ID:上游每次按 `unb` 随机生成;这里生成一次后存在凭证的 device 里。 */
|
|
38
|
+
get deviceId() {
|
|
39
|
+
const device = this.ctx.credential.device;
|
|
40
|
+
return (device.device_id ??= generateDeviceId(this.myId));
|
|
41
|
+
}
|
|
42
|
+
/** mtop 签名用的令牌:cookie `_m_h5_tk` 下划线前的部分,没有(或已过期)时为空串。 */
|
|
43
|
+
token() {
|
|
44
|
+
const c = this.jar.forUrl(`${H5API}/`).find((x) => x.name === '_m_h5_tk');
|
|
45
|
+
return (c?.value ?? '').split('_')[0];
|
|
46
|
+
}
|
|
47
|
+
/** 全部 cookie 拼成一个 Cookie 头(上游 get_session_cookies_str,不分域名)。 */
|
|
48
|
+
cookieString() {
|
|
49
|
+
return Object.entries(this.jar.toObject())
|
|
50
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
51
|
+
.join('; ');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 纯 HTTP 获取初始 cookie,不含登录态(上游 build_initial_cookies,扫码登录前用):
|
|
55
|
+
* eg.js 拿 `cna`,两次空签名的 mtop 拿 `_m_h5_tk` 和 `cookie2`,最后跑 JS 生成 `tfstk`。
|
|
56
|
+
*/
|
|
57
|
+
async buildInitialCookies() {
|
|
58
|
+
await this.http.request({ url: 'https://log.mmstat.com/eg.js', headers: SESSION_HEADERS });
|
|
59
|
+
const cna = this.jar.get('cna', '.mmstat.com');
|
|
60
|
+
if (cna)
|
|
61
|
+
this.jar.set('cna', cna, COOKIE_DOMAIN);
|
|
62
|
+
for (const api of ['mtop.taobao.idlehome.home.webpc.feed', 'mtop.gaia.nodejs.gaia.idle.data.gw.v2.index.get']) {
|
|
63
|
+
await this.http.request(unsignedMtop(api));
|
|
64
|
+
}
|
|
65
|
+
const tfstk = await genTfstk((line) => this.ctx.log.debug(line));
|
|
66
|
+
if (tfstk)
|
|
67
|
+
this.jar.set('tfstk', tfstk, COOKIE_DOMAIN);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 发一个 mtop 请求并检查业务码。build 拿当前令牌构造请求(签名在里面算);
|
|
71
|
+
* 令牌过期或为空时用 Set-Cookie 带回的新令牌重签一次(上游只在 get_token 里这样做)。
|
|
72
|
+
*/
|
|
73
|
+
async mtop(build) {
|
|
74
|
+
for (let attempt = 0;; attempt++) {
|
|
75
|
+
const body = await parseJson(await this.http.request(build(this.token())));
|
|
76
|
+
const ret = (body.ret ?? []).join(';');
|
|
77
|
+
if (attempt === 0 && TOKEN_RE.test(ret)) {
|
|
78
|
+
this.ctx.log.debug(`mtop 令牌失效,重签:${ret}`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
check(this.ctx, body);
|
|
82
|
+
return body;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** 写操作和私信前检查登录态(registry 已保证不是游客,这里防 cookie 不全)。 */
|
|
86
|
+
requireLogin() {
|
|
87
|
+
if (!this.myId)
|
|
88
|
+
throw authError(this.ctx, '当前账号的 cookie 里没有 unb,请重新登录');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** 空签名的 mtop 请求(build_initial_cookies、qrcode_login 最后一步),只为拿响应里的 cookie。 */
|
|
92
|
+
export function unsignedMtop(api) {
|
|
93
|
+
return {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
url: `${H5API}/${api}/1.0/`,
|
|
96
|
+
query: [
|
|
97
|
+
['jsv', '2.7.2'],
|
|
98
|
+
['appKey', APP_KEY],
|
|
99
|
+
['t', String(rand.now())],
|
|
100
|
+
['sign', ''],
|
|
101
|
+
['v', '1.0'],
|
|
102
|
+
['type', 'originaljson'],
|
|
103
|
+
['dataType', 'json'],
|
|
104
|
+
['timeout', '20000'],
|
|
105
|
+
['api', api],
|
|
106
|
+
['sessionOption', 'AutoLoginOnly'],
|
|
107
|
+
['spm_cnt', 'a21ybx.home.0.0'],
|
|
108
|
+
],
|
|
109
|
+
body: 'data=%7B%7D',
|
|
110
|
+
headers: merge(SESSION_HEADERS, MTOP_HEADERS),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** mtop 的 ret 映射成 specific-ai 的错误(AGENTS 6.4)。 */
|
|
114
|
+
function check(ctx, body) {
|
|
115
|
+
const ret = body?.ret ?? [];
|
|
116
|
+
const first = String(ret[0] ?? '');
|
|
117
|
+
if (first.startsWith('SUCCESS'))
|
|
118
|
+
return;
|
|
119
|
+
const all = ret.join(';');
|
|
120
|
+
const message = first.split('::').slice(1).join('::') || first || '闲鱼返回了空的 ret';
|
|
121
|
+
const detail = { ret, api: body?.api ?? null };
|
|
122
|
+
if (SESSION_RE.test(all))
|
|
123
|
+
throw authError(ctx, `闲鱼登录态无效:${message}`);
|
|
124
|
+
if (CAPTCHA_RE.test(all)) {
|
|
125
|
+
throw new SpecificAIError('RISK_CONTROL', `闲鱼风控拦截,需要滑块验证:${message}`, { detail: { kind: 'captcha', ...detail, url: body?.data?.url ?? null } });
|
|
126
|
+
}
|
|
127
|
+
if (LIMIT_RE.test(all))
|
|
128
|
+
throw new SpecificAIError('RISK_CONTROL', `闲鱼限流:${message}`, { detail: { kind: 'rate_limit', ...detail } });
|
|
129
|
+
throw new SpecificAIError('UPSTREAM', `闲鱼返回错误:${message}`, { detail });
|
|
130
|
+
}
|
|
131
|
+
/** 建立会话。web 端不支持游客态(AGENTS 5.2),除 auth 外的命令都已登录。 */
|
|
132
|
+
export function xianyu(ctx) {
|
|
133
|
+
return new Xianyu(ctx);
|
|
134
|
+
}
|