longcat接入ccswitch获取余量查询

📅 2026/7/2 11:58:41
longcat接入ccswitch获取余量查询
longcat最近出了LongCat-2.0新模型用着还不错还有个9.9套餐包。但是官方没出余量查询api为了方便接入ccswitch查询余量做了个脚本效果如图api请求地址 https://longcat.chat/api/pay/quota/metering/token-packs/summary需要打开https://longcat.chat/platform/usage 后登录并打开f12-网络刷新一下页面找到summary这个就是余量查询请求。完整的复制cookies然后放到下面脚本里面cookies目前有效时间不确定短期用用还是不错的({ request: { url: https://longcat.chat/api/pay/quota/metering/token-packs/summary, method: POST, headers: { cookie: 这里填写前面获取的cookies, Accept: application/json, User-Agent: cc-switch/1.0 } }, extractor: function(response) { const isValid response?.code 0; const data response?.data || {}; const currentLot data.currentLot || {}; const otherLots data.otherLots || []; //自动缩放数值到 K 或 M function formatData(remainingRaw, usedRaw, totalRaw) { let divisor 1; let unit Tokens; if (totalRaw 1000000) { divisor 1000000; unit M; } else if (totalRaw 1000) { divisor 1000; unit K; } return { remaining: Number((remainingRaw / divisor).toFixed(3)), used: Number((usedRaw / divisor).toFixed(3)), total: Number((totalRaw / divisor).toFixed(3)), unit: unit }; } const results []; if (currentLot.lotId) { const formatted formatData( Number(currentLot.remainingToken || 0), Number(currentLot.consumedToken || 0), Number(currentLot.totalToken || 0) ); results.push({ isValid, planName: 当前生效包, remaining: formatted.remaining, total: formatted.total, used: formatted.used, unit: formatted.unit, extra: 消耗: ${formatted.used}${formatted.unit} / 剩余: ${formatted.remaining}${formatted.unit} }); } otherLots.forEach((lot, index) { const formatted formatData( Number(lot.remainingToken || 0), Number(lot.consumedToken || 0), Number(lot.totalToken || 0) ); results.push({ isValid, planName: otherLots.length 1 ? 备用包 ${index 1} : 备用包, remaining: formatted.remaining, total: formatted.total, used: formatted.used, unit: formatted.unit, extra: 消耗: ${formatted.used}${formatted.unit} / 剩余: ${formatted.remaining}${formatted.unit} }); }); let totalRemainingRaw 0; let totalUsedRaw 0; let totalAllRaw 0; if (currentLot.lotId) { totalRemainingRaw Number(currentLot.remainingToken || 0); totalUsedRaw Number(currentLot.consumedToken || 0); totalAllRaw Number(currentLot.totalToken || 0); } otherLots.forEach(lot { totalRemainingRaw Number(lot.remainingToken || 0); totalUsedRaw Number(lot.consumedToken || 0); totalAllRaw Number(lot.totalToken || 0); }); const formattedTotal formatData(totalRemainingRaw, totalUsedRaw, totalAllRaw); if (results.length 0) { results.unshift({ isValid, planName: 总账户额度, remaining: formattedTotal.remaining, total: formattedTotal.total, used: formattedTotal.used, unit: formattedTotal.unit, extra: 总消耗: ${formattedTotal.used}${formattedTotal.unit} / 总计: ${formattedTotal.total}${formattedTotal.unit} }); } else { results.push({ isValid, invalidMessage: isValid ? 当前无可用额度包 : 请求失败, planName: 总账户额度, remaining: 0, unit: Tokens }); } return results; } });