Aile 平臺整合(Integration)外部對接手冊
版本: v2.2
最後更新: 2026-06-26
適用對象: 第三方系統整合開發者
服務模組: aile-service-integration
程式碼分支: release
v2.2 保留 AIFF 寫入規格、
pictureUrl主資料與 setting 級圖片、訊息傳送、服務廣播與 Simulator 聯調說明。v2.2+ 變更摘要(2026-06-25 release):
- Breaking: OpenAPI 路徑重構 — 從
/integration/openapi/v1/<資源>改為/<資源>/v1/<動作>。- Breaking: 所有 OpenAPI 端點統一為 POST,不再支援 GET。
- Breaking: HMAC 簽名公式修正 —
integrationId + nonce + body(不含 method/path)。- Breaking: Authorization 頭字首從
HMAC-SHA256改為AILE。- 新增: AIFF 寫入介面(create/update/delete)。
- 新增: 訊息傳送介面(
POST /messages/v1/send)。- 新增: 群發廣播介面(
POST /messages/v1/broadcast/create)。- 修正: 事件資源域和事件型別列表(基於原始碼)。
目錄
- 概述
- 核心概念與模型
- 整合接入流程
- OpenAPI 安全機制(HMAC 簽名)
- 控制面 API(平臺管理端)
- OpenAPI(第三方呼叫 Aile)
- Webhook 事件推送(Aile → 第三方)
- 事件資源域與事件型別參考
- 接入實戰指南(第三方 開發步驟)
- 參考實現:Simulator 模擬服務
- 常見問題與錯誤碼
1. 概述
Aile 平臺整合(Platform Integration)是一套標準化的第三方系統接入框架,允許外部 SaaS 平臺以租戶級別安裝 Aile 服務,並交換業務事件與資料。
1.1 架構全景
┌─────────────────────────────────────────────────┐
│ Aile 平臺 │
│ │
│ aile-service-integration │
│ ├── /integration/app/* 應用定義管理 │
│ ├── /integration/tenant/* 安裝生命週期管理 │
│ ├── /messages/* 訊息傳送 / 廣播 │
│ ├── /openapi/* 第三方 API(HMAC簽名)│
│ └── InternalEvent → Webhook → 第三方回撥 │
│ │
│ aile-service-tenant (事件釋出) │
│ └── InternalEventTrigger → 業務事件發布 │
└─────────────────────────────────────────────────┘
│ 控制面 (HTTP) │ OpenAPI (HMAC) │ Webhook (HMAC)
▼ ▼ ▼
┌─────────────────────────────────────────────────┐
│ 第三方整合平臺(你) │
│ ├── 安裝介面 (接收 Aile 安裝請求) │
│ ├── OpenAPI 呼叫 (查詢/傳送訊息/群發廣播) │
│ └── Webhook 接收 (接收 Aile 業務事件) │
└─────────────────────────────────────────────────┘
1.2 與舊版 TenantAppModel 的關係
注意: aile-service-job 模組中有一個舊的 TenantAppModel / TenantAppController 體系,以 /tenantapp、/webhook 為路徑字首。本手冊描述的是新的 Integration Platform 體系(基於 IntegrationAppModel / TenantIntegrationModel),路徑字首為 /integration/。新體系相較舊體繫有以下增強:
| 特性 | 舊 TenantAppModel | 新 Integration Platform |
|---|---|---|
| 應用定義 | 無全域性應用定義 | IntegrationApp(獨立於租戶) |
| 安裝生命週期 | 簡單 CRUD | 完整狀態機 Pending→Active→Suspended→Deleted |
| 金鑰管理 | 固定 secretKey | HMAC appSecret + rotate-secret |
| 事件訂閱 | webHookTypes | subscribedEvents(事件資源域粒度) |
| 第三方回撥 | 無 | install/update/rotateSecret/uninstall |
| OpenAPI 目錄 | 無 | catalog 端點自動發現 |
| 安全隔離 | 簽名+租戶繫結 | integrationId + body 一致性校驗 + nonce |
2. 核心概念與模型
2.1 IntegrationApp(平臺應用定義)
這是由 Aile 管理員建立的全域性應用註冊,描述一個第三方平臺的身份和能力。
{
"appId": "your-app-id", // 全域性唯一應用 ID
"appName": "Your Platform Name", // 應用名稱
"provider": "your-company", // 提供方
"supportedEvents": [ // 支援的事件資源域(*. 為通配)
"contact.*",
"service_number.*"
],
"authType": "HMAC_SHA256", // 鑑權型別
"secret": "platform-secret", // 平臺級金鑰(Aile 呼叫第三方時使用)
"installUrl": "https://your-platform.com/api/aile/install", // 第三方安裝 URL
"updateUrl": "https://your-platform.com/api/aile/update", // 第三方更新 URL
"rotateSecretUrl": "https://your-platform.com/api/aile/rotate", // 第三方輪換金鑰 URL
"uninstallUrl": "https://your-platform.com/api/aile/uninstall", // 第三方解除安裝 URL
"installAckMode": "Sync", // Sync(同步完成)或 Async(非同步受理)
"status": "Active" // Draft → Active → Suspended → Deleted
}
──→ 狀態機:
Draft → Active → Suspended → Active → Deleted
2.2 TenantIntegration(租戶安裝例項)
當一個 Aile 租戶安裝你的平臺應用時,會在 Aile 端建立一個安裝例項:
{
"integrationId": "ti_xxxxx", // 安裝例項唯一 ID(Aile 生成)
"appId": "your-app-id", // 關聯的應用 ID
"tenantId": "T001", // Aile 租戶 ID
"tenantType": "enterprise", // 租戶型別
"externalTenantId": "EXT-12345", // 第三方系統對應租戶 ID(由你指定)
"appSecret": "generated-secret", // 安裝級金鑰(用於 HMAC 簽名,由 Aile 生成)
"webhookUrl": "https://your-platform.com/webhook/events", // 事件接收地址
"subscribedEvents": [ // 實際訂閱的事件資源域
"contact.*",
"service_number.*"
],
"installAckMode": "Sync", // 受理模式
"status": "Active" // 安裝狀態
}
──→ 安裝狀態機:
Pending → Active → Suspended/Disabled → Active → Deleted
InstallFailed狀態表示安裝失敗。
2.3 租戶隔離模型
- 一個
IntegrationApp可以被多個租戶安裝(多個TenantIntegration) - 每個
TenantIntegration擁有獨立的appSecret和webhookUrl - OpenAPI 呼叫時,第三方只能訪問該安裝例項所屬租戶的資料
- 跨系統租戶對映透過
externalTenantId欄位管理(不存在獨立的 TenantMapping 模型)
3. 整合接入流程
3.1 整體流程圖
Step 0: Aile 管理員註冊 IntegrationApp(後臺操作)
│
Step 1: Aile 租戶發起安裝
POST /integration/tenant/system/v1/install
{ appId, tenantId, tenantType }
│
├── Aile 建立 TenantIntegration(狀態=Pending)
├── Aile 呼叫第三方 installUrl(傳遞 integrationId、appSecret 等)
│
Step 2: 第三方處理安裝
├── 驗證請求合法性
├── 建立外部租戶關聯
├── 確認 webhookUrl 和 subscribedEvents
│
├── Sync 模式:直接返回 { status: "Active", externalTenantId, webhookUrl, subscribedEvents }
│ → Aile 更新狀態為 Active
│
└── Async 模式:先返回 { accepted: true, status: "Pending" }
→ 後續回撥 Aile
POST /integration/tenant/open/v1/install/callback
{ integrationId, status: "Active", externalTenantId, webhookUrl, subscribedEvents }
→ Aile 更新狀態為 Active
Step 3: 日常執行
├── 第三方呼叫 Aile OpenAPI(HMAC 簽名,查詢/同步資料)
└── Aile 推送業務事件到第三方 webhookUrl(HMAC 簽名)
Step 4: 解除安裝
POST /integration/tenant/system/v1/uninstall?integrationId=xxx
├── Aile 呼叫第三方 uninstallUrl
└── TenantIntegration 狀態 = Deleted
3.2 Aile 傳送給第三方的安裝請求
當租戶發起安裝後,Aile 會呼叫 IntegrationApp.installUrl,傳送的請求體:
{
"integrationId": "ti_xxxxx",
"appId": "your-app-id",
"tenantId": "T001",
"tenantType": "enterprise",
"operatorId": "emp_001",
"appSecret": "generated-secret-for-this-instance",
"installationCallbackUrl": "https://aile-api.com/integration/tenant/open/v1/install/callback",
"installAckMode": "Sync",
"subscribedEvents": ["contact.*", "service_number.*"]
}
3.3 第三方應返回的安裝響應
Sync 模式(installAckMode=Sync):
{
"status": "Active",
"externalTenantId": "EXT-12345",
"webhookUrl": "https://your-platform.com/webhook/events",
"subscribedEvents": ["contact.*", "service_number.*"]
}
Async 模式(installAckMode=Async):
{
"accepted": true,
"status": "Pending"
}
之後非同步回撥 Aile:
curl -X POST https://aile-api.com/integration/tenant/open/v1/install/callback \
-H "Content-Type: application/json" \
-d '{
"integrationId": "ti_xxxxx",
"status": "Active",
"externalTenantId": "EXT-12345",
"webhookUrl": "https://your-platform.com/webhook/events",
"subscribedEvents": ["contact.*", "service_number.*"]
}'
3.4 第三方更新 / 輪換金鑰 / 解除安裝介面
Aile 在以下場景會呼叫第三方對應 URL(定義在 IntegrationApp 中):
| 操作 | Aile 呼叫 | 傳遞引數 |
|---|---|---|
| 更新配置 | updateUrl | { integrationId, webhookUrl, subscribedEvents } |
| 輪換金鑰 | rotateSecretUrl | { integrationId, operatorId } |
| 解除安裝 | uninstallUrl | { integrationId } |