array-golden.mjs
2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* 数组参数的线上字节钉值:固定 timestamp 后发一次真实请求,让网关自己认证这份 sign。
* 用法:node out/.temp/array-golden.mjs <sessionId>
* 只读金额合计接口,不写任何数据。
*/
import { readFileSync } from 'node:fs';
import { createServer, loadConfigFromFile } from 'vite';
const SID = process.argv[2];
if (!SID) {
console.log('用法:node out/.temp/array-golden.mjs <sessionId>');
process.exit(1);
}
const lines = readFileSync('.env', 'utf8')
.split('\n')
.filter((line) => /^[A-Z_]+=/.test(line))
.map((line) => line.split('='));
const val = (k) => lines.find(([key]) => key === k)?.[1]?.trim() ?? '';
const credential = {
origin: val('VITE_POINTS_GATEWAY_ORIGIN'),
appKey: val('VITE_POINTS_GATEWAY_APP_KEY'),
secret: val('VITE_POINTS_GATEWAY_SECRET'),
version: '1.0.0',
format: 'json',
};
const TIMESTAMP = 1794300000000;
const realNow = Date.now;
Date.now = () => TIMESTAMP;
const cfg = await loadConfigFromFile({ command: 'serve', mode: 'development' }, 'vite.config.ts');
const server = await createServer({
...cfg.config,
appType: 'custom',
optimizeDeps: { noDiscovery: true, include: [] },
server: { ...cfg.config.server, middlewareMode: true },
logLevel: 'error',
});
const apiCore = await server.ssrLoadModule('@uj/api-core');
await server.ssrLoadModule('/src/adapter/gateways/index.ts');
const raw = await apiCore.prepareRpcCall(
{
gateway: 'scrm-shopmall',
method: 'scrm.api.shopmall.integral.transfer.out.pay.amount',
params: { ids: ['214', '213', '212'], canApprove: false, usedCarFlag: '1' },
},
{
resolveCredential: () => credential,
resolveToken: () => SID,
session: { name: 'sessionId', value: SID },
timeout: 60000,
},
);
Date.now = realNow;
const body = raw.data;
const form = new URLSearchParams(
Object.entries(body).map(([k, v]) => [k, typeof v === 'string' ? v : String(v)]),
).toString();
const reply = await fetch(raw.url, {
method: 'POST',
headers: { ...raw.headers, 'content-type': 'application/x-www-form-urlencoded' },
body: form,
}).then(async (r) => ({ http: r.status, t: await r.text() }));
console.log('url :', raw.url);
console.log('timestamp :', TIMESTAMP);
console.log('keys :', JSON.stringify(Object.keys(body)));
console.log('body :', form.replace(/(appKey=)[^&]+/, '$1…').replace(/(sign=)[^&]+/, '$1…'));
console.log('sign :', body.sign);
console.log('reply :', `HTTP ${reply.http}`, reply.t.slice(0, 220));
console.log('appKey :', credential.appKey);
await server.close();