<think>
用户需要 curl 命令的例子来测试广告系统。根据我实现的 API,我需要提供:
1. 创建广告的例子 (POST /x-ads)
2. 获取广告列表的例子 (GET /x-ads)
3. 更新广告的例子 (PUT /x-ads/{id})
4. 删除广告的例子 (DELETE /x-ads/{id})
需要注意的是:
- 创建、更新、删除需要 root 权限,所以需要使用 root 的 sess_key
- 获取广告列表不需要认证,但认证后可以看到更多信息
- 需要包含正确的 headers
</think>
根据实现的广告系统,这里是 curl 命令示例:
## 1. 创建广告(需要 root 权限)
```bash
# 基本广告
curl -X POST http://your-api-domain/x-ads \
-H "Content-Type: application/json" \
-H "Cookie: sk=YOUR_ROOT_SESS_KEY" \
-d '{
"title": "新功能发布",
"content": "我们推出了全新的 AI 模型,欢迎体验!",
"priority": 8,
"active": true
}'
# 带图片和链接的广告
curl -X POST http://your-api-domain/x-ads \
-H "Content-Type: application/json" \
-H "Cookie: sk=YOUR_ROOT_SESS_KEY" \
-d '{
"title": "限时优惠活动",
"content": "本月订阅享受 8 折优惠,立即升级您的账户!",
"link": "https://example.com/upgrade",
"image_url": "https://example.com/banner.jpg",
"priority": 10,
"days": 7,
"active": true
}'
# 创建一个非活跃广告(草稿)
curl -X POST http://your-api-domain/x-ads \
-H "Content-Type: application/json" \
-H "Cookie: sk=YOUR_ROOT_SESS_KEY" \
-d '{
"title": "即将推出",
"content": "新功能正在开发中...",
"priority": 5,
"active": false
}'
# 获取所有活跃广告(默认)
curl -X GET http://your-api-domain/x-ads
# 获取包括非活跃的所有广告
curl -X GET "http://your-api-domain/x-ads?active=false"
# 限制返回数量
curl -X GET "http://your-api-domain/x-ads?limit=5"
# 带认证获取(可以看到更多信息如展示次数)
curl -X GET http://your-api-domain/x-ads \
-H "Cookie: sk=YOUR_ROOT_SESS_KEY"
# 更新广告内容
curl -X PUT http://your-api-domain/x-ads/ad_1234567890_abc \
-H "Content-Type: application/json" \
-H "Cookie: sk=YOUR_ROOT_SESS_KEY" \
-d '{
"title": "更新后的标题",
"content": "更新后的内容",
"priority": 9
}'
# 激活一个广告
curl -X PUT http://your-api-domain/x-ads/ad_1234567890_abc \
-H "Content-Type: application/json" \
-H "Cookie: sk=YOUR_ROOT_SESS_KEY" \
-d '{
"active": true
}'
# 更新广告链接
curl -X PUT http://your-api-domain/x-ads/ad_1234567890_abc \
-H "Content-Type: application/json" \
-H "Cookie: sk=YOUR_ROOT_SESS_KEY" \
-d '{
"link": "https://new-link.com",
"image_url": "https://new-image.com/banner.jpg"
}'
curl -X DELETE http://your-api-domain/x-ads/ad_1234567890_abc \
-H "Cookie: sk=YOUR_ROOT_SESS_KEY"
{
"success": true,
"ad": {
"id": "ad_1234567890_abc",
"title": "新功能发布",
"content": "我们推出了全新的 AI 模型,欢迎体验!",
"link": "",
"image_url": "",
"priority": 8,
"created_at": "2024-01-20T10:30:00Z",
"expires_at": "2024-02-19T10:30:00Z",
"created_by": "root (ID: 1)",
"active": true,
"impressions": 0
},
"message": "Ad created successfully, expires in 30 days"
}
{
"success": true,
"count": 2,
"ads": [
{
"id": "ad_1234567890_abc",
"title": "限时优惠活动",
"content": "本月订阅享受 8 折优惠,立即升级您的账户!",
"link": "https://example.com/upgrade",
"image_url": "https://example.com/banner.jpg",
"priority": 10,
"created_at": "2024-01-20T10:30:00Z",
"expires_at": "2024-01-27T10:30:00Z",
"created_by": "",
"active": true,
"impressions": 0
},
{
"id": "ad_0987654321_xyz",
"title": "新功能发布",
"content": "我们推出了全新的 AI 模型,欢迎体验!",
"priority": 8,
"created_at": "2024-01-19T10:30:00Z",
"expires_at": "2024-02-18T10:30:00Z",
"created_by": "",
"active": true,
"impressions": 0
}
]
}
# 1. 首先获取 root 的 session key(假设你已经有了)
ROOT_SK="your_root_session_key"
# 2. 创建一个高优先级广告
AD_RESPONSE=$(curl -s -X POST http://your-api-domain/x-ads \
-H "Content-Type: application/json" \
-H "Cookie: sk=$ROOT_SK" \
-d '{
"title": "重要通知",
"content": "系统将于今晚进行维护",
"priority": 10,
"days": 1,
"active": true
}')
# 3. 提取广告 ID
AD_ID=$(echo $AD_RESPONSE | jq -r '.ad.id')
echo "Created ad with ID: $AD_ID"
# 4. 查看当前所有广告
curl -s http://your-api-domain/x-ads | jq
# 5. 更新广告内容
curl -s -X PUT http://your-api-domain/x-ads/$AD_ID \
-H "Content-Type: application/json" \
-H "Cookie: sk=$ROOT_SK" \
-d '{
"content": "系统将于今晚 22:00-23:00 进行维护"
}' | jq
# 6. 删除广告
curl -s -X DELETE http://your-api-domain/x-ads/$AD_ID \
-H "Cookie: sk=$ROOT_SK" | jq
注意事项:
- 替换 your-api-domain
为实际的 API 域名
- 替换 YOUR_ROOT_SESS_KEY
为实际的 root session key
- 广告默认有效期为 30 天,可以通过 days
参数设置(1-365 天)
- priority
范围是 0-10,数字越大优先级越高
- 普通用户只能看到活跃的广告,root 用户可以看到所有广告和详细信息
“`