aixxai 1.7.5 → 1.7.7

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/bin/aixx.js CHANGED
@@ -32,6 +32,7 @@ import { aci } from '../src/commands/aci.js';
32
32
  import { market } from '../src/commands/market.js';
33
33
  import { servers } from '../src/commands/servers.js';
34
34
  import { status } from '../src/commands/status.js';
35
+ import { subscribe } from '../src/commands/subscribe.js';
35
36
  import { showHelp, showVersion } from '../src/commands/help.js';
36
37
 
37
38
  // 版本号从 package.json 读(单一来源,别再硬编码)
@@ -56,7 +57,8 @@ const COMMANDS = [
56
57
  { name: 'market', run: market }, /* 1030产品版: 行情数据订阅(docs/PLAN_MARKET_API_1030.md), 不进help带外态 */
57
58
  { name: 'aci', run: aci }, /* 已并入market, 保留指路 */
58
59
  { name: 'servers', run: servers }, /* 1022版: 萬安云服务器货架 */
59
- { name: 'status', aliases: ['st'], run: status }, /* 1120 K哥令: 身份编号给到agent·一条命令看全貌 */
60
+ { name: 'status', aliases: ['st'], run: status },
61
+ { name: 'subscribe', aliases: ['sub'], run: subscribe }, /* 1121 K哥令: 一步收银台·对话直达 */ /* 1120 K哥令: 身份编号给到agent·一条命令看全貌 */
60
62
  ];
61
63
 
62
64
  // help/version 不吃子参数(走 flag/无参分支),但命令名仍参与下面的近似匹配
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aixxai",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
4
4
  "description": "AIXX CLI - 让你的AI调用万物。One command, every AI model. By AIXX (Wanan Exchange), the verification-first compute exchange. 安装:npx aixxai",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,14 +1,15 @@
1
1
  /**
2
2
  * AIXX CLI - balance 命令
3
3
  *
4
- * 查询当前账户余额、已用额度。
4
+ * 查询当前账户余额、已用额度(模型API)+ 数据API额度一屏。
5
5
  *
6
- * 数据来源(New-API兼容接口):
7
- * 1. GET /v1/dashboard/billing/subscription → hard_limit_usd(总额度,美元)
8
- * 2. GET /v1/dashboard/billing/usage → 已用量(可能多种格式,做兜底)
6
+ * 数据来源:
7
+ * 1. GET {model}/dashboard/billing/subscription → hard_limit_usd(总额度,美元)
8
+ * 2. GET {model}/dashboard/billing/usage → 已用量(多格式兜底)
9
+ * 3. GET www.aixx.vip/api/v1/account/usage → 数据API免费额度(1121千问终检③接入)
9
10
  *
10
- * 展示时换算成人民币(按 1 USD ≈ 7 元,只是给用户一个直观感受)。
11
- * "还剩约N次对话":按每次对话约 ¥0.01 预估(最便宜模型单次几厘到几分)。
11
+ * 1121终验四修:三路并发(5.7s→~2s)·指引走stdout(PowerShell不再包NativeCommandError)·
12
+ * 耗尽态隐藏"省着用"通用提示·lifetime与daily文案分流。
12
13
  */
13
14
 
14
15
  import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
@@ -20,18 +21,13 @@ const USD_TO_CNY = 7;
20
21
  const COST_PER_CHAT_CNY = 0.01;
21
22
  // 所有对外请求统一 15 秒超时
22
23
  const FETCH_TIMEOUT = 15000;
23
- // 网络/超时异常统一成友好提示
24
+
24
25
  function friendlyNetErr(err) {
25
26
  return err?.name === 'TimeoutError' || err?.name === 'AbortError'
26
27
  ? '连接超时,请检查网络'
27
28
  : err?.message || String(err);
28
29
  }
29
30
 
