API 文档

基本信息

所有接口遵循统一的响应格式:

{
  "code": 0,
  "message": "响应消息",
  "data": {},
  "timestamp": 1672531200000
}

API 详情

1. 发送短信验证码

端点: POST /otp

描述: 向用户手机发送一次性短信验证码,可用于注册或登录等后续操作。

请求体:

{
  "phone": "+8613800138000",
  "purpose": "signup"
}

参数:

cURL 示例:

curl -X POST https://rewriting.congrongtech.cn/otp \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "+8613800138000",
    "purpose": "login"
  }'

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "验证码发送成功",
  "data": null,
  "timestamp": 1672531200000
}

错误响应:


2. 用户注册

端点: POST /user/register

描述: 创建新用户账户,支持邮箱注册和可选的手机号绑定。

请求体:

{
  "username": "testuser",
  "email": "test@example.com",
  "phone": "+8613800138000",
  "verification_code": "123456",
  "password": "password123",
  "invite_code": "ABC123"
}

参数:

cURL 示例:

# 基础注册(不使用手机号和邀请码)
curl -X POST https://rewriting.congrongtech.cn/user/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "email": "test@example.com",
    "verification_code": "123456",
    "password": "password123"
  }'

# 完整注册(包含手机号和邀请码)
curl -X POST https://rewriting.congrongtech.cn/user/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "email": "test@example.com",
    "phone": "+8613800138000",
    "verification_code": "123456",
    "password": "password123",
    "invite_code": "ABC123"
  }'

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "注册成功",
  "data": {
    "id": 1,
    "username": "testuser",
    "email": "test@example.com",
    "phone": "+8613800138000",
    "invite_code": "XYZ789",
    "role": "user",
    "points_balance": 0,
    "created_at": "2023-12-01T10:00:00.000Z",
    "invited_by": "inviter_username"
  },
  "timestamp": 1672531200000
}

错误响应:


3. 用户登录

端点: POST /user/login

描述: 用户登录接口,支持用户名密码登录和手机号OTP验证码登录两种方式。

请求体:

{
  "username": "testuser",
  "password": "password123"
}

{
  "phone": "+8613800138000",
  "verification_code": "123456"
}

参数:

注意: 两种登录方式只能选择一种,不能同时提供。

cURL 示例:

# 用户名密码登录
curl -X POST https://rewriting.congrongtech.cn/user/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "password123"
  }'

# 手机号OTP登录
curl -X POST https://rewriting.congrongtech.cn/user/login \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "+8613800138000",
    "verification_code": "123456"
  }'

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "登录成功",
  "data": {
    "user": {
      "id": "uuid-string",
      "username": "testuser",
      "email": "test@example.com",
      "phone": "+8613800138000",
      "role": "user",
      "points_balance": 100,
      "invite_code": "XYZ789",
      "created_at": "2023-12-01T10:00:00.000Z"
    },
    "session": {
      "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "expires_at": 1701470400
    }
  },
  "timestamp": 1672531200000
}

错误响应:


4. 查询用户列表

端点: GET /user/list

描述: 查询用户列表,需要登录并具备 adminagent 角色。

请求头:

Authorization: Bearer <access_token>

权限说明:

cURL 示例:

# 管理员查询所有用户
curl -X GET https://rewriting.congrongtech.cn/user/list \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

# 代理查询下级用户
curl -X GET https://rewriting.congrongtech.cn/user/list \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "获取用户列表成功",
  "data": {
    "users": [
      {
        "id": 1,
        "user_id": "uuid-string",
        "username": "testuser",
        "email": "test@example.com",
        "phone": "+8613800138000",
        "role": "user",
        "points_balance": 120,
        "invite_code": "INV001",
        "invited_by": null,
        "invited_by_username": null,
        "created_at": "2023-12-01T10:00:00.000Z"
      }
    ],
    "total": 1,
    "scope": "all"
  },
  "timestamp": 1672531200000
}

响应字段说明:

错误响应:


5. 管理员修改用户角色

端点: POST /user/update-role

描述: 管理员修改任意用户的角色,支持在 adminagentuser 之间切换。

