用户模块

功能说明

接口前缀为:

  1. 主站:https://ai.burncloud.com
  2. 企业站:https://b.burncloud.com

核心用户管理系统,实现四级权限体系(公开/用户/管理员/Root)和完整的用户生命周期管理。包含注册登录、个人资料、Token 管理、充值支付、推广系统等功能。支持 2FA、邮箱验证和多种 OAuth 登录方式。

账号注册/登录

🔐 无需鉴权

注册新账号

💡 请求示例:
const response = await fetch('/api/user/register', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json'  
  },  
  body: JSON.stringify({  
    username: "newuser",  
    password: "password123",  
    email: "user@example.com",  
    verification_code: "123456",  
    aff_code: "INVITE123"  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "用户注册成功"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "管理员关闭了新用户注册"  
}
🧾 字段说明:

用户登录

💡 请求示例:
const response = await fetch('/api/user/login', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json'  
  },  
  body: JSON.stringify({  
    username: "testuser",  
    password: "password123"  
  })  
});  
const data = await response.json();
✅ 成功响应示例(无 2FA):
{  
  "success": true,  
  "message": "登录成功",  
  "data": {  
    "token": "user_access_token",  
    "user": {  
      "id": 1,  
      "username": "testuser",  
      "role": 1,  
      "quota": 1000000  
    }  
  }  
}
✅ 成功响应示例(需要 2FA):
{  
  "success": true,  
  "message": "请输入两步验证码",  
  "data": {  
    "require_2fa": true  
  }  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "管理员关闭了密码登录"  
}
🧾 字段说明:

Epay 支付回调

💡 请求示例:
// 通常由支付系统自动回调,前端无需主动调用  
// 示例URL: /api/user/epay/notify?trade_no=USR1NO123456&money=10.00&trade_status=TRADE_SUCCESS
✅ 成功响应示例:
{  
  "success": true,  
  "message": "支付成功"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "订单不存在或已处理"  
}
🧾 字段说明:

列出所有分组(无鉴权版)

💡 请求示例:
const response = await fetch('/api/user/groups', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json'  
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": {  
    "default": {  
      "ratio": 1.0,  
      "desc": "默认分组"  
    },  
    "vip": {  
      "ratio": 0.8,  
      "desc": "VIP分组"  
    },  
    "auto": {  
      "ratio": "自动",  
      "desc": "自动选择最优分组"  
    }  
  }  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "获取分组信息失败"  
}
🧾 字段说明:

🔐 用户鉴权

退出登录

💡 请求示例:
const response = await fetch('/api/user/logout', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": ""  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "会话清除失败"  
}
🧾 字段说明:

用户自身操作

🔐 用户鉴权

获取自己所在分组

💡 请求示例:
const response = await fetch('/api/user/self/groups', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": {  
    "default": {  
      "ratio": 1.0,  
      "desc": "默认分组"  
    },  
    "vip": {  
      "ratio": 0.8,  
      "desc": "VIP分组"  
    },  
    "auto": {  
      "ratio": "自动",  
      "desc": "自动选择最优分组"  
    }  
  }  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "获取分组信息失败"  
}
🧾 字段说明:

获取个人资料

💡 请求示例:
const response = await fetch('/api/user/self', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": {  
    "id": 1,  
    "username": "testuser",  
    "display_name": "Test User",  
    "role": 1,  
    "status": 1,  
    "email": "user@example.com",  
    "group": "default",  
    "quota": 1000000,  
    "used_quota": 50000,  
    "request_count": 100,  
    "aff_code": "ABC123",  
    "aff_count": 5,  
    "aff_quota": 10000,  
    "aff_history_quota": 50000,  
    "inviter_id": 0,  
    "linux_do_id": "",  
    "setting": "{}",  
    "stripe_customer": "",  
    "sidebar_modules": "{\"chat\":{\"enabled\":true}}",  
    "permissions": {  
      "can_view_logs": true,  
      "can_manage_tokens": true  
    }  
  }  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "获取用户信息失败"  
}
🧾 字段说明:

获取模型可见性

💡 请求示例:
const response = await fetch('/api/user/models', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": [  
    "gpt-3.5-turbo",  
    "gpt-4",  
    "claude-3-sonnet",  
    "claude-3-haiku"  
  ]  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "获取模型列表失败"  
}
🧾 字段说明:

修改个人资料

