技术博客
绕口令与谜语查询:谜语关键词检索实战(搜谜面、取谜底)

绕口令与谜语查询:谜语关键词检索实战(搜谜面、取谜底)

作者: 万维易源
2026-09-03
谜语查询关键词检索question参数谜面谜底
# 绕口令与谜语查询:谜语关键词检索实战(搜谜面、取谜底) **接口**:绕口令与谜语查询(apiCode=1623)· 接入点 1623-2 谜语|**是否免费**:免费(含使用档次限制)|**请求方式**:POST/GET|**返回格式**:JSON|**适用人群**:全栈、教育产品、小程序开发者|**阅读时间**:约 5 分钟 ## 核心要点 - 谜语接入点用 `question` 参数做谜面关键词检索(可选,留空返回默认列表)。 - 每条结果含 `question`(谜面)+ `answer`(谜底),适合做「猜谜」互动。 - 客户端超时建议 15s(对齐官方 `x-read-timeout`,比绕口令更长)。 ## Why:把谜语库变成可玩的互动素材 谜语能锻炼记忆力与反应力,是亲子、班级、社群互动的好素材。用 `question` 关键词(如地名、动物、节气)就能按主题取谜,省去自己收集谜面谜底。 ## What:接口速览 | 项目 | 说明 | |------|------| | 接口地址 | `https://route.showapi.com/1623-2?appKey={your_appKey}` | | 检索参数 | `question`(String,否,谜面关键词,如「云南」「动物」) | | 分页参数 | `page`(String,否,默认 1) | | 返回内容 | `contentlist[]` 每项含 `question`(谜面)+ `answer`(谜底) | | 超时 | 15s | ## How:带关键词调用 **Python(requests)** ```python import requests APP_KEY = "YOUR_APPKEY" URL = "https://route.showapi.com/1623-2" def query_riddles(keyword: str, page: int = 1): resp = requests.post( URL, params={"appKey": APP_KEY}, data={"question": keyword, "page": str(page)}, timeout=15, # 谜语接入点超时为 15s ) data = resp.json() body = data["showapi_res_body"] if body["ret_code"] != "0": raise RuntimeError(data.get("showapi_res_error")) return body body = query_riddles("云南", page=1) print("总数:", body["allNum"], "总页:", body["allPages"]) for item in body["contentlist"]: print(f"谜面:{item['question']}\n谜底:{item['answer']}\n") ``` **cURL** ```bash curl -X POST "https://route.showapi.com/1623-2?appKey=YOUR_APPKEY" \ -H "content-type: application/x-www-form-urlencoded" \ -d "question=%E4%BA%91%E5%8D%97&page=1" ``` **Node.js(fetch)** ```javascript const APP_KEY = "YOUR_APPKEY"; async function queryRiddles(keyword, page = 1) { const url = `https://route.showapi.com/1623-2?appKey=${APP_KEY}`; const body = new URLSearchParams({ question: keyword, page: String(page) }); const resp = await fetch(url, { method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body, signal: AbortSignal.timeout(15000), // 谜语 15s }); const data = await resp.json(); const resBody = data.showapi_res_body; if (resBody.ret_code !== "0") throw new Error(data.showapi_res_error); return resBody; } const body = await queryRiddles("云南", 1); console.log("总数:", body.allNum, "总页:", body.allPages); for (const it of body.contentlist) console.log(`谜面:${it.question}\n谜底:${it.answer}\n`); ``` ## 返回示例与解析 ```json { "showapi_res_body": { "ret_code": "0", "contentlist": [ { "question": "“二儿故琢钉戏,了无遽容” (云南地名连民族2+2)", "answer": "昆明白族" } ], "maxResult": "1000", "allNum": "10", "allPages": "100", "currentPage": "1" } } ``` 字段含义见[返回字段与 ret_code 全解](https://www.showapi.com/guides/tongue-riddle-response-fields-1623)。 ## 进阶 / 边界 - 多页遍历:用 `page` 循环到 `allPages`,见[分页遍历指南](https://www.showapi.com/guides/tongue-riddle-pagination-1623)。 - 做「猜谜」互动时,先把 `answer` 藏起来,用户作答后再揭晓;结合[前端限流](https://www.showapi.com/guides/tongue-riddle-frontend-throttle-1623) 防刷。 - 免费档位限制:循环调用前加缓存,见[本地缓存策略](https://www.showapi.com/guides/tongue-riddle-cache-tier-1623)。 ## FAQ **Q1:question 必填吗?** A:否,可选。不传或留空返回默认谜语列表。 **Q2:为什么谜语超时比绕口令长?** A:官方 OpenAPI 中谜语接入点 `x-read-timeout` 为 15s、绕口令为 5s,客户端对齐即可。 **Q3:返回里没有"谜目"字段?** A:文档与示例的谜语结果仅含 `question`(谜面)与 `answer`(谜底),无独立「谜目」字段,按实际返回处理。 **Q4:一次能返回多少条?** A:单页约 10 条,`maxResult` 上限 1000;更多用 `page` 翻页。 **Q5:空结果怎么判断?** A:`contentlist` 为空数组但 `ret_code` 可能为 `"0"`,用「数组长度 + ret_code」双重判断。 ## 下一步阅读 - [绕口令与谜语查询:绕口令关键词检索实战](https://www.showapi.com/guides/tongue-riddle-twister-query-1623) - [绕口令与谜语查询:分页遍历指南](https://www.showapi.com/guides/tongue-riddle-pagination-1623) - [绕口令与谜语查询:返回字段与 ret_code 全解](https://www.showapi.com/guides/tongue-riddle-response-fields-1623) - **本系列共 12 篇**:查看[绕口令与谜语查询指南总目录](https://www.showapi.com/guides/tongue-riddle-guides-1623)