💡 缓存状态:
缓存文件 59 个 |
总大小 322.4 KB |
有效期 24小时
(命中缓存可大幅提升响应速度)
📌 接口地址:https://www.98qy.com/history/api.php
📌 请求方式:GET
📌 返回格式: JSON Text JS
📌 数据源:网络收集(每天自动抓取更新,档案库永久保存)
📌 缓存策略:档案库永久 + 参数缓存24小时
📋 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
date |
string | 否 | 查询指定日期(格式:YYYY-MM-DD) | 1949-10-01 |
year |
int | 否 | 按年份筛选事件 | 1949 |
month |
int | 否 | 按月份筛选(配合day使用) | 9 |
day |
int | 否 | 按日期筛选(配合month使用) | 1 |
type |
string | 否 | 按事件类型筛选(政治/科技/文化/经济/军事/自然/人物) | 科技 |
keyword |
string | 否 | 关键词搜索(标题+描述) | 成立 |
start |
string | 否 | 开始日期(范围查询) | 1949-10-01 |
end |
string | 否 | 结束日期(范围查询) | 1949-10-31 |
num |
int | 否 | 返回条数(默认全部,最大1000) | 10 |
format |
string | 否 | 输出格式:json / text / js | json |
fields |
string | 否 | 返回字段(逗号分隔:id,date,year,title,desc,type) | title,year,type |
random |
int | 否 | 随机获取一条(random=1,跳过缓存) | 1 |
force |
int | 否 | 强制刷新(忽略缓存) | 1 |
📤 返回参数(JSON格式)
| 字段 | 类型 | 说明 |
|---|---|---|
code |
int | 状态码(200=成功) |
success |
boolean | 是否成功 |
msg |
string | 提示信息 |
data |
array | 事件列表(包含id、date、year、title、desc、type) |
total |
int | 返回数量 |
query |
object | 查询参数 |
from_cache |
boolean | 是否来自缓存(缓存命中时返回) |
cache_age_hours |
float | 缓存已保存小时数(缓存命中时返回) |
📄 返回示例(JSON)
{
"code": 200,
"success": true,
"msg": "success",
"data": [
{
"id": 1,
"date": "1949-10-01",
"year": 1949,
"title": "返回的标题",
"desc": "返回的内容",
"type": "娱乐"
}
],
"total": 12,
"query": {
"format": "json"
},
"from_cache": true,
"cache_age_hours": 2.5
}
📌 JS 格式使用示例(跨域友好)
方式一:script 标签直接引用(返回全局变量 returnHistorySN)
<!-- 加载JS格式API -->
<script src="https://www.98qy.com/history/api.php?date=1949-10-01&format=js"></script>
<script>
// 脚本加载后,全局变量 returnHistorySN 自动可用
console.log(returnHistorySN.data);
document.write('历史上的今天:' + returnHistorySN.data[0].title);
</script>
方式二:动态加载(推荐,可控性强)
<script>
function loadHistoryAPI(params, callback) {
var script = document.createElement('script');
script.src = 'https://www.98qy.com/history/api.php?' + params + '&format=js';
script.onload = function() {
if (typeof returnHistorySN !== 'undefined') {
callback(returnHistorySN);
}
};
script.onerror = function() {
console.error('API加载失败');
};
document.head.appendChild(script);
}
// 使用示例:查询9月1日的历史事件
loadHistoryAPI('month=9&day=1', function(data) {
console.log('历史上的今天:', data.data);
});
</script>
方式三:jQuery 方式(需要 jQuery 支持)
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$.ajax({
url: 'https://www.98qy.com/history/api.php',
data: { year: 1949, format: 'json' },
dataType: 'json',
success: function(res) {
console.log(res.data);
},
error: function() {
console.error('请求失败');
}
});
</script>
📌 请求示例
📅 查询今天的"历史上的今天"(默认)
https://www.98qy.com/history/api.php
📅 查询指定日期的事件
https://www.98qy.com/history/api.php?date=1949-10-01&format=json
📅 按年份查询
https://www.98qy.com/history/api.php?year=1949&format=json
📅 历史上的今天(9月1日)
https://www.98qy.com/history/api.php?month=9&day=1&format=json
📅 按类型查询(科技类)
https://www.98qy.com/history/api.php?type=科技&num=5&format=json
📅 关键词搜索
https://www.98qy.com/history/api.php?keyword=成立&format=json
📅 日期范围查询(1949年10月的事件)
https://www.98qy.com/history/api.php?start=1949-10-01&end=1949-10-31&format=json
🎲 随机获取一条(跳过缓存)
https://www.98qy.com/history/api.php?random=1&format=json
🧪 在线测试
💡 默认查询"历史上的今天"(今天月日),首次查询会自动从网络抓取并永久保存到档案库
💡 后续相同请求直接读缓存(24小时有效)
💡 空参数不参与查询,避免干扰结果
💡 后续相同请求直接读缓存(24小时有效)
💡 空参数不参与查询,避免干扰结果