葫芦生 - API接口文档 v3.0《赵籁》版

《赵籁》专属API设计理念

基于赵国兴衰史的沉浸式历史文化体验API设计。从篇章管理到NPC深度交互,从历史教育到个性化推荐,为用户提供完整的历史学习之旅。

1. 设计概述

1.1 《赵籁》专属API设计理念

历史脉络驱动
以7个篇章为核心,支撑赵国兴衰史体验
沉浸式交互
从篇章报幕到NPC深度交互的完整流程
教育价值突出
每个接口都承载历史教育和文化传承功能
个性化体验
基于用户属性和历史的智能推荐

1.2 核心改进点

v3.0版本核心改进

  • 新增篇章管理模块:支持7个历史篇章的完整管理
  • 优化NPC交互流程:增加历史背景和教育价值
  • 强化体验记录:详细记录用户的历史学习过程
  • 增加智能推荐:基于历史兴趣的个性化内容推荐

2. 篇章管理接口

GET /api/v1/chapters
获取赵国兴衰史的7个篇章列表

请求头

Authorization: Bearer {token}

响应示例

{ "code": 0, "message": "success", "data": { "chapters": [{ "id": 1, "name": "赵氏初啼·铁血奠基", "subtitle": "马足光阴赋", "storyPhase": "起源", "theme": "赵氏起源,传承奠基", "storyContext": "造父驭马,叔带择主,赵氏在西周末年开始崭露头角", "historicalPeriod": { "startYear": -1000, "endYear": -800, "dynasty": "西周" }, "npcCount": 2, "displayOrder": 1, "isUnlocked": true, "userProgress": { "status": "未开始", "completionPercentage": 0, "npcsInteracted": 0, "lastInteractionAt": null } }] } }
GET /api/v1/chapters/{chapterId}
获取指定篇章的详细信息

路径参数

chapterId: number - 篇章ID

响应示例

{ "code": 0, "message": "success", "data": { "id": 1, "name": "赵氏初啼·铁血奠基", "subtitle": "马足光阴赋", "storyPhase": "起源", "theme": "赵氏起源,传承奠基", "storyContext": "造父驭马,叔带择主,赵氏在西周末年开始崭露头角", "prologueText": "造父执辔,为王驾车平乱,因功封于赵城,赵氏由此而始...", "prologueVideoUrl": "https://example.com/prologue1.mp4", "epilogueText": "马蹄踏碎光阴,赵城初启时,不过一握黄沙,却是赵国七百年兴衰的起点...", "historicalBackground": { "period": "西周末年", "startYear": -1000, "endYear": -800, "majorEvents": ["造父为王驾车", "叔带择主晋国"], "politicalSituation": "西周衰微,诸侯争霸", "zhaoStatus": "赵氏始祖获封赵城" }, "npcs": [{ "id": 1, "name": "造父", "roleDescription": "赵氏始祖,善御者", "historicalContribution": "为周穆王驾车,平定徐偃王之乱", "impactOnZhao": "因功获封赵城,开创赵氏基业", "avatarUrl": "https://example.com/zaofu.jpg", "isInteracted": false, "lastInteractionAt": null }] } }
POST /api/v1/chapters/{chapterId}/prologue
播放篇章报幕,记录用户观看状态

请求参数

{ "interactionPointId": 1, "watchDuration": 120 }

响应示例

{ "code": 0, "message": "success", "data": { "prologueText": "造父执辔,为王驾车平乱,因功封于赵城,赵氏由此而始...", "prologueVideoUrl": "https://example.com/prologue1.mp4", "nextAction": "开始与历史人物交互", "availableNpcs": [{ "id": 1, "name": "造父", "triggerWeight": 100 }] } }

3. 历史体验接口

POST /api/v1/chapters/{chapterId}/select-npc
基于用户历史和算法智能选择NPC

请求参数

{ "userPreferences": { "preferredPersonalityTypes": ["智者", "忠臣"], "historicalInterests": ["政治", "军事"], "lastInteractionTime": "2024-03-20T10:30:00Z" }, "contextFactors": { "currentLocation": { "lat": 36.123456, "lng": 114.123456 }, "timeOfDay": "morning", "weatherCondition": "sunny" } }

响应示例

