文档版本:v1.0 最后更新:2026-04-02 08:28:05
本文档定义小程序接入线上业务 API 时的架构边界,确保以下原则始终成立:
本文档适用于以下接入范围:
线上接入后,系统仍保持两层结构:
两层之间只允许通过一个明确的启动模型通信,不允许业务 API 对游戏规则对象做直接写入。
一句话定义:
API 负责发放启动上下文,配置负责定义游戏本身。
业务层负责:
业务层可以决定:
session_id、session_token业务层不可以决定:
游戏层负责:
GameDefinition 构建游戏层只认配置和本地运行态,不认业务 API 对象。
游戏层不应该直接出现以下业务字段:
competition_idregistration_statusaccess_tokenrefresh_tokenAuthorizationuser_id业务字段可以存在于页面壳层或业务服务层,但不进入规则层。
业务层和游戏层之间,统一通过 GameLaunchEnvelope 通信。
建议结构如下:
interface GameLaunchEnvelope {
config: {
configUrl: string
configLabel: string
configChecksumSha256?: string | null
releaseId?: string | null
routeCode?: string | null
}
business: {
source: 'demo' | 'competition' | 'direct-event' | 'custom'
competitionId?: string | null
eventId?: string | null
launchRequestId?: string | null
participantId?: string | null
sessionId?: string | null
sessionToken?: string | null
sessionTokenExpiresAt?: string | null
realtimeEndpoint?: string | null
realtimeToken?: string | null
} | null
}
解释:
config 是游戏层真正消费的输入business 是业务壳保留的上下文config适用于本地调试、离线测试、玩法验证。
流程:
GameLaunchEnvelopeconfig.configUrl 指向 demo 配置business.source = 'demo'特点:
适用于正式业务入口。
流程:
launchsession_id、session_token、release_id、manifest_url、route_codeGameLaunchEnvelopeconfig 载入配置business 上下文供后续上报使用注意:
launch 是业务启动,不等于规则层 startSession适用于地图详情或 Event 直入。
流程与赛事入口基本一致,区别仅在于:
business.source = 'direct-event'后端提供的 manifest_url 不应直接变成规则层对象。
推荐做法:
manifest 是“线上发布描述”,不是“规则运行对象”。
建议把 manifest 适配理解为一个编译过程:
建议按三层组织代码:
miniprogram/
services/
http.ts
client-api.ts
auth.ts
business/
launch/
launchBuilder.ts
launchStore.ts
manifestAdapter.ts
utils/
gameLaunch.ts
pages/
login/
home/
competition-detail/
event-detail/
map/
说明:
services 只处理 API 通信business/launch 只做业务到配置的适配utils/gameLaunch.ts 定义启动模型和页面跳转协议pages/map 只做配置加载和游戏承载允许进入地图页:
GameLaunchEnvelopeconfigUrlconfigLabelreleaseIdrouteCodesessionToken但地图页内部还要继续区分:
configbusiness以下内容禁止进入 MapEngine、GameRuntime、GameDefinition:
后续若接 punches、finish、session-uploads,建议流程如下:
不要在规则层里直接 wx.request。
当前项目已具备以下基础:
remoteMapConfig.ts 负责远程配置加载MapEngine 负责本地规则与表现运行utils/gameLaunch.ts 作为启动边界模型当前建议继续保持:
MapEngine 只接 RemoteMapConfigGameLaunchEnvelope.config 获取配置入口目标:
GameLaunchEnvelope验收标准:
目标:
验收标准:
目标:
manifest_url 适配为当前配置体系可消费的输入验收标准:
目标:
验收标准:
GameDefinition如果后续出现需求需要绕过这几条规则,应视为架构变更,不应当作普通功能迭代处理。
线上系统负责“把用户送进正确的一局游戏”,配置系统负责“定义这局游戏是什么”。