开发环境: http://localhost:8000
生产环境: https://api.yourdomain.com
{
"code": 200,
"message": "success",
"data": {}
}- 200: 成功
- 400: 请求参数错误
- 401: 未认证
- 403: 无权限
- 404: 资源不存在
- 429: 请求过于频繁
- 500: 服务器内部错误
使用JWT Token认证,在请求头中添加:
Authorization: Bearer {access_token}
POST /api/v1/auth/register请求体:
{
"username": "string",
"email": "string",
"password": "string"
}响应:
{
"code": 200,
"message": "注册成功",
"data": {
"id": 1,
"username": "testuser",
"email": "test@example.com",
"credit_balance": 0,
"is_member": false,
"referral_code": "ABC123"
}
}POST /api/v1/auth/login请求体:
{
"username": "string",
"password": "string"
}响应:
{
"code": 200,
"message": "登录成功",
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"token_type": "bearer",
"user": {
"id": 1,
"username": "testuser",
"email": "test@example.com",
"credit_balance": 100,
"is_member": true,
"membership_type": "monthly"
}
}
}POST /api/v1/auth/refresh请求头:
Authorization: Bearer {refresh_token}
响应:
{
"code": 200,
"message": "Token刷新成功",
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"token_type": "bearer"
}
}GET /api/v1/auth/me响应:
{
"code": 200,
"message": "success",
"data": {
"id": 1,
"username": "testuser",
"email": "test@example.com",
"credit_balance": 100,
"is_member": true,
"membership_type": "monthly",
"membership_end_date": "2026-02-22T10:00:00",
"referral_code": "ABC123"
}
}POST /api/v1/credit/recharge请求体:
{
"amount": 10.00,
"payment_method": "alipay",
"coupon_code": "DISCOUNT10"
}响应:
{
"code": 200,
"message": "订单创建成功",
"data": {
"order_id": "R202601221000001",
"amount": 10.00,
"credits": 100,
"payment_url": "https://payment.example.com/pay?order=..."
}
}POST /api/v1/credit/membership请求体:
{
"membership_type": "monthly",
"payment_method": "wechat"
}响应:
{
"code": 200,
"message": "会员订单创建成功",
"data": {
"order_id": "M202601221000001",
"membership_type": "monthly",
"amount": 9.90,
"payment_url": "https://payment.example.com/pay?order=..."
}
}POST /api/v1/credit/payment/callback请求体:
{
"order_id": "R202601221000001",
"payment_method": "alipay",
"transaction_id": "2026012212345678",
"status": "success"
}GET /api/v1/credit/balance响应:
{
"code": 200,
"message": "success",
"data": {
"credit_balance": 100,
"is_member": true,
"membership_type": "monthly",
"membership_end_date": "2026-02-22T10:00:00"
}
}GET /api/v1/credit/transactions?page=1&page_size=20响应:
{
"code": 200,
"message": "success",
"data": {
"total": 50,
"page": 1,
"page_size": 20,
"items": [
{
"id": 1,
"type": "recharge",
"amount": 100,
"balance_after": 200,
"description": "充值10元",
"created_at": "2026-01-22T10:00:00"
}
]
}
}GET /api/v1/credit/recharge/orders?page=1&page_size=20GET /api/v1/credit/membership/orders?page=1&page_size=20POST /api/v1/writing/{tool_type}/generate路径参数:
- tool_type: 工具类型(wechat_article, xiaohongshu_note等)
请求体:
{
"title": "如何提高工作效率",
"keywords": ["时间管理", "效率工具"],
"requirements": "字数2000字,包含实用技巧",
"model_id": 1
}响应:
{
"code": 200,
"message": "生成成功",
"data": {
"creation_id": 123,
"content": "生成的文章内容...",
"credits_used": 10
}
}GET /api/v1/writing/tools响应:
{
"code": 200,
"message": "success",
"data": [
{
"type": "wechat_article",
"name": "公众号文章",
"description": "生成适合微信公众号的文章",
"credits_cost": 10
}
]
}POST /api/v1/image/generate请求体:
{
"prompt": "一只可爱的猫咪在花园里玩耍",
"size": "1024x1024",
"model_id": 2
}响应:
{
"code": 200,
"message": "生成成功",
"data": {
"image_url": "https://cdn.example.com/images/xxx.png",
"credits_used": 20
}
}POST /api/v1/video/generate请求体:
{
"script": "视频脚本内容",
"duration": 30,
"model_id": 3
}响应:
{
"code": 200,
"message": "任务已创建",
"data": {
"task_id": "video_task_123",
"status": "processing"
}
}GET /api/v1/video/{task_id}/status响应:
{
"code": 200,
"message": "success",
"data": {
"task_id": "video_task_123",
"status": "completed",
"video_url": "https://cdn.example.com/videos/xxx.mp4",
"credits_used": 50
}
}POST /api/v1/ppt/generate请求体:
{
"topic": "产品发布会",
"outline": ["产品介绍", "核心功能", "市场分析"],
"model_id": 4
}响应:
{
"code": 200,
"message": "生成成功",
"data": {
"ppt_id": 456,
"download_url": "https://cdn.example.com/ppt/xxx.pptx",
"credits_used": 30
}
}GET /api/v1/creations?page=1&page_size=20&type=writing响应:
{
"code": 200,
"message": "success",
"data": {
"total": 100,
"page": 1,
"page_size": 20,
"items": [
{
"id": 123,
"type": "writing",
"tool_type": "wechat_article",
"title": "如何提高工作效率",
"content": "文章内容...",
"created_at": "2026-01-22T10:00:00"
}
]
}
}GET /api/v1/creations/{id}PUT /api/v1/creations/{id}请求体:
{
"title": "新标题",
"content": "更新后的内容"
}DELETE /api/v1/creations/{id}POST /api/v1/publish请求体:
{
"creation_id": 123,
"platforms": ["wechat", "xiaohongshu"],
"schedule_time": "2026-01-23T10:00:00"
}响应:
{
"code": 200,
"message": "发布任务已创建",
"data": {
"publish_id": 789,
"status": "pending"
}
}GET /api/v1/publish/platformsPOST /api/v1/publish/platforms/bind请求体:
{
"platform": "wechat",
"credentials": {
"app_id": "xxx",
"app_secret": "xxx"
}
}GET /api/v1/publish/history?page=1&page_size=20POST /api/v1/operation/activities请求体:
{
"name": "新用户注册送积分",
"type": "credit_gift",
"description": "新用户注册即送100积分",
"config": {
"credits": 100
},
"start_time": "2026-01-22T00:00:00",
"end_time": "2026-02-22T23:59:59"
}响应:
{
"code": 200,
"message": "活动创建成功",
"data": {
"id": 1,
"name": "新用户注册送积分",
"status": "active"
}
}GET /api/v1/operation/activities?status=active&page=1&page_size=20POST /api/v1/operation/activities/{activity_id}/participatePOST /api/v1/operation/coupons请求体:
{
"code": "DISCOUNT10",
"name": "充值优惠券",
"type": "discount",
"value": 10.0,
"min_amount": 100.0,
"max_usage": 1000,
"valid_from": "2026-01-22T00:00:00",
"valid_until": "2026-02-22T23:59:59"
}响应:
{
"code": 200,
"message": "优惠券创建成功",
"data": {
"id": 1,
"code": "DISCOUNT10",
"status": "active"
}
}GET /api/v1/operation/coupons?status=active&page=1&page_size=20POST /api/v1/operation/coupons/{coupon_id}/claimGET /api/v1/operation/my-coupons?status=unusedPOST /api/v1/operation/referral/generate响应:
{
"code": 200,
"message": "推荐码已生成",
"data": {
"referral_code": "ABC123",
"referral_url": "https://example.com/register?ref=ABC123"
}
}GET /api/v1/operation/referral/records?page=1&page_size=20响应:
{
"code": 200,
"message": "success",
"data": {
"total": 10,
"total_rewards": 500,
"items": [
{
"id": 1,
"referred_user": "user123",
"reward_amount": 50,
"status": "completed",
"created_at": "2026-01-22T10:00:00"
}
]
}
}GET /api/v1/operation/statistics?start_date=2026-01-01&end_date=2026-01-31响应:
{
"code": 200,
"message": "success",
"data": {
"total_users": 10000,
"new_users": 500,
"total_revenue": 50000.00,
"total_credits_sold": 500000,
"active_members": 1000,
"conversion_rate": 0.15
}
}GET /api/v1/models?provider=qwen&is_active=true响应:
{
"code": 200,
"message": "success",
"data": [
{
"id": 1,
"name": "通义千问Max",
"provider": "qwen",
"model_name": "qwen-max",
"is_active": true,
"credits_cost": 10
}
]
}POST /api/v1/models请求体:
{
"name": "通义千问Plus",
"provider": "qwen",
"model_name": "qwen-plus",
"api_key": "sk-xxx",
"api_base": "https://dashscope.aliyuncs.com/api/v1",
"config": {
"temperature": 0.7,
"max_tokens": 2000
},
"credits_cost": 8
}PUT /api/v1/models/{id}DELETE /api/v1/models/{id}wechat_article: 公众号文章xiaohongshu_note: 小红书笔记official_document: 公文写作academic_paper: 论文写作marketing_copy: 营销文案news_article: 新闻稿/软文video_script: 短视频脚本story_novel: 故事/小说business_plan: 商业计划书work_report: 工作报告resume: 简历/求职信lesson_plan: 教案/课件content_rewrite: 内容改写translation: 多语言翻译
credit_gift: 积分赠送membership_discount: 会员折扣referral_bonus: 推荐奖励first_purchase: 首次购买优惠
discount: 折扣券(百分比)deduction: 抵扣券(固定金额)credit_bonus: 积分加赠
monthly: 月度会员(9.9元/月)quarterly: 季度会员(25元/季)yearly: 年度会员(99元/年)
alipay: 支付宝wechat: 微信支付balance: 余额支付
wechat: 微信公众号xiaohongshu: 小红书douyin: 抖音kuaishou: 快手toutiao: 今日头条
| 错误码 | 说明 | 解决方案 |
|---|---|---|
| 40001 | 积分不足 | 请充值积分或购买会员 |
| 40002 | 会员已过期 | 请续费会员 |
| 40003 | 优惠券无效 | 检查优惠券状态和有效期 |
| 40004 | 订单不存在 | 检查订单ID是否正确 |
| 40005 | 支付失败 | 重试支付或联系客服 |
| 40006 | AI服务调用失败 | 稍后重试或更换模型 |
| 40007 | 内容生成失败 | 检查输入参数或重试 |
| 40008 | 平台账号未绑定 | 先绑定平台账号 |
| 40009 | 发布失败 | 检查平台规则或重试 |
| 40010 | 活动已结束 | 查看其他活动 |
| 接口类型 | 限制 |
|---|---|
| 认证接口 | 10次/分钟 |
| AI生成接口 | 会员:无限制 非会员:20次/小时 |
| 查询接口 | 100次/分钟 |
| 其他接口 | 60次/分钟 |
-
Token管理
- 访问令牌有效期2小时,刷新令牌有效期7天
- 在访问令牌过期前使用刷新令牌获取新的访问令牌
- 安全存储Token,不要在客户端明文存储
-
错误处理
- 始终检查响应的code字段
- 根据错误码进行相应的错误处理
- 对于5xx错误,实施重试机制(指数退避)
-
积分消费
- 生成前检查用户积分余额或会员状态
- 会员用户优先使用会员权益(不扣积分)
- 生成失败会自动退还积分
-
异步任务
- 视频生成等耗时任务采用异步处理
- 定期轮询任务状态或使用WebSocket接收通知
- 任务完成后及时获取结果
-
分页查询
- 使用page和page_size参数进行分页
- 默认page_size为20,最大100
- 响应中包含total字段表示总记录数
-
日期时间
- 所有时间使用ISO 8601格式
- 时区为UTC+8(北京时间)
- 示例:2026-01-22T10:00:00
import requests
# 基础配置
BASE_URL = "http://localhost:8000"
headers = {}
# 1. 用户登录
def login(username, password):
response = requests.post(
f"{BASE_URL}/api/v1/auth/login",
json={"username": username, "password": password}
)
data = response.json()
if data["code"] == 200:
token = data["data"]["access_token"]
headers["Authorization"] = f"Bearer {token}"
return token
return None
# 2. 生成文章
def generate_article(title, keywords):
response = requests.post(
f"{BASE_URL}/api/v1/writing/wechat_article/generate",
headers=headers,
json={
"title": title,
"keywords": keywords,
"requirements": "字数2000字",
"model_id": 1
}
)
return response.json()
# 3. 充值积分
def recharge(amount):
response = requests.post(
f"{BASE_URL}/api/v1/credit/recharge",
headers=headers,
json={
"amount": amount,
"payment_method": "alipay"
}
)
return response.json()
# 使用示例
token = login("testuser", "password123")
if token:
result = generate_article("如何提高工作效率", ["时间管理", "效率工具"])
print(result)const BASE_URL = 'http://localhost:8000';
let token = '';
// 1. 用户登录
async function login(username, password) {
const response = await fetch(`${BASE_URL}/api/v1/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
const data = await response.json();
if (data.code === 200) {
token = data.data.access_token;
return token;
}
return null;
}
// 2. 生成文章
async function generateArticle(title, keywords) {
const response = await fetch(
`${BASE_URL}/api/v1/writing/wechat_article/generate`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
title,
keywords,
requirements: '字数2000字',
model_id: 1
})
}
);
return await response.json();
}
// 3. 获取积分余额
async function getBalance() {
const response = await fetch(`${BASE_URL}/api/v1/credit/balance`, {
headers: { 'Authorization': `Bearer ${token}` }
});
return await response.json();
}
// 使用示例
(async () => {
await login('testuser', 'password123');
const result = await generateArticle('如何提高工作效率', ['时间管理', '效率工具']);
console.log(result);
})();- 初始版本发布
- 支持阿里通义千问模型
- 实现积分和会员系统
- 实现运营管理功能
- 14个AI写作工具
- 图片、视频、PPT生成功能
- 多平台发布功能
如有问题,请联系: