API 使用指南

1. 概览

本平台提供 RESTful HTTP API,让你用程序化方式:

  • 按 业务 (BIN) 批量开虚拟卡,拿到 PAN + CVV + exp
  • 查看/取消 已开的卡
  • 导出 CSV / 查询余额

所有接口版本前缀 /api/v1/*,响应格式 application/json,字符集 UTF-8。

2. 认证 (API Key)
  1. 在 个人账户 页 (可先点 "修改密码" 改成自己好记的),点击 "重新生成 API Key",一次性拿到 64 位 hex 字符串(仅显示一次,请立即复制)
  2. 之后每次调用带一个 header:
# 推荐:Authorization Bearer
Authorization: Bearer 

# 或者:X-API-Key
X-API-Key: 
⚠ 安全提示:API Key 等同密码。
  • 不要写到公开代码仓库
  • 不要发给客服/QQ 群
  • 怀疑泄漏立即到账户页 重新生成(旧 key 立即失效)
  • 用旧 API Key 调 /account/api-key/rotate 会 403,防止密钥被盗后自我续期 — 必须走 Web 会话
3. Base URL & 通用规则
Base URLhttps://cvv.nerver.cc(即当前域名)
协议HTTPS only (HTTP 会被 301 重定向)
Content-Type请求体一律 application/json
时间格式ISO 8601 UTC,如 2026-09-29T20:15:00Z
金额单位响应里 *_yuan 字段是字符串(如 "12.50");内部数据库用分
ID 类型整数(int64 range)
4. 快速上手 (30 秒 3 步)

假设你已经拿到 API Key,想在业务 kiro 上开 3 张卡:

# 1. 查一下有哪些业务可用
curl -H "X-API-Key: <your_key>" https://cvv.nerver.cc/api/v1/businesses

# 2. 批量开 3 张
curl -X POST https://cvv.nerver.cc/api/v1/cards/allocate \
     -H "X-API-Key: <your_key>" \
     -H "Content-Type: application/json" \
     -d '{"business": "kiro", "count": 3}'

# 3. 拿到 3 张卡的 PAN / CVV / exp 后可以立即使用
5. 完整端点
方法路径说明
POST /api/v1/cards/allocate 批量开卡 (最多 20 张/次)
GET /api/v1/cards 列出我的卡(分页 + 过滤)
GET /api/v1/cards/{id} 查单张卡详情
POST /api/v1/cards/{id}/cancel 取消一张卡
GET /api/v1/businesses 列出可用业务 (BIN)
GET /api/v1/account 查账户余额 + 消费
POST /api/v1/cards/export 导出 CSV
POST /api/v1/cards/allocate — 批量开卡

按业务 (含 BIN 匹配) 从卡池分配 N 张虚拟卡。原子扣费。

请求体:

{
  "business": "kiro",      // 业务名 (或 id 数字字符串)
  "count": 3               // 张数, 1~20
}

响应 (成功):

{
  "allocated": [
    {
      "id": 12345,
      "pan": "4513123456781234",
      "cvv": "123",
      "exp": "12/28",
      "business": "kiro",
      "status": "active",
      "allocated_at": "2026-09-29T20:15:00Z",
      "cancelled_at": null
    },
    ...
  ],
  "partial": false,
  "failed_at": null,
  "reason": null
}

错误:

  • 400 count_exceeds_cap — 超过 max_batch_allocate (默认 20)
  • 402 insufficient_balance — 余额不够 (返回 need_cents / have_cents)
  • 409 all_accounts_saturated — 所有匹配 BIN 的 Netspend 账号都满 (上限 6 张/账号)
  • 503 all_accounts_token_expired — 所有账号 token 都过期,后台正在刷新
  • 504 replenish_timeout — 触发补货但等待超时
  • 404 business_not_found — business 名不存在
  • 400 business_disabled — 业务已被管理员禁用
GET /api/v1/cards — 我的卡片

Query 参数:

business按业务名过滤
statusactive / cancelled / opening / failed
page分页,默认 1
page_size每页条数,默认 50,上限 200
curl -H "X-API-Key: <key>" \
     "https://cvv.nerver.cc/api/v1/cards?business=kiro&status=active&page=1&page_size=100"

响应:

{
  "items": [ /* CardV1Out[] */ ],
  "total": 128,
  "page": 1,
  "page_size": 50
}

GET /api/v1/cards/{id} — 查单张:

curl -H "X-API-Key: <key>" https://cvv.nerver.cc/api/v1/cards/12345
POST /api/v1/cards/{id}/cancel — 取消卡

异步销卡,先立即改成 cancelled 状态,后台推真实销卡请求到 Netspend。

curl -X POST -H "X-API-Key: <key>" \
     https://cvv.nerver.cc/api/v1/cards/12345/cancel

错误:

  • 404 card_not_found — 卡不存在或不属于你 (越权 → 404 而非 403,防信息泄漏)
  • 409 card_already_cancelled
GET /api/v1/businesses — 业务 (BIN) 列表
curl -H "X-API-Key: <key>" https://cvv.nerver.cc/api/v1/businesses

响应:

[
  {
    "id": 1,
    "name": "kiro",
    "description": "Kiro AI Coder",
    "color": "primary",
    "unit_price_yuan": "5.00",
    "bin_prefix": "4513",
    "available_stock": 42
  },
  ...
]
GET /api/v1/account — 账户信息
curl -H "X-API-Key: <key>" https://cvv.nerver.cc/api/v1/account

响应:

{
  "username": "alice",
  "balance_yuan": "1234.50",
  "month_spent_yuan": "68.00",
  "api_key_masked": "****abcd1234",
  "rate_limit_per_minute": 60
}
POST /api/v1/cards/export — 导出 CSV

请求体 (三者可组合):

{
  "ids":      [12345, 67890],   // 明确 id 列表
  "business": "kiro",           // 按业务
  "status":   "active"          // 按状态
}

响应:text/csv; charset=utf-8(UTF-8 with BOM,可直接 Excel 打开)

6. 错误码总览

错误响应统一格式:

HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "detail": {
    "code": "insufficient_balance",
    "message": "余额不足",
    "extra": {"need_cents": 500, "have_cents": 240}
  }
}
HTTPcode含义
400bad_request请求参数不合法(见 detail.extra)
401authentication_required未带 API Key 或 JWT
401invalid_api_keyAPI Key 不存在或已被撤销
402insufficient_balance余额不足 (含 need_cents/have_cents)
403user_disabled账户被管理员禁用
403web_only此接口仅 Web 会话可用(如轮换 Key)
404card_not_found卡不存在或不属于你
404business_not_found业务名不存在
409all_accounts_saturated所有账号饱和
429rate_limit_exceeded限流(见 X-RateLimit-Retry-After header)
503all_accounts_token_expired所有匹配账号 token 都过期
504replenish_timeout触发补货但超时
7. 限流 (Rate Limit)

每用户默认 60 请求/分钟,管理员可给单用户调高。达到上限后返回 429,响应头带:

HTTP/1.1 429 Too Many Requests
X-RateLimit-Retry-After: 42

{"detail": {"code": "rate_limit_exceeded", "message": "rate limit exceeded"}}

成功响应也会带 X-RateLimit-Remaining header 告知剩余额度,方便客户端做退避。

8. 多语言示例 — 完整开卡流程
import requests

BASE = "https://cvv.nerver.cc"
API_KEY = "<your_64_hex_api_key>"
HEADERS = {"X-API-Key": API_KEY}

# 1. 看余额
r = requests.get(f"{BASE}/api/v1/account", headers=HEADERS)
r.raise_for_status()
print(r.json())
# → {"username": "alice", "balance_yuan": "1234.50", ...}

# 2. 看有哪些业务
r = requests.get(f"{BASE}/api/v1/businesses", headers=HEADERS)
for biz in r.json():
    print(biz["name"], biz["bin_prefix"], "库存", biz["available_stock"])

# 3. 批量开卡
r = requests.post(
    f"{BASE}/api/v1/cards/allocate",
    headers={**HEADERS, "Content-Type": "application/json"},
    json={"business": "kiro", "count": 3},
    timeout=60,  # replenish 可能耗时
)
if r.status_code == 402:
    err = r.json()["detail"]
    print(f"余额不足: 需要 {err['extra']['need_cents']} 分")
elif r.status_code == 200:
    for card in r.json()["allocated"]:
        print(f"卡 #{card['id']}: {card['pan']}  {card['exp']}  cvv={card['cvv']}")
else:
    print("失败:", r.status_code, r.text)

# 4. 列表 & 取消
r = requests.get(f"{BASE}/api/v1/cards?business=kiro&status=active", headers=HEADERS)
for card in r.json()["items"]:
    print(card["id"], card["pan"])

# 取消一张
r = requests.post(f"{BASE}/api/v1/cards/12345/cancel", headers=HEADERS)
// Node 18+ 自带 fetch
const BASE = 'https://cvv.nerver.cc';
const API_KEY = '<your_64_hex_api_key>';
const H = {'X-API-Key': API_KEY, 'Content-Type': 'application/json'};

// 批量开卡
const r = await fetch(`${BASE}/api/v1/cards/allocate`, {
    method: 'POST',
    headers: H,
    body: JSON.stringify({business: 'kiro', count: 3}),
});
const data = await r.json();
if (!r.ok) {
    console.error('失败:', data);
    process.exit(1);
}
for (const card of data.allocated) {
    console.log(`卡 #${card.id}: ${card.pan}  ${card.exp}  cvv=${card.cvv}`);
}
# 环境变量存 key
export KEY="<your_64_hex_api_key>"

# 看余额
curl -sS -H "X-API-Key: $KEY" https://cvv.nerver.cc/api/v1/account | jq

# 批量开 3 张 kiro 业务卡
curl -sS -X POST https://cvv.nerver.cc/api/v1/cards/allocate \
     -H "X-API-Key: $KEY" \
     -H "Content-Type: application/json" \
     -d '{"business":"kiro","count":3}' | jq

# 列出所有 active 卡
curl -sS -H "X-API-Key: $KEY" \
     "https://cvv.nerver.cc/api/v1/cards?status=active&page_size=100" | jq
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

const (
    baseURL = "https://cvv.nerver.cc"
    apiKey  = "<your_64_hex_api_key>"
)

func main() {
    body, _ := json.Marshal(map[string]any{
        "business": "kiro", "count": 3,
    })
    req, _ := http.NewRequest("POST",
        baseURL+"/api/v1/cards/allocate",
        bytes.NewReader(body))
    req.Header.Set("X-API-Key", apiKey)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil { panic(err) }
    defer resp.Body.Close()

    var out struct {
        Allocated []struct {
            ID  int    `json:"id"`
            PAN string `json:"pan"`
            CVV string `json:"cvv"`
            Exp string `json:"exp"`
        } `json:"allocated"`
    }
    json.NewDecoder(resp.Body).Decode(&out)
    for _, c := range out.Allocated {
        fmt.Printf("卡 #%d: %s  %s  cvv=%s\n", c.ID, c.PAN, c.Exp, c.CVV)
    }
}

更多细节 (schema / 参数验证规则) 见交互式文档 /api/v1/docs (Swagger UI)。 问题反馈请到管理员群。