{ "code": 0, "message": "success", "data": { "selectedNpc": { "id": 1, "name": "造父", "selectionReason": "基于您对忠诚品质的偏好,推荐与赵氏始祖造父交流", "historicalContext": "造父是赵氏的开创者,以忠诚和技艺著称", "expectedLearning": ["忠诚品质", "技艺精神", "开创精神"] }, "interactionPreparation": { "backgroundMaterial": "造父生活在西周时期...", "suggestedQuestions": ["您是如何获得周王信任的?"], "culturalContext": "西周时期的政治制度和社会结构" } } }
GET /api/v1/npcs/{npcId}/historical-background
获取NPC的详细历史背景信息

响应示例

{ "code": 0, "message": "success", "data": { "npc": { "id": 1, "name": "造父", "courtesyName": null, "title": "御者", "serveLord": "周穆王", "lifeSpan": { "birthYear": -1050, "deathYear": -970, "age": 80 }, "historicalContribution": "为周穆王驾车,平定徐偃王之乱,因功获封赵城", "impactOnZhao": "开创赵氏基业,为后世赵国奠定基础", "characterTraits": "忠诚、技艺精湛、勇敢", "famousQuotes": ["御者之道,在于人车合一"], "majorEvents": [{ "year": -1000, "event": "为周穆王驾车西征", "significance": "展现了卓越的驾车技艺" }], "relationships": [{ "relatedNpcId": 2, "relatedNpcName": "叔带", "relationshipType": "后代", "description": "造父的后代,继承了赵氏血脉" }], "culturalLegacy": { "skills": ["驾车技艺", "军事才能"], "values": ["忠诚", "勇敢", "技艺精神"], "influence": "开创了赵氏家族的忠诚传统" } } } }

4. NPC交互接口

POST /api/v1/npcs/{npcId}/start-interaction
开始与NPC的深度交互

请求参数

{ "chapterId": 1, "interactionContext": { "location": { "lat": 36.123456, "lng": 114.123456 }, "triggerMethod": "ar_scan", "userMood": "curious" } }

响应示例

{ "code": 0, "message": "success", "data": { "interactionId": "int_20240320_001", "npc": { "id": 1, "name": "造父", "greeting": "年轻人,你来到这赵城遗址,是想了解我们赵氏的起源吗?", "currentMood": "friendly", "availableTopics": ["赵氏起源", "驾车技艺", "忠诚之道"] }, "interactionStages": { "currentStage": "greeting", "availableStages": ["dilemma", "regret", "philosophy"], "stageProgress": { "greeting": "completed", "dilemma": "available", "regret": "locked", "philosophy": "locked" } }, "historicalContext": { "timeDescription": "西周末年,王室衰微,诸侯争霸的时代", "locationDescription": "赵城,造父因功获封之地", "socialContext": "贵族社会,重视忠诚和技艺" } } }
POST /api/v1/interactions/{interactionId}/dilemma
进入两难问题阶段

响应示例

{ "code": 0, "message": "success", "data": { "dilemma": { "id": 1, "title": "忠诚与生命的抉择", "description": "徐偃王叛乱,周王命我驾车前往平叛。路途凶险,九死一生,但这是王命...", "historicalContext": "徐偃王自立为王,挑战周王权威,局势危急", "contextVideoUrl": "https://example.com/dilemma1.mp4", "emotionalTone": "紧张", "difficultyLevel": 3, "educationalValue": "探讨忠诚与个人安危的关系,理解古代君臣关系" }, "strategies": [{ "id": 1, "strategyType": 1, "title": "义无反顾,驾车前往", "description": "忠君是臣子的本分,纵然前路凶险,也要完成王命", "requiredAttributes": { "strategy": 2, "warfare": 3, "benevolence": 1, "chivalry": 4, "versatility": 2 }, "potentialOutcome": "展现忠诚品质,但面临生命危险", "historicalAccuracy": "符合造父的历史形象" }], "timeLimit": 300, "hints": ["考虑当时的社会价值观", "思考忠诚的真正含义"] } }
POST /api/v1/interactions/{interactionId}/submit-strategy
提交策略选择

请求参数

{ "strategyId": 1, "reasoning": "忠诚是古代君臣关系的核心,造父的选择体现了那个时代的价值观", "emotionalResponse": "敬佩", "decisionTime": 180 }

响应示例

