技术博客
节假日查询:节日简介与农历日期怎么拿?needDesc 与 h 字段实战

节假日查询:节日简介与农历日期怎么拿?needDesc 与 h 字段实战

作者: 万维易源
2026-08-27
节假日查询节日简介农历needDesc
# 节假日查询:节日简介与农历日期怎么拿?needDesc 与 h 字段实战 > 接口 894(接入点 894-6 节假日查询) · 免费 · POST/GET · 返回 JSON · 适用人群:开发者 · 阅读时间:约 6 分钟 ## TL;DR - 894-6 默认**不返回**节日简介;要简介必须传 `needDesc=1`(公众日/国际日/传统节日)或 `2`(仅法定节假日)。 - 简介在 `h` 数组里:含 `genus`(public/traditional)、`info`、`name`、`lunaDay`(农历)、`origin`。 - `h` 只在 `needDesc` 触发时出现,写代码时要把它当"可选字段"处理。 ## Why:做文化/科普类展示用得上 日历 App 想在点开某天时显示"今天是端午节,农历五月初五,纪念屈原";或国际日想展示"世界环境日"简介——这些都要节日详情。894-6 的 `needDesc` + `h` 就是为此设计。 ## What:接口速览 | 项 | 说明 | |----|------| | 接入点 | **894-6 节假日查询** | | 接口地址 | `https://route.showapi.com/894-6?appKey=YOUR_APPKEY` | | 请求方式 | POST / GET | | 计费 | 免费服务 | **关键参数**:`day`(可选)、`needDesc`(可选):`1`=返回公众日/国际日/传统节日简介,`2`=仅法定节假日简介,默认不返回。 ## How:拿到节日简介 **Python(requests)** ```python import requests url = "https://route.showapi.com/894-6" r = requests.post(url, params={"appKey": "YOUR_APPKEY", "day": "2026-06-19", "needDesc": 1}, timeout=10) b = r.json()["showapi_res_body"] if str(b["ret_code"]) != "0": print("失败:", b.get("showapi_res_error")) else: for f in b.get("h", []): # h 可能不存在,用 .get 兜底 print(f["name"], "| 农历:", f.get("lunaDay"), "| 类型:", f["genus"]) print("简介:", f.get("info")) print("起源:", f.get("origin")) ``` **Node.js(fetch)** ```javascript const res = await fetch("https://route.showapi.com/894-6?appKey=YOUR_APPKEY&day=2026-06-19&needDesc=1", { method: "POST", timeout: 10000 }); const b = (await res.json()).showapi_res_body; if (String(b.ret_code) !== "0") console.error(b.showapi_res_error); else for (const f of (b.h || [])) console.log(f.name, f.genus, f.lunaDay); ``` **cURL** ```bash curl -X POST "https://route.showapi.com/894-6?appKey=YOUR_APPKEY" \ -H "content-type: application/x-www-form-urlencoded" \ -d "day=2026-06-19&needDesc=1" ``` ## 返回示例与解析 ```json { "showapi_res_body": { "ret_code": 0, "day": "2026-06-19", "type": "3", "holiday": "端午节", "h": [ { "day": "2026-06-19", "genus": "traditional", "name": "端午节", "lunaDay": "五月初五", "info": "…", "origin": "…" } ] } } ``` | h[] 字段 | 说明 | |----------|------| | day | 节日公历日期 | | genus | `public`=公众日/国际日,`traditional`=传统节日 | | name | 节日名称 | | lunaDay | 农历日期 | | info | 节日简介 | | origin | 节日起源 | ## 进阶 / 边界 - **h 是可选字段**:不传 `needDesc` 或当日无节日时 `h` 不返回,代码用 `b.get("h", [])` 兜底。 - **needDesc=1 vs 2**:`1` 含国际日(genus=public)与传统节日(genus=traditional);`2` 只含法定节假日。 - **农历只在中国传统节日有**:genus=public 的国际日 `lunaDay` 通常为空。 ## FAQ **Q1:为什么不传 needDesc 也能看到节日名?** A:`holiday` 字段(如"端午节")默认就返回;但 `h` 里的简介、农历、起源需要 `needDesc` 才返回。 **Q2:needDesc=1 和 2 怎么选?** A:想展示国际日/传统节日科普用 `1`;只关心法定节假日简介用 `2`。 **Q3:h 返回空数组说明什么?** A:当日没有节日,或没传 `needDesc`。 **Q4:农历日期一定有吗?** A:仅 genus=traditional 的传统节日有 `lunaDay`,国际日一般为空。 **Q5:ret_code 类型?** A:894-6 是数字 `0`,统一 `str(...)` 判断最稳。 ## 相关能力 / 下一步阅读 - [节假日查询:某天到底放不放假?894-6 单日判定接入指南](https://www.showapi.com/guides/holiday-query-day-check-894) - [节假日查询返回字段全解:ret_code 与 type(1/2/3) 及三接入点结构一文读懂](https://www.showapi.com/guides/holiday-query-response-codes-894) - [节假日查询:5 分钟接入,从注册到拿到全年放假安排](https://www.showapi.com/guides/holiday-query-quickstart-894) - **本系列共 12 篇**:查看[节假日查询指南总目录](https://www.showapi.com/guides/holiday-query-guides-894)