creditdaddy 1.7.1 → 1.7.2

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.
@@ -27,6 +27,37 @@ export const LINGXI_BALANCE_URL = `${LINGXI_BASE}/api/public/v1/credits/balance`
27
27
 
28
28
  export const DAILY_CHECK_IN_KEY = 'daily_check_in';
29
29
 
30
+ /**
31
+ * 稳定身份:WPS 会话罐里的 `uid` cookie(WPS 账号 uid,纯数字;与 wps_sid 同罐收割,
32
+ * 登录号变了它必变)。tasks/balance 响应无任何身份字段、user 系端点 404(2026-11-09
33
+ * 本机实测)——cookie 罐是唯一可靠身份源,多号归户(capture 匹配 / 10R 卡 source)都用它。
34
+ * @returns {string|null}
35
+ */
36
+ export function lingxiIdentityFromCookie(cookie) {
37
+ for (const seg of String(cookie || '').split(';')) {
38
+ const i = seg.indexOf('=');
39
+ if (i < 1) continue;
40
+ if (seg.slice(0, i).trim() === 'uid') {
41
+ const v = seg.slice(i + 1).trim();
42
+ if (/^\d{1,20}$/.test(v)) return v;
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+
48
+ /**
49
+ * uid 展示脱敏(用户要求,手机号同款口径):≥7 位前 3 后 3,4~6 位前 1 后 1,更短全掩。
50
+ * 只用于行名等显示位;归户哈希 / 账号 uid / 10R source 仍用原始值。
51
+ * @param {string|number} uid
52
+ * @returns {string}
53
+ */
54
+ export function maskLingxiUid(uid) {
55
+ const s = String(uid ?? '');
56
+ if (s.length >= 7) return s.slice(0, 3) + '****' + s.slice(-3);
57
+ if (s.length >= 4) return s.slice(0, 1) + '****' + s.slice(-1);
58
+ return '****';
59
+ }
60
+
30
61
  function lingxiHeaders(cookie) {
31
62
  return {
32
63
  Cookie: String(cookie || '').trim(),
@@ -59,7 +90,7 @@ function localDayKey(now = new Date()) {
59
90
  * 任务面板:每日签到状态 + 智点余额/资源包一次拿全。
60
91
  * @param {string} cookie
61
92
  * @param {{ fetchImpl?: Function }} [opts]
62
- * @returns {Promise<{ auth: boolean, checkedIn?: boolean, reward?: number, streakDays?: number,
93
+ * @returns {Promise<{ auth: boolean, checkedIn?: boolean, reward?: number, dayReward?: number, streakDays?: number,
63
94
  * balance?: number, packs?: Array, raw?: object, code?: string }>}
64
95
  * auth=false = 会话失效;其余字段尽力而为(接口各自独立,某一路失败不带该字段)
65
96
  *
@@ -87,7 +118,13 @@ export async function fetchLingxiStatus(cookie, { fetchImpl } = {}) {
87
118
  const reward = Number(daily.reward_amount ?? daily.rewardAmount);
88
119
  if (Number.isFinite(reward) && reward > 0) out.reward = reward;
89
120
  const days = daily.extra?.check_in_days || daily.extra?.checkInDays;
90
- if (Array.isArray(days)) out.streakDays = days.filter((d) => d?.claimed || d?.status === 'claimed').length;
121
+ if (Array.isArray(days)) {
122
+ out.streakDays = days.filter((d) => d?.claimed || d?.status === 'claimed').length;
123
+ // 当天奖励 = 本轮第 streakDays+1 天的 reward(每日 100 / 第七天 200,#53 实测口径);
124
+ // claim 响应的 total_claimed_credits 是本轮周期累计,不能当当天额展示
125
+ const dayReward = Number(days[out.streakDays]?.reward ?? days[out.streakDays]?.rewardAmount);
126
+ if (Number.isFinite(dayReward) && dayReward > 0) out.dayReward = dayReward;
127
+ }
91
128
  }
92
129
  out.raw = { tasks: tasks.length };
93
130
  } catch (e) {
@@ -151,7 +188,9 @@ export async function checkinLingxi(account, ctx = {}) {
151
188
  e.auth = true;
152
189
  throw e;
153
190
  }
154
- const reward = status.reward ?? 100;
191
+ // 展示口径的当天额:优先当日奖励(check_in_days[连签天数].reward),
192
+ // 退 reward_amount;绝不直接用 claim 的 total_claimed_credits(周期累计,会虚报 N 倍)
193
+ const reward = status.dayReward ?? status.reward ?? 100;
155
194
  if (status.checkedIn) {
156
195
  return {
157
196
  status: 'already',
@@ -184,8 +223,10 @@ export async function checkinLingxi(account, ctx = {}) {
184
223
  return { status: 'failed', message: t('灵犀签到失败:{err}', { err: e.message }) };
185
224
  }
186
225
 
187
- const claimed = Number(claimData?.data?.total_claimed_credits ?? claimData?.data?.totalClaimedCredits);
188
- const pts = Number.isFinite(claimed) && claimed > 0 ? claimed : reward;
226
+ // 2026-11-09 实测:连签第 3 天 claim 返回 total_claimed_credits=300,余额实动 +100——
227
+ // 该字段是本轮周期累计(100×3),当当天额展示会虚报 3 倍(第七天会虚报成 800)。
228
+ // pts 一律走任务状态的当日奖励链,不再读累计值。
229
+ const pts = reward;
189
230
  log?.('灵犀签到成功');
190
231
  return {
191
232
  status: 'checked-in',
@@ -18,6 +18,7 @@
18
18
  * - Anthropic 兼容端点:POST {agent}/mavis/api/v1/llm/v1/messages
19
19
  */
20
20
 
21
+ import { createHash } from 'node:crypto';
21
22
  import { fetchJsonRace } from './zcodeClient.js';
22
23
  import { withRefreshDedupe, refreshFpDead } from './refreshGuard.js';
23
24
  import { FETCH_TIMEOUT_MS } from './constants.js';
@@ -64,6 +65,80 @@ export function minimaxEndpointsOf(account) {
64
65
  };
65
66
  }
66
67
 
68
+ /** 账户动作类端点(签到 / 额度 / 资料)的服务端签名,取自 10Router open-sse 实现 */
69
+ const SIGN_SECRET = 'I*7Cf%WZ#S&%1RlZJ&C2';
70
+ const md5hex = (s) => createHash('md5').update(s).digest('hex');
71
+
72
+ /**
73
+ * 构造 signed account 请求:查询参数与请求头参与签名,签名值绑定
74
+ * URL+时间戳(+body),因此不能与裸 fetch 的查询串混用。
75
+ * @returns {{url: string, headers: object, body?: string}}
76
+ */
77
+ export function signedMiniMaxRequest(flavor, path, { access, userID, body, now = Date.now() } = {}) {
78
+ const lang = flavor === 'global' ? 'en' : 'zh';
79
+ const url = new URL(path, basesOf({ provider: flavor === 'global' ? 'minimax-global' : 'minimax' }).agent);
80
+ url.search = new URLSearchParams({
81
+ device_platform: 'mcode',
82
+ biz_id: '3',
83
+ app_id: '3001',
84
+ version_code: '22201',
85
+ unix: String(now),
86
+ timezone_offset: String(new Date().getTimezoneOffset() * -60),
87
+ sys_language: lang,
88
+ lang,
89
+ device_id: '0',
90
+ os_name: process.platform,
91
+ browser_name: 'mcode',
92
+ user_id: String(userID ?? '').trim() || '0',
93
+ client: 'mcode',
94
+ }).toString();
95
+ const at = url.pathname + url.search;
96
+ const ts = Math.floor(now / 1000);
97
+ const json = body === undefined ? undefined : JSON.stringify(body);
98
+ const headers = {
99
+ Accept: 'application/json',
100
+ 'Content-Type': 'application/json',
101
+ 'User-Agent': 'MiniMaxCode',
102
+ Authorization: `Bearer ${String(access || '').trim()}`,
103
+ yy: json === undefined
104
+ ? md5hex(`${encodeURIComponent(at)}_{}${md5hex(String(now))}ooui`)
105
+ : md5hex(`${encodeURIComponent(at)}_${json}${md5hex(String(now))}ooui`),
106
+ 'x-timestamp': String(ts),
107
+ 'x-signature': json === undefined ? md5hex(`${ts}${SIGN_SECRET}`) : md5hex(`${ts}${SIGN_SECRET}${json}`),
108
+ };
109
+ return { url: url.toString(), headers, body: json };
110
+ }
111
+
112
+ /** 账户端点统一入口:国际版走签名 + 代理优先(CN 网络直连 agent.minimax.io 会被 307 到 CN 域名家族) */
113
+ function signedCall(account, path, { access, userID, body, timeoutMs = FETCH_TIMEOUT_MS } = {}) {
114
+ const flavor = minimaxFlavorOf(account);
115
+ const req = signedMiniMaxRequest(flavor, path, { access, userID, body });
116
+ return fetchJsonRace(req.url, {
117
+ method: req.body === undefined ? 'GET' : 'POST',
118
+ headers: req.headers,
119
+ body: req.body ?? null,
120
+ timeoutMs,
121
+ preferProxy: flavor === 'global',
122
+ });
123
+ }
124
+
125
+ /** 307 到别的域名家族 = 地区限制,本机配置代理即可,token 本身没问题 */
126
+ function geoNote(requestedUrl, res) {
127
+ try {
128
+ const from = new URL(requestedUrl).host;
129
+ const to = new URL(res.url || requestedUrl).host;
130
+ if (from === to) return null;
131
+ return `上游 ${from} 在当前网络被重定向到 ${to}(地区限制)——请为国际版配置代理后重试`;
132
+ } catch {
133
+ return null;
134
+ }
135
+ }
136
+
137
+ /** 签名里的 user_id:账号已解析出 uid 时带上,未解析按 10Router 口径退化为 "0" */
138
+ function uiOf(account) {
139
+ return account?.uid || account?.meta?.realUserID || undefined;
140
+ }
141
+
67
142
  /** 时间戳宽容转换(口径同 traeClient.iso):≤1e11 视为秒,否则视为毫秒;0/无效 → null */
68
143
  function isoMs(v) {
69
144
  const n = Number(v);
@@ -244,17 +319,8 @@ export async function verifyMiniMaxAccount(account) {
244
319
  * 查询额度 (quota)
245
320
  */
246
321
  export async function fetchMiniMaxQuota(account, ctx = {}) {
247
- const { membershipUrl } = minimaxEndpointsOf(account);
248
322
  return withMiniMaxAuth(account, async (token) => {
249
- const res = await fetchJsonRace(membershipUrl, {
250
- method: 'POST',
251
- headers: {
252
- ...authHeaders(token),
253
- 'Content-Type': 'application/json',
254
- },
255
- body: JSON.stringify({}),
256
- timeoutMs: FETCH_TIMEOUT_MS,
257
- });
323
+ const res = await signedCall(account, '/matrix/api/v1/commerce/get_membership_info', { access: token, userID: uiOf(account), body: {} });
258
324
  if (res.status === 401) {
259
325
  const err = new Error('MiniMax 凭据已失效 (401)');
260
326
  err.auth = true;
@@ -331,13 +397,9 @@ export function normalizeMiniMaxQuota(data) {
331
397
  * @returns {Promise<{checkedToday: boolean, streakDays: number, points: number, bonusPoints: number}|null>}
332
398
  */
333
399
  export async function fetchMiniMaxCheckinStatus(account, ctx = {}) {
334
- const { signinStatusUrl } = minimaxEndpointsOf(account);
335
400
  try {
336
401
  return await withMiniMaxAuth(account, async (token) => {
337
- const statusRes = await fetchJsonRace(signinStatusUrl, {
338
- headers: authHeaders(token),
339
- timeoutMs: FETCH_TIMEOUT_MS,
340
- });
402
+ const statusRes = await signedCall(account, '/minimax-cloud/api/v1/signin/status', { access: token, userID: uiOf(account) });
341
403
  if (!statusRes.ok) return null;
342
404
  const statusData = await statusRes.json().catch(() => null);
343
405
  if (!statusData || statusData.base_resp?.status_code !== 0) return null;
@@ -359,14 +421,12 @@ export async function fetchMiniMaxCheckinStatus(account, ctx = {}) {
359
421
  * 每日自动签到 (checkin)
360
422
  */
361
423
  export async function checkinMiniMax(account, ctx = {}) {
362
- const { signinStatusUrl, signinClaimUrl } = minimaxEndpointsOf(account);
363
424
  return withMiniMaxAuth(account, async (token) => {
364
425
  // 1. 查询签到状态
365
- const statusRes = await fetchJsonRace(signinStatusUrl, {
366
- headers: authHeaders(token),
367
- timeoutMs: FETCH_TIMEOUT_MS,
368
- });
369
- if (statusRes.status === 401) {
426
+ const statusRes = await signedCall(account, '/minimax-cloud/api/v1/signin/status', { access: token, userID: uiOf(account) });
427
+ if (statusRes.status === 401 || statusRes.status === 403) {
428
+ const geo = geoNote(statusRes.url, statusRes);
429
+ if (geo) throw new Error(geo);
370
430
  const err = new Error('MiniMax 凭据已失效 (401)');
371
431
  err.auth = true;
372
432
  throw err;
@@ -390,13 +450,11 @@ export async function checkinMiniMax(account, ctx = {}) {
390
450
  };
391
451
  }
392
452
 
393
- // 2. 发起签到 claim
394
- const claimRes = await fetchJsonRace(signinClaimUrl, {
395
- method: 'POST',
396
- headers: authHeaders(token),
397
- timeoutMs: FETCH_TIMEOUT_MS,
398
- });
399
- if (claimRes.status === 401) {
453
+ // 2. 发起签到 claim(status=GET,claim=POST;动词错了是裸 404,不是签名错)
454
+ const claimRes = await signedCall(account, '/minimax-cloud/api/v1/signin/claim', { access: token, userID: uiOf(account), body: {} });
455
+ if (claimRes.status === 401 || claimRes.status === 403) {
456
+ const geo = geoNote(claimRes.url, claimRes);
457
+ if (geo) throw new Error(geo);
400
458
  const err = new Error('MiniMax 凭据已失效 (401)');
401
459
  err.auth = true;
402
460
  throw err;
@@ -105,6 +105,27 @@ export function minimaxExePath() {
105
105
  return fs.existsSync(cand) ? cand : null;
106
106
  }
107
107
 
108
+ /**
109
+ * app-update.yml 文本 → 构建语言版:国内构建更新源指向 minimax.chat、国际构建指向
110
+ * minimax.io(两站发的安装包同名同路径——exe 无法区分,更新源是唯一可靠标记)。
111
+ * 判别不了返回 null(宁可不提示,不误报)。
112
+ */
113
+ export function buildLangFromUpdateYml(text) {
114
+ if (!text) return null;
115
+ if (/minimax\.chat/i.test(text)) return 'cn';
116
+ if (/minimax\.io/i.test(text)) return 'en';
117
+ return null;
118
+ }
119
+
120
+ /** 已装客户端的构建语言版('cn' / 'en' / null=未知或未装)。exe 同级的 resources/app-update.yml。 */
121
+ export function detectMiniMaxBuildLang() {
122
+ const exe = minimaxExePath();
123
+ if (!exe) return null;
124
+ try {
125
+ return buildLangFromUpdateYml(fs.readFileSync(path.join(path.dirname(exe), 'resources', 'app-update.yml'), 'utf8'));
126
+ } catch { return null; }
127
+ }
128
+
108
129
  const WIN_TASKLIST = () => {
109
130
  try {
110
131
  return execSync('tasklist /FI "IMAGENAME eq MiniMax Code.exe" /NH', { windowsHide: true, encoding: 'utf8' });
@@ -142,6 +163,7 @@ export function detectMiniMax(flavor = 'cn') {
142
163
  exePath: exe,
143
164
  authPath: authFile,
144
165
  signedIn: hasRecord,
166
+ buildLang: detectMiniMaxBuildLang(),
145
167
  running: minimaxRunningCached(),
146
168
  };
147
169
  }