# AI 有声书 API 接口文档

## 目录

- [认证模块](#认证模块)
- [TTS 模块](#tts 模块)
- [音频模块](#音频模块)
- [会员模块](#会员模块)
- [分享模块](#分享模块)

---

## 认证模块

### 1. 发送验证码

**接口**: `POST /api/auth/send-code`

**请求参数**:
```json
{
  "phone": "13800138000"
}
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "success": true
  }
}
```

---

### 2. 手机号登录

**接口**: `POST /api/auth/login`

**请求参数**:
```json
{
  "phone": "13800138000",
  "code": "123456"
}
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "user": {
      "id": "xxx",
      "nickname": "用户昵称",
      "avatar": "头像 URL",
      "memberLevel": 0
    }
  }
}
```

---

### 3. 获取用户信息

**接口**: `GET /api/auth/user-info`

**Headers**:
```
Authorization: Bearer <token>
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "id": "xxx",
    "nickname": "用户昵称",
    "avatar": "头像 URL",
    "memberLevel": 0
  }
}
```

---

## TTS 模块

### 1. 获取音色列表

**接口**: `GET /api/tts/voices`

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "voices": [
      {
        "id": "xiaoyun",
        "name": "小云",
        "gender": "female",
        "description": "温柔女声",
        "preview": "试听 URL"
      }
    ]
  }
}
```

---

### 2. 生成音频

**接口**: `POST /api/tts/generate`

**Headers**:
```
Authorization: Bearer <token>
```

**请求参数**:
```json
{
  "text": "要转换的文本内容",
  "voiceId": "xiaoyun",
  "voiceParams": {
    "speed": 1.0,
    "pitch": 0,
    "volume": 50
  }
}
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "audioId": "xxx",
    "audioUrl": "/uploads/xxx/output.mp3",
    "duration": 120.5,
    "size": 1024000
  }
}
```

---

## 音频模块

### 1. 获取音频列表

**接口**: `GET /api/audio/list`

**Headers**:
```
Authorization: Bearer <token>
```

**Query 参数**:
```
page=1&pageSize=20
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "list": [
      {
        "_id": "xxx",
        "title": "标题",
        "summary": "摘要",
        "tags": ["标签 1", "标签 2"],
        "audioUrl": "/uploads/xxx/output.mp3",
        "audioDuration": 120.5,
        "wordCount": 1000,
        "voiceId": "xiaoyun",
        "isFavorite": false,
        "createdAt": "2024-01-01T00:00:00Z"
      }
    ],
    "total": 100,
    "page": 1,
    "pageSize": 20,
    "totalPages": 5
  }
}
```

---

### 2. 获取音频详情

**接口**: `GET /api/audio/:id`

**Headers**:
```
Authorization: Bearer <token>
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "_id": "xxx",
    "title": "标题",
    "text": "原文内容",
    "summary": "摘要",
    "tags": ["标签 1", "标签 2"],
    "audioUrl": "/uploads/xxx/output.mp3",
    "audioDuration": 120.5,
    "wordCount": 1000,
    "isFavorite": false,
    "createdAt": "2024-01-01T00:00:00Z"
  }
}
```

---

### 3. 删除音频

**接口**: `DELETE /api/audio/:id`

**Headers**:
```
Authorization: Bearer <token>
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": null
}
```

---

### 4. 切换收藏

**接口**: `PUT /api/audio/:id/favorite`

**Headers**:
```
Authorization: Bearer <token>
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "isFavorite": true
  }
}
```

---

## 会员模块

### 1. 获取会员权益

**接口**: `GET /api/member/benefits`

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "levels": [
      {
        "level": 0,
        "name": "免费版",
        "price": 0,
        "features": ["每日 3 次", "每次 5000 字"]
      },
      {
        "level": 1,
        "name": "月度会员",
        "price": 19.9,
        "features": ["每日 20 次", "每次 50000 字", "全部音色"]
      },
      {
        "level": 2,
        "name": "年度会员",
        "price": 199,
        "features": ["无限次数", "无字数限制", "全部音色", "优先处理"]
      }
    ]
  }
}
```

---

### 2. 获取会员状态

**接口**: `GET /api/member/status`

**Headers**:
```
Authorization: Bearer <token>
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "level": 0,
    "levelName": "免费版",
    "isValid": true,
    "quota": {
      "dailyLimit": 3,
      "dailyUsed": 1,
      "dailyRemaining": 2,
      "wordLimit": 5000
    }
  }
}
```

---

### 3. 创建订单

**接口**: `POST /api/member/order`

**Headers**:
```
Authorization: Bearer <token>
```

**请求参数**:
```json
{
  "productType": "monthly" // 或 "yearly"
}
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "orderNo": "ORDER_XXX",
    "amount": 19.9
  }
}
```

---

### 4. 支付订单（模拟）

**接口**: `POST /api/member/pay/mock`

**Headers**:
```
Authorization: Bearer <token>
```

**请求参数**:
```json
{
  "orderNo": "ORDER_XXX"
}
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": null
}
```

---

## 分享模块

### 1. 获取分享卡片

**接口**: `GET /api/share/card/:audioId`

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "title": "音频标题",
    "description": "音频简介",
    "imageUrl": {
      "type": "gradient",
      "colors": ["#4f46e5", "#818cf8"],
      "icon": "🎵"
    },
    "link": "http://localhost:3000/#/pages/player/index?id=xxx"
  }
}
```

---

### 2. 获取二维码数据

**接口**: `GET /api/share/qrcode/:audioId`

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": {
    "text": "http://localhost:3000/#/pages/player/index?id=xxx"
  }
}
```

---

### 3. 记录分享行为

**接口**: `POST /api/share/track`

**Headers**:
```
Authorization: Bearer <token>
```

**请求参数**:
```json
{
  "audioId": "xxx",
  "platform": "wechat" // wechat, weibo, qq 等
}
```

**响应**:
```json
{
  "code": 0,
  "message": "success",
  "data": null
}
```

---

## 错误码说明

| 错误码 | 说明 |
|--------|------|
| 0 | 成功 |
| 400 | 请求参数错误 |
| 401 | 未授权，需要登录 |
| 403 | 禁止访问 |
| 404 | 资源不存在 |
| 500 | 服务器内部错误 |

---

## 响应格式说明

所有接口统一返回格式：

```json
{
  "code": 0,      // 错误码，0 表示成功
  "message": "",  // 提示信息
  "data": {}      // 返回数据
}
```