请求头:

Authorization: Bearer <access_token>

请求体:

{
  "target_user_id": "uuid-string",
  "role": "agent"
}

参数:

cURL 示例:

curl -X POST https://rewriting.congrongtech.cn/user/update-role \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "target_user_id": "8f8b2c9e-5a4f-4a38-b9c0-77cbd9c0bb01",
    "role": "agent"
  }'

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "角色更新成功",
  "data": {
    "id": 12,
    "user_id": "8f8b2c9e-5a4f-4a38-b9c0-77cbd9c0bb01",
    "username": "targetuser",
    "email": "target@example.com",
    "phone": "+8613800138001",
    "role": "agent",
    "previous_role": "user",
    "points_balance": 120,
    "invite_code": "INV123",
    "invited_by": null,
    "created_at": "2023-12-01T10:00:00.000Z"
  },
  "timestamp": 1672531200000
}

错误响应:

说明:


6. 用户退出登录

端点: POST /user/logout

描述: 用户退出登录接口,使当前访问令牌和刷新令牌失效。

请求头:

Authorization: Bearer <access_token>
refresh_token: <refresh_token>

参数:

cURL 示例:

# 基础退出(仅使用access_token)
curl -X POST https://rewriting.congrongtech.cn/user/logout \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

# 完整退出(同时撤销refresh_token)
curl -X POST https://rewriting.congrongtech.cn/user/logout \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "refresh_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "退出登录成功",
  "data": null,
  "timestamp": 1672531200000
}

错误响应:

说明:


7. 用户修改密码

端点: POST /user/change-password

描述: 用户修改密码接口,需要验证当前密码并设置新密码,修改成功后会退出所有会话。

请求头:

Authorization: Bearer <access_token>

请求体:

{
  "current_password": "oldpassword123",
  "new_password": "newpassword456"
}

参数:

cURL 示例:

curl -X POST https://rewriting.congrongtech.cn/user/change-password \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "current_password": "oldpassword123",
    "new_password": "newpassword456"
  }'

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "密码修改成功,请重新登录",
  "data": null,
  "timestamp": 1672531200000
}

错误响应:

说明:


8. 提交降重或降AI率任务

端点: POST /ai/reduce-task

描述: 提交降重或降AI率任务,支持知网和维普平台。需要用户登录认证,按文本长度动态计算积分消耗,并会基于平台和任务类型自动切换上游 AI 服务。

请求头:

Authorization: Bearer <access_token>

请求体:

{
  "text": "待处理的文本内容(最多3000字)",
  "platform": "zhiwang",
  "type": "reduce-plagiarism"
}

参数:

服务路由策略:

platform type service 字段 REDUCEAI toolName / CHEEYUAN product_type
zhiwang reduce-plagiarism reduceai onlyjc
zhiwang reduce-ai-rate cheeyuan 78 (固定 product_type)
weipu reduce-plagiarism reduceai onlyjc
weipu reduce-ai-rate reduceai onlyai

客户端无需关心上游具体实现,按平台+类型组合传参即可。

积分说明:

cURL 示例:

# 知网降重
curl -X POST https://rewriting.congrongtech.cn/ai/reduce-task \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "text": "需要降重的文本内容",
    "platform": "zhiwang",
    "type": "reduce-plagiarism"
  }'

# 知网降AI率
curl -X POST https://rewriting.congrongtech.cn/ai/reduce-task \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "text": "需要降AI率的文本内容",
    "platform": "zhiwang",
    "type": "reduce-ai-rate"
  }'

# 维普降重
curl -X POST https://rewriting.congrongtech.cn/ai/reduce-task \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "text": "需要降重的文本内容",
    "platform": "weipu",
    "type": "reduce-plagiarism"
  }'

# 维普降AI率
curl -X POST https://rewriting.congrongtech.cn/ai/reduce-task \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "text": "需要降AI率的文本内容",
    "platform": "weipu",
    "type": "reduce-ai-rate"
  }'

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "任务提交成功",
  "data": {
    "taskId": "onlyjc_98631379_1758017276712",
    "service": "reduceai",
    "newBalance": 462,
    "cost": 3.6
  },
  "timestamp": 1672531200000
}