{ "code": 0, "message": "success", "data": { "result": { "strategyEvaluation": "excellent", "historicalAccuracy": 95, "educationalValue": "深刻理解了古代忠诚观念" }, "npcResponse": { "gratitudeVideoUrl": "https://example.com/gratitude1.mp4", "responseText": "你理解了忠诚的真谛。正是这种品质,让赵氏得以传承至今", "emotionalReaction": "感动" }, "enlightenment": { "videoUrl": "https://example.com/enlightenment1.mp4", "insights": ["忠诚不仅是对君主的忠诚,更是对信念的坚持"], "historicalLessons": ["古代社会的君臣关系", "忠诚品质的时代价值"] }, "attributeChanges": { "strategy": { "before": 3, "after": 3 }, "warfare": { "before": 2, "after": 3 }, "benevolence": { "before": 4, "after": 4 }, "chivalry": { "before": 3, "after": 5 }, "versatility": { "before": 2, "after": 2 } }, "rewards": [{ "type": 1, "name": "忠诚之心", "description": "造父传承的忠诚品质", "iconUrl": "https://example.com/loyalty.png", "rarity": 2 }], "nextStage": "regret" } }

5. 用户成长接口

GET /api/v1/user/growth-report
获取用户的历史学习成长报告

响应示例

{ "code": 0, "message": "success", "data": { "overallProgress": { "totalChaptersCompleted": 3, "totalNpcsInteracted": 15, "totalHistoricalInsights": 28, "learningDays": 45, "averageSessionDuration": 25 }, "attributeGrowth": { "strategy": { "initial": 3, "current": 7, "growth": 4, "growthRate": "133%" }, "warfare": { "initial": 2, "current": 5, "growth": 3, "growthRate": "150%" } }, "historicalInterests": { "topPeriods": ["战国中期", "春秋晚期"], "favoriteNpcs": ["赵武灵王", "廉颇"], "preferredTopics": ["军事改革", "外交策略"], "learningStyle": "深度思考型" }, "achievements": [{ "id": 1, "name": "历史学者", "description": "完成3个篇章的学习", "unlockedAt": "2024-03-15T14:30:00Z", "rarity": "rare" }], "recommendations": { "nextChapter": { "id": 4, "name": "胡服骑射·变法图强", "reason": "基于您对军事改革的兴趣推荐" }, "suggestedNpcs": ["赵武灵王", "李牧"], "learningGoals": ["了解军事改革的历史意义", "学习变法的智慧"] } } }

6. 数据统计接口

GET /api/v1/statistics/community
获取社区统计数据

响应示例

{ "code": 0, "message": "success", "data": { "globalStats": { "totalUsers": 15420, "totalInteractions": 89650, "totalChapterCompletions": 32180, "averageCompletionTime": 180 }, "popularContent": { "topChapters": [{ "id": 5, "name": "长平血战·国运转折", "completionCount": 8920, "averageRating": 4.8 }], "topNpcs": [{ "id": 15, "name": "赵武灵王", "interactionCount": 12450, "favoriteRate": 0.85 }] }, "userRanking": { "currentUserRank": 156, "totalParticipants": 15420, "percentile": 99, "nearbyUsers": [{ "rank": 155, "nickname": "历史爱好者", "score": 8920 }] } } }

7. 通用规范

7.1 响应格式规范

{ "code": 0, // 0表示成功,非0表示错误 "message": "string", // 状态描述信息 "data": "object" // 响应数据 }

7.2 错误码规范

错误码 描述 说明
0 成功 请求处理成功
1001 参数错误 请求参数格式或内容错误
1002 未授权 token无效或已过期
2001 用户不存在 指定的用户ID不存在
2002 篇章不存在 指定的篇章ID不存在
2003 NPC不存在 指定的NPC ID不存在
3001 篇章未解锁 用户尚未解锁该篇章
3002 交互条件不满足 不满足NPC交互的前置条件
5001 系统错误 服务器内部错误

7.3 安全规范

安全要求

  • HTTPS传输:所有接口必须使用HTTPS
  • 身份认证:使用JWT token进行身份验证
  • 数据加密:敏感数据传输必须加密
  • 频率限制:关键接口需要进行频率限制
  • 位置验证:交互触发需要验证用户位置

7.4 性能规范

< 200ms
普通查询接口响应时间
< 500ms
复杂计算接口响应时间
99.9%
服务可用性要求
1000 QPS
并发处理能力

7.5 文化教育规范

教育价值要求

  • 历史准确性:所有历史内容必须经过专业验证
  • 教育意义:每个交互都要有明确的教育价值
  • 文化传承:突出中华优秀传统文化的传承
  • 价值引导:通过历史故事传递正确的价值观