30
- /**
31
- * apiKey 读取统一走 src/utils/env.js 的 loadApiKey:
32
- * 环境变量 AIXX_API_KEY → ~/.aixx/config.json → ~/.aixx/account.json
33
- */
34
-
35
31
  export async function balance(subArgs) {
36
32
  console.log('╔══════════════════════════════════════════╗');
37
33
  console.log('║ AIXX 账户余额 ║');
@@ -46,24 +42,56 @@ export async function balance(subArgs) {
46
42
  process.exit(1);
47
43
  }
48
44
 
49
- // 0.5 数据API额度预取(1121千问终检⑥顺序优化:先打快的,展示也排前面)
50
- let dataApi = null;
51
- try {
52
- const c = new AbortController();
53
- const t0 = setTimeout(() => c.abort(), 8000);
54
- const u = await fetch('https://www.aixx.vip/api/v1/account/usage', {
55
- headers: { Authorization: `Bearer ${apiKey}` },
56
- signal: c.signal,
57
- });
58
- clearTimeout(t0);
59
- const j = await u.json();
60
- if (j && j.ok) dataApi = j;
61
- } catch { /* 数据API额度查询失败不影响主流程 */ }
62
-
63
45
  console.log(`使用Key: ${maskKey(apiKey)}`);
64
- console.log(`后端地址: ${baseUrl}\n`);
46
+ console.log(`模型接口: ${baseUrl} · 数据接口: www.aixx.vip/api/v1\n`);
47
+
48
+ // 1121终验: 三路并发(数据API额度 / 订阅总额度 / 已用量)——串行5.7s→并发~2s
49
+ const pData = (async () => {
50
+ try {
51
+ const u = await fetch('https://www.aixx.vip/api/v1/account/usage', {
52
+ headers: { Authorization: `Bearer ${apiKey}` },
53
+ signal: AbortSignal.timeout(FETCH_TIMEOUT),
54
+ });
55
+ const j = await u.json();
56
+ if (j && j.ok) return j;
57
+ } catch { /* 数据API额度查询失败不影响主流程 */ }
58
+ return null;
59
+ })();
60
+
61
+ const pSub = (async () => {
62
+ try {
63
+ const r = await fetch(`${baseUrl}/dashboard/billing/subscription`, {
64
+ headers: { Authorization: `Bearer ${apiKey}` },
65
+ signal: AbortSignal.timeout(FETCH_TIMEOUT),
66
+ });
67
+ if (r.status === 401) return { _unauthorized: true };
68
+ if (!r.ok) return null;
69
+ const d = await r.json();
70
+ return { hard: d.hard_limit_usd ?? d.hard_limit ?? d.data?.hard_limit_usd ?? 0 };
71
+ } catch { return null; }
72
+ })();
73
+
74
+ const pUse = (async () => {
75
+ try {
76
+ const today = new Date();
77
+ const r = await fetch(
78
+ `${baseUrl}/dashboard/billing/usage?start_date=${today.getFullYear()}-01-01&end_date=${today.getFullYear()}-12-31`,
79
+ { headers: { Authorization: `Bearer ${apiKey}` }, signal: AbortSignal.timeout(FETCH_TIMEOUT) }
80
+ );
81
+ if (!r.ok) return null;
82
+ const d = await r.json();
83
+ return { used: d.total_usage ?? d.total_cost ?? d.data?.total_usage ?? d.cumulative_usage ?? 0 };
84
+ } catch { return null; }
85
+ })();
86
+
87
+ const [dataApi, subR, useR] = await Promise.all([pData, pSub, pUse]);
65
88
 
66
- // 4. GPU行情数据API额度先上屏(预取于下方0.5段完成·千问终检⑥:最快的先显示)
89
+ if (subR && subR._unauthorized) {
90
+ console.error('❌ API Key 无效(401),请重新 install 或检查 key');
91
+ process.exit(1);
92
+ }
93
+
94
+ // ── GPU 行情数据 API ──(先显示:最快最准的额度账)
67
95
  if (dataApi) {
68
96
  const left = dataApi.free_quota - dataApi.free_used;
69
97
  const dRem = typeof dataApi.daily_remaining === 'number' ? dataApi.daily_remaining
@@ -71,9 +99,13 @@ export async function balance(subArgs) {
71
99
  console.log('── GPU 行情数据 API ──');
72
100
  console.log(`📊 档位:${dataApi.tier === 'sub' ? '订阅中' : '免费档'}${dataApi.sub_expires_at ? `(至 ${String(dataApi.sub_expires_at).slice(0, 10)})` : ''}`);
73
101
  console.log(`📊 免费额度:剩 ${left} / ${dataApi.free_quota} 次(今日已用 ${dataApi.today_counted})`);
74
- if (dRem <= 0) {
75
- // 1121千问P0-3: 额度用尽时置顶引导(通用文案用户读完不知道该干嘛)
76
- console.log('⚠️ 今日免费额度已用尽——北京时间次日00:00自动重置,现在重试无意义');
102
+ if (left <= 0) {
103
+ // 1121终验新增: lifetime耗尽分支——"明日重置"对lifetime耗尽者=空头承诺(0点后撞403)
104
+ console.log('🚫 免费档总量已用完——日重置不恢复总量,升级订阅档继续使用');
105
+ console.log(' 订阅档: https://aixx.ai/data-api.html#price');
106
+ } else if (dRem <= 0) {
107
+ // 1121千问P0-3: 日额度用尽置顶引导
108
+ console.log(`⚠️ 今日免费额度已用尽——北京时间次日00:00恢复(免费总量剩 ${left} 次)`);
77
109
  console.log(' 需要现在继续? 订阅档: https://aixx.ai/data-api.html#price');
78
110
  } else if (dataApi.tier !== 'sub' && dRem <= 10) {
79
111
  console.log(`💡 今日剩余 ${dRem} 次,快到日上限(40/日)——省着点用`);
@@ -81,91 +113,24 @@ export async function balance(subArgs) {
81
113
  console.log('────────────────────────────────────\n');
82
114
  }
83
115
 
84
- // 0. /v1/account 端点已退役(1121千问终检:console/v1/account=404死路,白耗一次请求)
85
- // 直接走 /dashboard/billing/subscription(1121实测200活)
86
-
87
- // 1. 查总额度(subscription)
88
- let hardLimitUsd = 0;
89
- try {
90
- const resp = await fetch(`${baseUrl}/dashboard/billing/subscription`, {
91
- headers: { Authorization: `Bearer ${apiKey}` },
92
- signal: AbortSignal.timeout(FETCH_TIMEOUT),
93
- });
94
- if (!resp.ok) {
95
- if (resp.status === 401) {
96
- console.error('❌ API Key 无效(401),请重新 install 或检查 key');
97
- process.exit(1);
98
- }
99
- console.error(`❌ 查询余额失败: HTTP ${resp.status}`);
100
- process.exit(1);
101
- }
102
- const data = await resp.json();
103
- // New-API/OpenAI兼容:hard_limit_usd 是总额度
104
- hardLimitUsd =
105
- data.hard_limit_usd ??
106
- data.hard_limit ??
107
- data.data?.hard_limit_usd ??
108
- 0;
109
- } catch (err) {
110
- console.error(`❌ ${friendlyNetErr(err)}`);
111
- process.exit(1);
112
- }
113
-
114
- // 2. 查已用量(usage)
115
- // 不同后端字段不一样,尽量兜底
116
- let usedUsd = 0;
117
- try {
118
- // 用一个宽日期范围,确保能查到所有用量
119
- const today = new Date();
120
- const start = `${today.getFullYear()}-01-01`;
121
- const end = `${today.getFullYear()}-12-31`;
122
- const resp = await fetch(
123
- `${baseUrl}/dashboard/billing/usage?start_date=${start}&end_date=${end}`,
124
- {
125
- headers: { Authorization: `Bearer ${apiKey}` },
126
- signal: AbortSignal.timeout(FETCH_TIMEOUT),
127
- }
128
- );
129
- if (resp.ok) {
130
- const data = await resp.json();
131
- // 常见字段优先级
132
- usedUsd =
133
- data.total_usage ??
134
- data.total_cost ??
135
- data.data?.total_usage ??
136
- data.cumulative_usage ??
137
- 0;
138
- // New-API 的 total_usage 单位有时是"分(美元)",要除以100
139
- // 这里做个粗判断:如果usedUsd比hardLimit还大100倍,多半是没除100
140
- if (usedUsd > 0 && hardLimitUsd > 0 && usedUsd > hardLimitUsd * 50) {
141
- usedUsd = usedUsd / 100;
142
- }
143
- } else {
144
- // usage 接口挂了不影响主流程,总额度照常显示
145
- console.log(' (用量接口未返回数据,仅显示总额度)\n');
146
- }
147
- } catch (err) {
148
- console.log(' (用量查询失败,仅显示总额度)\n');
116
+ // ── 模型 API 余额 ──
117
+ let hardLimitUsd = (subR && subR.hard) || 0;
118
+ let usedUsd = (useR && useR.used) || 0;
119
+ if (usedUsd > 0 && hardLimitUsd > 0 && usedUsd > hardLimitUsd * 50) {
120
+ usedUsd = usedUsd / 100; // New-API total_usage 偶尔是"分"单位
149
121
  }
150
122
 
151
- // 3. 计算并展示
152
- // New-API 的"无限额度"哨兵:hard_limit_usd >= 100000000(1亿)表示这个token不限额。
153
- // 直接显示真实数字(¥7亿)会吓到用户,所以单独走"无限额度"分支。
154
123
  const UNLIMITED_SENTINEL = 100000000;
155
124
  const isUnlimited = hardLimitUsd >= UNLIMITED_SENTINEL;
156
125
  const usedCny = usedUsd * USD_TO_CNY;
157
126
 
158
127
  console.log('────────────────────────────────────');
159
- if (isUnlimited) {
128
+ if (!subR) {
129
+ console.log('💰 模型余额查询暂不可用(稍后再试或看 aixx status)');
130
+ } else if (isUnlimited) {
160
131
  // unlimited token(New-API对unlimited_quota=true的token返回1亿作为标记)
161
- // 实际是"按账户余额扣费",不是真的无限。账户余额是注册送的¥5起,用完就停。
162
- // billing接口拿不到真实账户余额(它对unlimited token只返回1亿标记),
163
- // 所以这里如实告知用户,引导去后台查精确余额。
164
132
  console.log(`💰 计费方式:按账户余额扣费(注册送$0.5试用额度,用完需充值)`);
165
- // 1120 WorkBuddy实测: unlimited档下dashboard/billing/usage返回的单位不可信(曾显示¥58969虚惊)
166
- // 按账户余额扣费时"已用"以账户维度为准——不展示误算值;1121千问终检:死文案删除
167
133
  } else {
168
- // 正常有限额度
169
134
  const remainingUsd = Math.max(0, hardLimitUsd - usedUsd);
170
135
  const totalCny = hardLimitUsd * USD_TO_CNY;
171
136
  const remainingCny = remainingUsd * USD_TO_CNY;
@@ -176,9 +141,18 @@ export async function balance(subArgs) {
176
141
  }
177
142
  console.log('────────────────────────────────────');
178
143
 
144
+ // 1121终验(a): 耗尽态隐藏"省着用"通用提示——都烧干了还劝省着用=噪音
145
+ const dataDry = dataApi && ((dataApi.free_quota - dataApi.free_used) <= 0
146
+ || (typeof dataApi.daily_remaining === 'number' ? dataApi.daily_remaining : 40 - (dataApi.today_counted || 0)) <= 0);
179
147
  console.log('\n💡 提示:');
180
- console.log(' - 新用户注册送 $0.5 试用额度');
181
- console.log(' - glm-4-air 便宜,省着用能聊很久');
182
- console.log(' - 余额不足时运行 aixx recharge 查看充值方式');
183
- console.log(' - 一条命令看全貌:aixx status\n');
148
+ if (dataDry) {
149
+ console.log(' - 数据API额度已用尽——升级或等重置: https://aixx.ai/data-api.html#price');
150
+ console.log(' - 余额不足时运行 aixx recharge 查看充值方式');
151
+ console.log(' - 一条命令看全貌:aixx status\n');
152
+ } else {
153
+ console.log(' - 新用户注册送 $0.5 试用额度');
154
+ console.log(' - glm-4-air 便宜,省着用能聊很久');
155
+ console.log(' - 余额不足时运行 aixx recharge 查看充值方式');
156
+ console.log(' - 一条命令看全貌:aixx status\n');
157
+ }
184
158
  }
@@ -69,15 +69,21 @@ async function mFetch(path) {
69
69
  process.exit(1);
70
70
  }
71
71
  if (res.status === 429) {
72
- // 1121千问P0-2: 解析429体分流——quota_exhausted=额度墙(引导)·rate_limited=太快(等待)
72
+ // 1121千问P0-2+终验: 解析429体分流——指引走stdout(终验b: stderr在PowerShell包成NativeCommandError乱屏)
73
73
  let eb = {};
74
74
  try { eb = await res.json(); } catch { /* 无体走默认 */ }
75
75
  if (eb && eb.error === 'quota_exhausted') {
76
- console.error('🔥 今日免费数据额度已用完(北京时间次日00:00自动重置)');
77
- console.error(' 现在重试无意义。额度账目: aixx balance');
78
- console.error(' 需要现在继续? 订阅档: https://aixx.ai/data-api.html#price');
76
+ if (eb.reason === 'lifetime_free_quota') {
77
+ console.log('🚫 免费档总量已用完(lifetime)——日重置不恢复总量,升级订阅档继续使用');
78
+ console.log(' 订阅档: https://aixx.ai/data-api.html#price');
79
+ console.log(' 额度账目: aixx balance');
80
+ } else {
81
+ console.log('🔥 今日免费数据额度已用完(北京时间次日00:00恢复,免费总量剩 ' + (eb.lifetime_remaining ?? '?') + ' 次)');
82
+ console.log(' 现在重试无意义。额度账目: aixx balance');
83
+ console.log(' 需要现在继续? 订阅档: https://aixx.ai/data-api.html#price');
84
+ }
79
85
  } else {
80
- console.error('⏳ 请求太快,' + ((eb && eb.retry_after) || 60) + '秒后可继续');
86
+ console.log('⏳ 请求太快,' + ((eb && eb.retry_after) || 60) + '秒后可继续');
81
87
  }
82
88
  process.exit(1);
83
89
  }
@@ -1,131 +1,157 @@
1
- /**
2
- * AIXX CLI - recharge 命令
3
- *
4
- * 显示充值方式。优先尝试调后端 creem/pay 接口生成在线充值链接;
5
- * 如果后端不支持或失败,则给出通用引导(联系客服/后台充值)。
6
- */
7
-
8
- import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
9
- import { loadApiKey, maskKey } from '../utils/env.js';
10
-
11
- // 所有对外请求统一 15 秒超时
12
- const FETCH_TIMEOUT = 15000;
13
-
14
- /**
15
- * apiKey 读取统一走 src/utils/env.js 的 loadApiKey:
16
- * 环境变量 AIXX_API_KEY → ~/.aixx/config.json → ~/.aixx/account.json
17
- */
18
-
19
- /**
20
- * 尝试调后端的 creem 支付接口生成充值链接。
21
- * New-API 的在线充值常见接口:
22
- * POST /api/user/creem/pay { amount, ... }
23
- * 不同版本字段不一,失败就回退到手动引导。
24
- */
25
- async function tryGetCreemLink(apiKey, baseUrl, amount) {
26
- const apiBase = baseUrl.replace(/\/v1$/, '');
27
- const candidates = [
28
- {
29
- url: `${apiBase}/api/user/creem/pay`,
30
- body: { amount, currency: 'USD', gateway: 'creem' },
31
- },
32
- {
33
- url: `${apiBase}/api/user/topup`,
34
- body: { amount, top_up_code: '', payment_method: 'creem' },
35
- },
36
- ];
37
-
38
- for (const c of candidates) {
39
- try {
40
- const resp = await fetch(c.url, {
41
- method: 'POST',
42
- headers: {
43
- Authorization: `Bearer ${apiKey}`,
44
- 'Content-Type': 'application/json',
45
- },
46
- body: JSON.stringify(c.body),
47
- signal: AbortSignal.timeout(FETCH_TIMEOUT),
48
- });
49
- if (!resp.ok) continue;
50
- const data = await resp.json().catch(() => null);
51
- if (!data) continue;
52
- // 多种可能的字段名兜底
53
- const link =
54
- data.data?.url ||
55
- data.data?.payment_url ||
56
- data.data?.checkout_url ||
57
- data.url ||
58
- data.payment_url;
59
- if (link) return link;
60
- } catch (e) {
61
- // 超时单独提示一次(其余错误静默试下一个候选接口)
62
- if (e?.name === 'TimeoutError' || e?.name === 'AbortError') {
63
- console.log(' ⚠️ 连接超时,请检查网络');
64
- }
65
- }
66
- }
67
- return null;
68
- }
69
-
70
- export async function recharge(subArgs) {
71
- console.log('╔══════════════════════════════════════════╗');
72
- console.log('║ AIXX 充值 ║');
73
- console.log('╚══════════════════════════════════════════╝\n');
74
-
75
- const apiKey = loadApiKey();
76
- const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
77
-
78
- // 从参数取金额,默认 $5(最低)
79
- let amount = 5;
80
- if (subArgs[0]) {
81
- const n = Number(subArgs[0]);
82
- if (!Number.isNaN(n) && n > 0) amount = n;
83
- }
84
-
85
- if (!apiKey) {
86
- console.log('⚠️ 未检测到AIXX API Key,以下为通用充值方式:\n');
87
- console.log('充值方式:');
88
- console.log(' 信用卡 / ApplePay:登录 AIXX 后台 → 充值 → Creem');
89
- console.log(' USDT 加密货币:联系客服或后台提交');
90
- console.log(`\n 最低充值 $5`);
91
- console.log(`\n🌐 后台地址:${baseUrl.replace(/\/v1$/, '')}`);
92
- return;
93
- }
94
-
95
- console.log(`使用Key: ${maskKey(apiKey)}`);
96
- console.log(`充值金额:$${amount}\n`);
97
-
98
- // 尝试生成在线支付链接
99
- console.log('🔄 正在生成在线充值链接...');
100
- const link = await tryGetCreemLink(apiKey, baseUrl, amount);
101
-
102
- console.log('\n────────────────────────────────────');
103
- console.log('💳 充值方式:');
104
- console.log('────────────────────────────────────');
105
-
106
- if (link) {
107
- console.log('\n ① 信用卡 / ApplePay(推荐,即时到账):');
108
- console.log(` ${link}`);
109
- console.log('\n 复制链接到浏览器打开即可支付。');
110
- } else {
111
- console.log('\n ① 信用卡 / ApplePay:');
112
- console.log(' 自动生成链接失败,请直接登录后台充值:');
113
- console.log(` ${baseUrl.replace(/\/v1$/, '')}/console/topup`);
114
- }
115
-
116
- console.log('\n ② USDT 加密货币:');
117
- console.log(' 联系 AIXX 客服,或后台提交 USDT 充值订单');
118
- console.log(' (后续会支持自动生成钱包地址)');
119
-
120
- console.log('\n ③ 微信/支付宝:');
121
- console.log(' 联系 AIXX 客服走人工充值');
122
-
123
- console.log('\n────────────────────────────────────');
124
- console.log(`最低充值 $5(约 ¥${(amount * 7).toFixed(0)})`);
125
- console.log(`充值后额度即时到账,可直接使用。\n`);
126
-
127
- console.log('💡 充值提示:');
128
- console.log(' - 充 $5 用 glm-4-air 能聊 5 万次以上');
129
- console.log(' - 充 $20 够用 Claude/GPT 跑一个月');
130
- console.log(' - 推荐码注册的用户充值后推荐人有分润\n');
131
- }
1
+ /**
2
+ * AIXX CLI - recharge 命令
3
+ *
4
+ * 显示充值方式。优先尝试调后端 creem/pay 接口生成在线充值链接;
5
+ * 如果后端不支持或失败,则给出通用引导(联系客服/后台充值)。
6
+ */
7
+
8
+ import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
9
+ import { loadApiKey, maskKey } from '../utils/env.js';
10
+
11
+ // 所有对外请求统一 15 秒超时
12
+ const FETCH_TIMEOUT = 15000;
13
+
14
+ /**
15
+ * apiKey 读取统一走 src/utils/env.js 的 loadApiKey:
16
+ * 环境变量 AIXX_API_KEY → ~/.aixx/config.json → ~/.aixx/account.json
17
+ */
18
+
19
+ /**
20
+ * 尝试调后端的 creem 支付接口生成充值链接。
21
+ * New-API 的在线充值常见接口:
22
+ * POST /api/user/creem/pay { amount, ... }
23
+ * 不同版本字段不一,失败就回退到手动引导。
24
+ */
25
+ async function tryGetCreemLink(apiKey, baseUrl, amount) {
26
+ const apiBase = baseUrl.replace(/\/v1$/, '');
27
+ const candidates = [
28
+ {
29
+ url: `${apiBase}/api/user/creem/pay`,
30
+ body: { amount, currency: 'USD', gateway: 'creem' },
31
+ },
32
+ {
33
+ url: `${apiBase}/api/user/topup`,
34
+ body: { amount, top_up_code: '', payment_method: 'creem' },
35
+ },
36
+ ];
37
+
38
+ for (const c of candidates) {
39
+ try {
40
+ const resp = await fetch(c.url, {
41
+ method: 'POST',
42
+ headers: {
43
+ Authorization: `Bearer ${apiKey}`,
44
+ 'Content-Type': 'application/json',
45
+ },
46
+ body: JSON.stringify(c.body),
47
+ signal: AbortSignal.timeout(FETCH_TIMEOUT),
48
+ });
49
+ if (!resp.ok) continue;
50
+ const data = await resp.json().catch(() => null);
51
+ if (!data) continue;
52
+ // 多种可能的字段名兜底
53
+ const link =
54
+ data.data?.url ||
55
+ data.data?.payment_url ||
56
+ data.data?.checkout_url ||
57
+ data.url ||
58
+ data.payment_url;
59
+ if (link) return link;
60
+ } catch (e) {
61
+ // 超时单独提示一次(其余错误静默试下一个候选接口)
62
+ if (e?.name === 'TimeoutError' || e?.name === 'AbortError') {
63
+ console.log(' ⚠️ 连接超时,请检查网络');
64
+ }
65
+ }
66
+ }
67
+ return null;
68
+ }
69
+
70
+ export async function recharge(subArgs) {
71
+ // 1121 K哥令一步收银台: aixx recharge 10 --channel alipay → checkout-intent直接开单(零登录)
72
+ const _num = (subArgs || []).find(a => /^\d+(\.\d+)?$/.test(a));
73
+ const _ch = (subArgs || []).find(a => a.startsWith('--channel'));
74
+ if (_num) {
75
+ const apiKey = loadApiKey ? loadApiKey() : '';
76
+ try {
77
+ const r = await fetch('https://console.aixx.ai/cloudpay/checkout/intent', {
78
+ method: 'POST',
79
+ headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
80
+ body: JSON.stringify({ item: 'balance', amount_usd: parseFloat(_num), channel: (_ch ? _ch.split('=')[1] || 'alipay' : 'alipay') }),
81
+ signal: AbortSignal.timeout(20000),
82
+ });
83
+ const j = await r.json().catch(() => ({}));
84
+ if (r.ok && j.ok) {
85
+ console.log(`✅ 收银台已开(订单 ${j.order_no})`);
86
+ console.log(` 金额:$${Number(j.amount_usd).toFixed(2)} ≈ ¥${Number(j.amount_cny).toFixed(2)} · 通道 ${j.channel}`);
87
+ console.log(`
88
+ 💳 收银台链接(点开或发到手机打开):
89
+ ${j.pay_url}`);
90
+ console.log(`
91
+ 付款到账自动入余额——aixx balance 随时看。`);
92
+ return;
93
+ }
94
+ console.log(`(一步收银台开单失败: ${(j && (j.detail || j.message)) || 'HTTP ' + r.status}——回退传统方式)`);
95
+ } catch { console.log('(一步收银台网络异常——回退传统方式)'); }
96
+ }
97
+ console.log('╔══════════════════════════════════════════╗');
98
+ console.log('║ AIXX 充值 ║');
99
+ console.log('╚══════════════════════════════════════════╝\n');
100
+
101
+ const apiKey = loadApiKey();
102
+ const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
103
+
104
+ // 从参数取金额,默认 $5(最低)
105
+ let amount = 5;
106
+ if (subArgs[0]) {
107
+ const n = Number(subArgs[0]);
108
+ if (!Number.isNaN(n) && n > 0) amount = n;
109
+ }
110
+
111
+ if (!apiKey) {
112
+ console.log('⚠️ 未检测到AIXX API Key,以下为通用充值方式:\n');
113
+ console.log('充值方式:');
114
+ console.log(' 信用卡 / ApplePay:登录 AIXX 后台 → 充值 → Creem');
115
+ console.log(' USDT 加密货币:联系客服或后台提交');
116
+ console.log(`\n 最低充值 $5`);
117
+ console.log(`\n🌐 后台地址:${baseUrl.replace(/\/v1$/, '')}`);
118
+ return;
119
+ }
120
+
121
+ console.log(`使用Key: ${maskKey(apiKey)}`);
122
+ console.log(`充值金额:$${amount}\n`);
123
+
124
+ // 尝试生成在线支付链接
125
+ console.log('🔄 正在生成在线充值链接...');
126
+ const link = await tryGetCreemLink(apiKey, baseUrl, amount);
127
+
128
+ console.log('\n────────────────────────────────────');
129
+ console.log('💳 充值方式:');
130
+ console.log('────────────────────────────────────');
131
+
132
+ if (link) {
133
+ console.log('\n ① 信用卡 / ApplePay(推荐,即时到账):');
134
+ console.log(` ${link}`);
135
+ console.log('\n 复制链接到浏览器打开即可支付。');
136
+ } else {
137
+ console.log('\n ① 信用卡 / ApplePay:');
138
+ console.log(' 自动生成链接失败,请直接登录后台充值:');
139
+ console.log(` ${baseUrl.replace(/\/v1$/, '')}/console/topup`);
140
+ }
141
+
142
+ console.log('\n ② USDT 加密货币:');
143
+ console.log(' 联系 AIXX 客服,或后台提交 USDT 充值订单');
144
+ console.log(' (后续会支持自动生成钱包地址)');
145
+
146
+ console.log('\n ③ 微信/支付宝:');
147
+ console.log(' 联系 AIXX 客服走人工充值');
148
+
149
+ console.log('\n────────────────────────────────────');
150
+ console.log(`最低充值 $5(约 ¥${(amount * 7).toFixed(0)})`);
151
+ console.log(`充值后额度即时到账,可直接使用。\n`);
152
+
153
+ console.log('💡 充值提示:');
154
+ console.log(' - 充 $5 用 glm-4-air 能聊 5 万次以上');
155
+ console.log(' - 充 $20 够用 Claude/GPT 跑一个月');
156
+ console.log(' - 推荐码注册的用户充值后推荐人有分润\n');
157
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * AIXX CLI - subscribe 命令(1121 K哥令:一步收银台·零登录·对话直达)
3
+ *
4
+ * aixx subscribe 1m → 数据API月档收银链接+二维码(支付宝默认)
5
+ * aixx subscribe 3m --channel wxpay
6
+ * aixx subscribe 12m --channel usdt(USDT需整数美元·测试期档价为1/2/3/4分)
7
+ *
8
+ * 凭证 = 本机 sk- 数据key(装机自带)——POST /cloudpay/checkout/intent
9
+ * 返回 pay_url + qr_url,打印给用户/agent:链接打开即真实收银台,付款自动升档。
10
+ * 金额/档位/收款地址全部服务端生成——agent拿不到也改不了。
11
+ */
12
+
13
+ import { loadApiKey } from '../utils/env.js';
14
+
15
+ const CHECKOUT = 'https://console.aixx.ai/cloudpay/checkout/intent';
16
+ const FETCH_TIMEOUT = 20000;
17
+
18
+ const PLANS = {
19
+ '1m': '1个月档', '3m': '3个月档', '6m': '6个月档', '12m': '12个月档',
20
+ };
21
+
22
+ export async function subscribe(subArgs) {
23
+ const rest = (subArgs || []).filter((a) => a && !a.startsWith('--'));
24
+ const plan = (rest[0] || '').toLowerCase();
25
+ const chArg = (subArgs || []).find((a) => a.startsWith('--channel'));
26
+ const channel = chArg ? chArg.split('=')[1] || subArgs[(subArgs.indexOf(chArg) + 1)] || '' : 'alipay';
27
+
28
+ if (!plan || !PLANS[plan]) {
29
+ console.log('用法: aixx subscribe <1m|3m|6m|12m> [--channel alipay|wxpay|usdt]\n');
30
+ console.log('示例:');
31
+ console.log(' aixx subscribe 1m 一个月档(支付宝扫码/打开)');
32
+ console.log(' aixx subscribe 12m --channel usdt 年档USDT付款');
33
+ console.log('\n订阅=行情数据API六域全开(80次免费额度之外的不限量档)。');
34
+ return;
35
+ }
36
+
37
+ const apiKey = loadApiKey();
38
+ if (!apiKey) {
39
+ console.error('❌ 未找到AIXX API Key——请先 npx aixxai install');
40
+ process.exit(1);
41
+ }
42
+
43
+ console.log(`🧾 正在开单:${PLANS[plan]} · 通道 ${channel}…\n`);
44
+ try {
45
+ const r = await fetch(CHECKOUT, {
46
+ method: 'POST',
47
+ headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
48
+ body: JSON.stringify({ item: `sub:${plan}`, channel }),
49
+ signal: AbortSignal.timeout(FETCH_TIMEOUT),
50
+ });
51
+ const j = await r.json().catch(() => ({}));
52
+ if (!r.ok || !j.ok) {
53
+ console.error(`❌ 开单失败: ${(j && (j.detail || j.message)) || 'HTTP ' + r.status}`);
54
+ if (j && j.detail && String(j.detail).includes('测试价')) {
55
+ console.error(' (订阅测试价当前仅限内部验证账号)');
56
+ }
57
+ process.exit(1);
58
+ }
59
+ console.log(`✅ 收银台已开(订单 ${j.order_no})`);
60
+ console.log(` 档位:${PLANS[plan]} 金额:$${Number(j.amount_usd).toFixed(2)} ≈ ¥${Number(j.amount_cny).toFixed(2)}`);
61
+ console.log(` 通道:${j.channel}`);
62
+ console.log(`\n💳 收银台链接(点开或发到手机打开):\n${j.pay_url}`);
63
+ if (j.qr_url && j.qr_url !== j.pay_url) {
64
+ console.log(`\n📱 二维码图片(可贴进对话):\n${j.qr_url}`);
65
+ }
66
+ console.log('\n付款到账后自动升级订阅档——aixx status 可随时看档位与到期日。');
67
+ } catch (err) {
68
+ console.error('❌ ' + (err?.name === 'TimeoutError' || err?.name === 'AbortError'
69
+ ? '连接超时,请检查网络' : err?.message || String(err)));
70
+ process.exit(1);
71
+ }
72
+ }