API 文档
完整的API接口文档和使用说明
获取广告列表
GET获取所有可用的广告内容,包括文字广告和图片广告。
接口地址
/api/content.php
响应示例
{
"ads": [
{
"id": 1,
"type": "text",
"title": "示例文字广告",
"content": "这是一条文字广告内容",
"text_color": "#000000",
"font_size": "16px",
"font_weight": "normal",
"link_url": "https://example.com",
"expiration_date": "2024-12-31"
},
{
"id": 2,
"type": "image",
"title": "示例图片广告",
"image_path": "/uploads/ad-image.jpg",
"image_url": "https://example.com/image.jpg",
"link_url": "https://example.com",
"expiration_date": "2024-12-31"
}
]
}
使用示例
// 使用 fetch 获取广告列表
fetch('api/content.php')
.then(response => response.json())
.then(data => {
// 处理广告数据
data.forEach(ad => {
if (ad.type === 'text') {
// 处理文字广告
console.log('文字广告:', ad.content);
} else if (ad.type === 'image') {
// 处理图片广告
console.log('图片广告:', ad.image_path);
}
});
})
.catch(error => console.error('获取广告失败:', error));
注意事项
- 接口不需要认证,可直接调用
- 返回的广告内容已按创建时间降序排序
- 过期的广告不会返回
- 建议实现缓存机制,避免频繁请求
- 关于域名记录:
- 系统会记录实际调用API的来源域名,而不是API所在的域名
- 如果域名显示为"unknown",可能是以下原因:
- 直接访问API地址而不是通过网页调用
- 浏览器未发送Referer或Origin头信息
- 使用了阻止发送Referer信息的浏览器插件
- 通过特殊工具(如curl、postman等)访问API
解决方案:- 在调用API时添加Origin头信息:
fetch('/api/content.php', { headers: { 'Origin': window.location.origin } })
- 或确保不阻止发送Referer信息:
<meta name="referrer" content="origin">
调用限制
为了确保系统的稳定性和安全性,我们对API的调用做出以下限制:
- 每个IP每分钟最多调用60次
- 每个域名每天最多调用10000次
- 单次请求超时时间为5秒
- 返回数据大小限制为1MB
错误码说明
错误码 | 说明 | 解决方案 |
---|---|---|
1001 | 请求超过频率限制 | 降低请求频率或等待一分钟后重试 |
1002 | 域名未授权 | 检查域名是否正确或联系管理员授权 |
1003 | 系统维护中 | 请稍后重试 |
获取更新历史
GET获取所有更新记录,包括版本号、描述和文件路径。
接口地址
/api/update.php
响应示例
[
{
"id": 1,
"version": "1.0.0",
"description": "首次发布",
"file_path": "uploads/update_1.0.0.zip",
"created_at": "2024-01-01 12:00:00"
},
{
"id": 2,
"version": "1.1.0",
"description": "修复了一些bug",
"file_path": "uploads/update_1.1.0.zip",
"created_at": "2024-02-01 12:00:00"
}
]
注意事项
- 返回的更新记录按创建时间降序排列
- 确保API调用频率在限制范围内
- 此接口仅用于查询更新历史,不支持上传或修改操作