💡 请求示例(更新个人信息):
const response = await fetch('/api/user/self', {  
  method: 'PUT',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    display_name: "New Display Name",  
    email: "newemail@example.com"  
  })  
});  
const data = await response.json();
💡 请求示例(更新侧边栏设置):
const response = await fetch('/api/user/self', {  
  method: 'PUT',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    sidebar_modules: JSON.stringify({  
      chat: { enabled: true, playground: true },  
      console: { enabled: true, token: true }  
    })  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "更新成功"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "输入不合法"  
}
🧾 字段说明:

注销账号

💡 请求示例:
const response = await fetch('/api/user/self', {  
  method: 'DELETE',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": ""  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "不能删除超级管理员账户"  
}
🧾 字段说明:

生成用户级别 Access Token

💡 请求示例:
const response = await fetch('/api/user/token', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": "<YOUR_API_KEY>"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "生成令牌失败"  
}
🧾 字段说明:

获取推广码信息

💡 请求示例:
const response = await fetch('/api/user/aff', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": "ABC123"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "获取推广码失败"  
}
🧾 字段说明:

余额直充

💡 请求示例:
const response = await fetch('/api/user/topup', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    key: "REDEEM123456"  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "兑换成功",  
  "data": 100000  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "兑换码无效或已使用"  
}
🧾 字段说明:

提交支付订单

💡 请求示例:
const response = await fetch('/api/user/pay', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    amount: 10000,  
    payment_method: "alipay",  
    top_up_code: ""  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "success",  
  "data": {  
    "pid": "12345",  
    "type": "alipay",  
    "out_trade_no": "USR1NO123456",  
    "notify_url": "https://example.com/notify",  
    "return_url": "https://example.com/return",  
    "name": "TUC10000",  
    "money": "10.00",  
    "sign": "abc123def456"  
  },  
  "url": "https://pay.example.com/submit"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "充值数量不能小于 1000"  
}
🧾 字段说明:

余额支付

💡 请求示例:
const response = await fetch('/api/user/amount', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    amount: 10000,  
    top_up_code: ""  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "success",  
  "data": "10.00"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "充值数量不能小于 1000"  
}
🧾 字段说明:

推广额度转账

💡 请求示例:
const response = await fetch('/api/user/aff_transfer', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    quota: 50000  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "划转成功"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "邀请额度不足!"  
}
🧾 字段说明:

更新用户设置

💡 请求示例:
const response = await fetch('/api/user/setting', {  
  method: 'PUT',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    theme: "dark",  
    language: "zh-CN",  
    notifications: {  
      email: true,  
      browser: false  
    }  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "设置更新成功"  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "设置格式错误"  
}
🧾 字段说明:

管理员用户管理

🔐 管理员鉴权

获取全部用户列表

💡 请求示例:
const response = await fetch('/api/user/?p=1&page_size=20', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": {  
    "items": [  
      {  
        "id": 1,  
        "username": "testuser",  
        "display_name": "Test User",  
        "role": 1,  
        "status": 1,  
        "email": "user@example.com",  
        "group": "default",  
        "quota": 1000000,  
        "used_quota": 50000,  
        "request_count": 100  
      }  
    ],  
    "total": 50,  
    "page": 1,  
    "page_size": 20  
  }  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "获取用户列表失败"  
}
🧾 字段说明:

搜索用户

💡 请求示例:
const response = await fetch('/api/user/search?keyword=test&group=default&p=1&page_size=20', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": {  
    "items": [  
      {  
        "id": 1,  
        "username": "testuser",  
        "display_name": "Test User",  
        "role": 1,  
        "status": 1,  
        "email": "test@example.com",  
        "group": "default"  
      }  
    ],  
    "total": 1,  
    "page": 1,  
    "page_size": 20  
  }  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "搜索用户失败"  
}
🧾 字段说明:

获取单个用户信息

💡 请求示例:
const response = await fetch('/api/user/123', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": "",  
  "data": {  
    "id": 123,  
    "username": "targetuser",  
    "display_name": "Target User",  
    "role": 1,  
    "status": 1,  
    "email": "target@example.com",  
    "group": "default",  
    "quota": 1000000,  
    "used_quota": 50000,  
    "request_count": 100,  
    "aff_code": "ABC123",  
    "aff_count": 5  
  }  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "无权获取同级或更高等级用户的信息"  
}
🧾 字段说明:

创建用户

💡 请求示例:
const response = await fetch('/api/user/', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'Bearer your_user_id' 
  },  
  body: JSON.stringify({  
    username: "newuser",  
    password: "password123",  
    display_name: "New User",  
    role: 1  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": ""  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "无法创建权限大于等于自己的用户"  
}
🧾 字段说明:

冻结/重置等管理操作

💡 请求示例:
const response = await fetch('/api/user/manage', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    id: 123,  
    action: "disable"  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": ""  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "无法禁用超级管理员用户"  
}
🧾 字段说明:

更新用户

💡 请求示例:
const response = await fetch('/api/user/', {  
  method: 'PUT',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'Bearer your_user_id'
  },  
  body: JSON.stringify({  
    id: 123,  
    username: "updateduser",  
    display_name: "Updated User",  
    email: "updated@example.com",  
    quota: 2000000,  
    role: 1,  
    status: 1  
  })  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": ""  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "无权更新同权限等级或更高权限等级的用户信息"  
}
🧾 字段说明:

删除用户

💡 请求示例:
const response = await fetch('/api/user/123', {  
  method: 'DELETE',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'Bearer your_user_id'
  }  
});  
const data = await response.json();
✅ 成功响应示例:
{  
  "success": true,  
  "message": ""  
}
❗ 失败响应示例:
{  
  "success": false,  
  "message": "无权删除同权限等级或更高权限等级的用户"  
}
🧾 字段说明:

Revision #1
Created 30 October 2025 03:36:33 by Burncloud
Updated 30 October 2025 03:36:56 by Burncloud