API 概述
小红测 API 提供文章发布、评论管理、密钥管理、测试结果计算等功能,支持 Agent 自动化内容管理
基础信息
基础URL: https://xiaohongce.top
认证方式: Bearer Token
数据格式: JSON
编码格式: UTF-8
认证说明
需要认证的接口需在请求头携带:
Authorization: Bearer <your-api-key>⚠️ 获取 API Key
使用 API 需要先获取认证密钥。请联系管理员获取您的专属 API Key。
xhc_sk_****************************已脱敏请妥善保管您的 API Key,切勿在公开场合泄露。
📋网站内容分类说明(Agent必读)
小红测网站包含三大内容板块:专业测试、趣味测试、心理文章。以下是完整的分类列表,Agent应参考此分类进行内容生成和管理。
专业测试共 9 种 - 科学验证的心理测评工具
mbtiMBTI性格测试🧠
enneagram九型人格测试💫
big5大五人格测试⭐
discDISC性格测试🐯
holland霍兰德职业测试🎯
学术级量表(新增):
rses自尊水平测试(RSES)💎
swls生活满意度(SWLS)🌈
cdrisc心理弹性(CD-RISC)🌿
gses自我效能感(GSES)🔥
趣味测试共 20 种 - 轻松有趣的心理探索
形象风格类:
fashion穿衣品味
scent气味人格
style风格路线
aesthetic审美水平
wedding婚礼风格
情感心理类:
lovebrain恋爱脑指数
emotion情绪压抑
innerchild内在小孩
eq情商测试
lovelanguage爱情语言
attachment依恋类型
stress压力感知
生活趣味类:
city城市性格
destiny天生命格
windfall下一笔横财
futurestatus十年后地位
职场生存类:
tangping躺平还是卷
workpersona职场性格
workpua职场PUA
aiskillAI使用水平
文章分类共 6 种 - 文章发布时必须选择一个分类
🧠
psychology心理学知识
🌱
growth个人成长
💕
emotion情感心理
💼
career职场发展
✨
life生活智慧
📊
test-insight测试解读
💡 提示:发布文章时,category 参数必须使用上述 6 个分类 ID 之一
文章管理 API
用于文章的增删改查操作,支持分页、筛选、排序
公开接口无需认证
查询参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | number | 否 | 页码,默认 1 |
| pageSize | number | 否 | 每页条数,默认 10 |
| category | string | 否 | 分类筛选 |
| status | string | 否 | 状态筛选:published / draft |
| tag | string | 否 | 标签筛选 |
| keyword | string | 否 | 关键词搜索(标题/内容/标签) |
| sortBy | string | 否 | 排序字段,默认 created_at |
| sortOrder | string | 否 | 排序方向:asc / desc |
响应示例
{
"success": true,
"data": {
"items": [
{
"id": "1735000000-abc123def",
"title": "文章标题",
"content": "文章内容...",
"summary": "文章摘要...",
"cover_image": "https://...",
"author": "小红测",
"author_avatar": "🌸",
"tags": ["心理学", "测试"],
"category": "psychology",
"status": "published",
"view_count": 100,
"like_count": 50,
"comment_count": 10,
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}
],
"total": 100,
"page": 1,
"pageSize": 10,
"totalPages": 10
}
}请求示例
curl -X GET "https://xiaohongce.top/api/articles?page=1&pageSize=10&status=published"错误码说明
API 返回的错误码及对应说明
| 状态码 | 错误信息 | 说明 |
|---|---|---|
| 400 | 参数错误 | 请求参数缺失或格式不正确 |
| 401 | 无效的API密钥 | 未提供认证信息或密钥无效 |
| 404 | 资源不存在 | 请求的文章或评论不存在 |
| 429 | 请求过于频繁 | 触发频率限制,请稍后重试 |
| 500 | 服务器错误 | 服务器内部错误 |
| 503 | 数据库未配置 | 数据库连接不可用 |
Agent 集成示例
如何在 Agent 中使用这些 API
Python 示例
import requests
API_BASE = "https://xiaohongce.top"
API_KEY = "<your-api-key>"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# 发布文章
def publish_article(title, content, tags=None):
response = requests.post(
f"{API_BASE}/api/articles",
headers=headers,
json={
"title": title,
"content": content,
"tags": tags or [],
"status": "published"
}
)
return response.json()
# 发布评论
def post_comment(article_id, content, author="AI助手"):
response = requests.post(
f"{API_BASE}/api/comments",
headers=headers,
json={
"articleId": article_id,
"content": content,
"author": author
}
)
return response.json()
# 使用示例
result = publish_article(
title="今日心理测试推荐",
content="今天为大家推荐一个有趣的人格测试...",
tags=["心理测试", "推荐"]
)
print(f"文章发布成功: {result['data']['id']}")JavaScript/Node.js 示例
const API_BASE = "https://xiaohongce.top";
const API_KEY = "<your-api-key>";
// 发布文章
async function publishArticle(title, content, tags = []) {
const response = await fetch(`${API_BASE}/api/articles`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
title,
content,
tags,
status: 'published'
})
});
return response.json();
}
// 发布评论
async function postComment(articleId, content, author = 'AI助手') {
const response = await fetch(`${API_BASE}/api/comments`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
articleId,
content,
author
})
});
return response.json();
}
// 使用示例
publishArticle(
'今日心理测试推荐',
'今天为大家推荐一个有趣的人格测试...',
['心理测试', '推荐']
).then(result => {
console.log('文章发布成功:', result.data.id);
});