diff --git a/src/modules/admin-billing/admin-billing.service.ts b/src/modules/admin-billing/admin-billing.service.ts index d124dbe..e486db0 100644 --- a/src/modules/admin-billing/admin-billing.service.ts +++ b/src/modules/admin-billing/admin-billing.service.ts @@ -1,4 +1,5 @@ import { Injectable, Logger } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; export interface BillingInfo { name: string; model: string; balance: string; currency: string; status: 'ok' | 'unknown'; consoleUrl: string; note: string; @@ -8,6 +9,8 @@ export interface BillingInfo { export class AdminBillingService { private readonly logger = new Logger(AdminBillingService.name); + constructor(private readonly config: ConfigService) {} + async getAllBilling(): Promise<{ providers: BillingInfo[] }> { const [deepseek, siliconflow] = await Promise.all([this.getDeepSeek(), this.getSiliconFlow()]); return { providers: [deepseek, siliconflow, this.getMiniMax(), this.getBaiduOcr()] }; @@ -15,7 +18,8 @@ export class AdminBillingService { private async getDeepSeek(): Promise { try { - const r = await fetch('https://api.deepseek.com/user/balance', { headers: { Authorization: 'Bearer sk-ddddea4986d843be978ced9e82988fa0' } }); + const apiKey = this.config.get('ai.deepseek.apiKey') || process.env.DEEPSEEK_API_KEY || ''; + const r = await fetch('https://api.deepseek.com/user/balance', { headers: { Authorization: `Bearer ${apiKey}` } }); const d = await r.json(); const b = d?.balance_infos?.[0]?.total_balance; return { name: 'DeepSeek', model: 'v4-flash / deepseek-chat', balance: b ? `¥${b}` : '—', currency: 'CNY', status: 'ok', consoleUrl: 'https://platform.deepseek.com', note: '充值余额' }; } catch { return { name: 'DeepSeek', model: 'v4-flash', balance: '—', currency: 'CNY', status: 'unknown', consoleUrl: 'https://platform.deepseek.com', note: '查询失败' }; } @@ -23,7 +27,8 @@ export class AdminBillingService { private async getSiliconFlow(): Promise { try { - const r = await fetch('https://api.siliconflow.cn/v1/user/info', { headers: { Authorization: 'Bearer sk-jdtqzgrlneklatdmymscrnvljvzlkkxcrzylznufpgggswjz' } }); + const apiKey = process.env.SILICONFLOW_API_KEY || ''; + const r = await fetch('https://api.siliconflow.cn/v1/user/info', { headers: { Authorization: `Bearer ${apiKey}` } }); const d = await r.json(); const b = d?.data?.totalBalance; return { name: '硅基流动', model: 'BGE-M3 / BGE-Reranker', balance: b ? `¥${b}` : '—', currency: 'CNY', status: 'ok', consoleUrl: 'https://cloud.siliconflow.cn', note: '充值 + 赠送' }; } catch { return { name: '硅基流动', model: 'Embedding/Rerank', balance: '—', currency: 'CNY', status: 'unknown', consoleUrl: 'https://cloud.siliconflow.cn', note: '查询失败' }; }