说明:

错误响应:


9. 查询任务结果

端点: POST /ai/result

描述: 查询降重或降AI率任务的处理结果。需要用户登录认证,会根据 service 字段自动调用 REDUCEAI 或 CHEEYUAN,并把最新状态返回给客户端。

请求头:

Authorization: Bearer <access_token>

请求体:

{
  "taskId": "onlyjc_98631379_1758017276712",
  "service": "reduceai"
}

参数:

cURL 示例:

# 查询REDUCEAI服务任务结果
curl -X POST https://rewriting.congrongtech.cn/ai/result \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "taskId": "onlyjc_98631379_1758017276712",
    "service": "reduceai"
  }'

# 查询CHEEYUAN服务任务结果
curl -X POST https://rewriting.congrongtech.cn/ai/result \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "taskId": "123456",
    "service": "cheeyuan"
  }'

成功响应 (HTTP 200):

REDUCEAI服务处理中响应(包括上游短暂不可用时返回的占位结果):

{
  "code": 0,
  "message": "查询成功",
  "data": {
    "status": "processing",
    "progress": 39,
    "result": null,
    "queuePosition": 0,
    "cost": 5
  },
  "timestamp": 1672531200000
}

REDUCEAI服务完成响应(若 result 是字符串会触发 R2 输出快照上传):

{
  "code": 0,
  "message": "查询成功",
  "data": {
    "status": "completed",
    "progress": 100,
    "result": "处理后的文本内容",
    "cost": 5
  },
  "timestamp": 1672531200000
}

CHEEYUAN服务处理中响应:

{
  "code": 0,
  "message": "查询成功",
  "data": {
    "status": "processing",
    "progress": 0,
    "result": null,
    "created_at": "2025-11-03 14:04:04",
    "updated_at": "2025-11-03 14:04:04"
  },
  "timestamp": 1672531200000
}

REDUCEAI服务失败响应:

{
  "code": 0,
  "message": "查询成功",
  "data": {
    "status": "failed",
    "progress": 0,
    "result": null,
    "cost": 5
  },
  "timestamp": 1672531200000
}

CHEEYUAN服务完成响应:

{
  "code": 0,
  "message": "查询成功",
  "data": {
    "status": "completed",
    "progress": 100,
    "result": "处理后的文本内容",
    "created_at": "2025-11-03 14:04:04",
    "updated_at": "2025-11-03 14:04:16"
  },
  "timestamp": 1672531200000
}

CHEEYUAN服务失败响应:

{
  "code": 0,
  "message": "查询成功",
  "data": {
    "status": "failed",
    "progress": 0,
    "result": null,
    "created_at": "2025-11-03 14:04:04",
    "updated_at": "2025-11-03 14:04:16"
  },
  "timestamp": 1672531200000
}

说明:

错误响应:


10. 查询用户积分

端点: POST /ai/points

描述: 查询当前用户的积分余额和积分计费规则。需要用户登录认证,返回值与扣费逻辑共用同一套配置,适合在前端实时展示。

请求头:

Authorization: Bearer <access_token>

参数:

cURL 示例:

curl -X POST https://rewriting.congrongtech.cn/ai/points \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "查询成功",
  "data": {
    "points_balance": 450,
    "task_cost": 3,
    "cost_per_1000_chars": 3
  },
  "timestamp": 1672531200000
}

错误响应:

说明:


11. 查询积分余额

端点: GET /points/balance

描述: 查询当前用户的积分余额。需要用户登录认证。

请求头:

Authorization: Bearer <access_token>

参数:

cURL 示例:

curl -X GET https://rewriting.congrongtech.cn/points/balance \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "查询积分余额成功",
  "data": {
    "points_balance": 1500
  },
  "timestamp": 1672531200000
}

错误响应:

12. 查询充值记录

端点: GET /points/recharges

描述: 查询积分充值记录。仅管理员和代理可用,管理员返回所有用户的充值记录,代理仅返回其邀请的下级用户充值记录。

请求头:

Authorization: Bearer <access_token>

查询参数:

cURL 示例:

# 管理员查询全部充值记录
curl -X GET "https://rewriting.congrongtech.cn/points/recharges?page=1&limit=20" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

# 代理查询下级充值记录
curl -X GET "https://rewriting.congrongtech.cn/points/recharges?page=1&limit=20" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "查询充值记录成功",
  "data": {
    "records": [
      {
        "id": 101,
        "profile_id": 456,
        "amount": 100,
        "balance_after": 450,
        "description": "管理员充值",
        "reference_id": "admin_topup_202401",
        "is_successful": true,
        "created_at": "2024-01-18T09:00:00.000Z",
        "profile": {
          "id": 456,
          "user_id": "8f8b2c9e-5a4f-4a38-b9c0-77cbd9c0bb01",
          "username": "targetuser",
          "email": "target@example.com",
          "phone": "+8613800138001",
          "role": "agent",
          "invited_by": 123,
          "invited_by_username": "admin"
        }
      }
    ],
    "pagination": {
      "current_page": 1,
      "per_page": 20,
      "total": 5,
      "total_pages": 1,
      "has_next_page": false,
      "has_prev_page": false
    },
    "scope": "all"
  },
  "timestamp": 1672531200000
}

响应字段说明:

错误响应:

说明:


13. 查询积分交易记录

端点: GET /points/transactions

描述: 查询当前用户的积分交易记录,支持分页和筛选。需要用户登录认证。

请求头:

Authorization: Bearer <access_token>

查询参数:

cURL 示例:

# 基础查询
curl -X GET "https://rewriting.congrongtech.cn/points/transactions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

# 分页查询
curl -X GET "https://rewriting.congrongtech.cn/points/transactions?page=2&limit=10" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

# 按交易类型筛选
curl -X GET "https://rewriting.congrongtech.cn/points/transactions?transaction_type=spend" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

# 按时间范围筛选
curl -X GET "https://rewriting.congrongtech.cn/points/transactions?start_date=2023-12-01T00:00:00.000Z&end_date=2023-12-31T23:59:59.999Z" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

# 复合查询
curl -X GET "https://rewriting.congrongtech.cn/points/transactions?page=1&limit=20&transaction_type=spend&start_date=2023-12-01T00:00:00.000Z" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "查询积分交易记录成功",
  "data": {
    "transactions": [
      {
        "id": 1,
        "profile_id": 123,
        "transaction_type": "spend",
        "amount": -3.6,
        "balance_after": 146.4,
        "description": "AI降重任务消费",
        "reference_id": "onlyjc_98631379_1758017276712",
        "is_successful": true,
        "created_at": "2023-12-01T10:30:00.000Z"
      },
      {
        "id": 2,
        "profile_id": 123,
        "transaction_type": "recharge",
        "amount": 100,
        "balance_after": 150,
        "description": "管理员充值",
        "reference_id": "admin_topup_001",
        "is_successful": true,
        "created_at": "2023-12-01T09:00:00.000Z"
      }
    ],
    "pagination": {
      "current_page": 1,
      "per_page": 20,
      "total": 25,
      "total_pages": 2,
      "has_next_page": true,
      "has_prev_page": false
    }
  },
  "timestamp": 1672531200000
}

响应字段说明:

错误响应:

说明:


14. 积分返还申请

端点: POST /points/refund

描述: 针对失败的积分消费记录申请返还积分。需要用户登录认证。

请求头:

Authorization: Bearer <access_token>

请求体:

{
  "transaction_id": 123
}

参数:

cURL 示例:

curl -X POST https://rewriting.congrongtech.cn/points/refund \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "transaction_id": 123
  }'

成功响应 (HTTP 200):

{
  "code": 0,
  "message": "积分返还成功",
  "data": {
    "success": true,
    "points_balance": 456.4
  },
  "timestamp": 1672531200000
}

错误响应:

说明:


📝 Development Notes

This is a complete example application demonstrating various features and best practices of the Hono framework on EdgeOne Functions.

The project structure is clear, code is well organized, and suitable as a starting template for other projects.