随机社会常识题 [31000 题库] 免费 API 接口教程

📅 2026/7/7 12:06:24 👁️ 阅读次数 📝 编程学习
随机社会常识题 [31000 题库] 免费 API 接口教程

一、接口简介

这是接口盒子的一个随机返回一条社会常识问答题的免费开放接口,题库规模约31000 条,涵盖历史、文学、中医、政治、生活常识等多种方向,例如:

  • "二十一条款由谁提出?" → 袁世凯
  • "对酒当歌,人生几何,这是谁的诗句?" → 曹操
  • "中医著名古籍《黄帝内经》约成书于?" → 春秋战国时期

典型使用场景:

  • 微信/Telegram 答题机器人
  • 小程序「每日一题」
  • 题库系统 / 知识问答类应用随机出题
  • 爬虫练习、教学 Demo

二、请求说明

📍 请求地址(三种线路任选)

线路类型

地址

说明

普通集群·域名(推荐)

https://接口盒子/api/zici/changshi.php

域名 TTL=60s,自动轮换负载

🔧 请求方式

GETPOST均可。

📥 请求参数

参数

必填

说明

id

用户中心的数字 ID,如10000000

key

用户中心通讯秘钥,如15he5h15ty854j5sr152hs2


三、返回参数

返回为 JSON:

字段

类型

说明

code

int

200成功,400错误

msg

string

信息提示(错误时才有意义)

p

string

题目

a

string

答案


四、返回示例

✅ 成功(200)

{ "code": 200, "p": "二十一条款由谁提出?", "a": "袁士凯" }
{ "code": 200, "p": "对酒当歌,人生几何,这是谁的诗句?", "a": "曹操" }
{ "code": 200, "p": "中医著名古籍《黄帝内经》约成书于?", "a": "春秋战国时期" }

❌ 失败(400)

{ "code": 400, "msg": "通讯秘钥错误。" }

五、调用示例

🐘 PHP 示例

GET 方式
<?php $id = "10000000"; // 替换成你的 ID $key = "15he5h15ty854j5sr152hs2"; // 替换成你的 KEY $url = "https://接口盒子/api/zici/changshi.php?id={$id}&key={$key}"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); if ($data['code'] == 200) { echo "题目:{$data['p']}\n"; echo "答案:{$data['a']}\n"; } else { echo "错误:{$data['msg']}\n"; }
POST 方式
<?php $id = "10000000"; $key = "15he5h15ty854j5sr152hs2"; $url = "https://接口盒子/api/zici/changshi.php"; $postData = http_build_query([ 'id' => $id, 'key' => $key, ]); $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData, CURLOPT_TIMEOUT => 10, ]); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); if ($data['code'] == 200) { echo "题目:{$data['p']}\n"; echo "答案:{$data['a']}\n"; } else { echo "错误:{$data['msg']}\n"; }

🐍 Python 示例

依赖:requests

pip install requests
GET 方式
import requests API_URL = "https://接口盒子/api/zici/changshi.php" USER_ID = "10000000" # 替换成你的 ID USER_KEY = "15he5h15ty854j5sr152hs2" # 替换成你的 KEY params = { "id": USER_ID, "key": USER_KEY, } try: resp = requests.get(API_URL, params=params, timeout=10) data = resp.json() if data["code"] == 200: print("题目:", data["p"]) print("答案:", data["a"]) else: print("错误:", data["msg"]) except Exception as e: print("请求异常:", e)
POST 方式
import requests API_URL = "https://接口盒子/api/zici/changshi.php" USER_ID = "10000000" USER_KEY = "15he5h15ty854j5sr152hs2" data = { "id": USER_ID, "key": USER_KEY, } try: resp = requests.post(API_URL, data=data, timeout=10) result = resp.json() if result["code"] == 200: print("题目:", result["p"]) print("答案:", result["a"]) else: print("错误:", result["msg"]) except Exception as e: print("请求异常:", e)