spec: 升级 openapi.provider.yaml 至 L2 契约等级 [AC-MCA-08][AC-MCA-12]

This commit is contained in:
MerCry 2026-02-24 11:31:30 +08:00
parent 84edbccb1b
commit f09f22f447
1 changed files with 308 additions and 10 deletions

View File

@ -9,7 +9,7 @@ info:
- 人工客服工作台 REST API - 人工客服工作台 REST API
- WebSocket 实时通信协议说明 - WebSocket 实时通信协议说明
version: 1.0.0 version: 1.0.0
x-contract-level: L0 x-contract-level: L2
x-consumer: "frontend, wechat-server, douyin-server, jd-server" x-consumer: "frontend, wechat-server, douyin-server, jd-server"
x-provider: "java-main-framework" x-provider: "java-main-framework"
@ -41,7 +41,10 @@ paths:
get: get:
operationId: verifyWecomUrl operationId: verifyWecomUrl
summary: 微信回调 URL 验证 summary: 微信回调 URL 验证
description: 企业微信回调 URL 验证接口 description: |
企业微信回调 URL 验证接口。
用于验证回调 URL 的有效性,企业微信在配置回调时会发送 GET 请求。
tags: tags:
- Channel Callback - Channel Callback
parameters: parameters:
@ -50,21 +53,31 @@ paths:
required: true required: true
schema: schema:
type: string type: string
minLength: 1
maxLength: 128
description: 消息签名,用于验证请求来源
- name: timestamp - name: timestamp
in: query in: query
required: true required: true
schema: schema:
type: string type: string
pattern: '^\d+$'
description: 时间戳(秒级),用于防重放攻击
- name: nonce - name: nonce
in: query in: query
required: true required: true
schema: schema:
type: string type: string
minLength: 1
maxLength: 64
description: 随机字符串,用于防重放攻击
- name: echostr - name: echostr
in: query in: query
required: true required: true
schema: schema:
type: string type: string
minLength: 1
description: 加密的随机字符串,验证成功后需解密返回
responses: responses:
'200': '200':
description: 验证成功,返回解密后的 echostr description: 验证成功,返回解密后的 echostr
@ -72,13 +85,31 @@ paths:
text/plain: text/plain:
schema: schema:
type: string type: string
'500': example: "1234567890"
description: 验证失败 '400':
description: 请求参数错误
content: content:
text/plain: text/plain:
schema: schema:
type: string type: string
example: error enum:
- error
'401':
description: 签名验证失败
content:
text/plain:
schema:
type: string
enum:
- error
'500':
description: 服务器内部错误
content:
text/plain:
schema:
type: string
enum:
- error
post: post:
operationId: handleWecomCallback operationId: handleWecomCallback
@ -104,18 +135,21 @@ paths:
required: false required: false
schema: schema:
type: string type: string
maxLength: 128
description: 消息签名(用于验签) description: 消息签名(用于验签)
- name: timestamp - name: timestamp
in: query in: query
required: false required: false
schema: schema:
type: string type: string
pattern: '^\d+$'
description: 时间戳(用于防重放) description: 时间戳(用于防重放)
- name: nonce - name: nonce
in: query in: query
required: false required: false
schema: schema:
type: string type: string
maxLength: 64
description: 随机数(用于防重放) description: 随机数(用于防重放)
requestBody: requestBody:
required: true required: true
@ -124,6 +158,7 @@ paths:
schema: schema:
type: string type: string
description: 加密的 XML 消息 description: 加密的 XML 消息
example: "<xml><Encrypt>...</Encrypt></xml>"
responses: responses:
'200': '200':
description: 处理成功 description: 处理成功
@ -131,7 +166,32 @@ paths:
text/plain: text/plain:
schema: schema:
type: string type: string
example: success enum:
- success
'400':
description: 请求格式错误
content:
text/plain:
schema:
type: string
enum:
- success
'401':
description: 签名验证失败
content:
text/plain:
schema:
type: string
enum:
- success
'500':
description: 服务器内部错误(仍返回 success 以避免微信重试)
content:
text/plain:
schema:
type: string
enum:
- success
/channel/{channelType}/callback: /channel/{channelType}/callback:
post: post:
@ -177,18 +237,21 @@ paths:
required: false required: false
schema: schema:
type: string type: string
maxLength: 256
description: 消息签名(可选,具体由渠道决定) description: 消息签名(可选,具体由渠道决定)
- name: X-Timestamp - name: X-Timestamp
in: header in: header
required: false required: false
schema: schema:
type: string type: string
pattern: '^\d+$'
description: 时间戳(可选,用于防重放) description: 时间戳(可选,用于防重放)
- name: X-Nonce - name: X-Nonce
in: header in: header
required: false required: false
schema: schema:
type: string type: string
maxLength: 64
description: 随机数(可选,用于防重放) description: 随机数(可选,用于防重放)
requestBody: requestBody:
required: true required: true
@ -204,6 +267,30 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
'400':
description: 请求格式错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
'401':
description: 签名验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
'404':
description: 不支持的渠道类型
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
/api/sessions: /api/sessions:
get: get:
@ -235,6 +322,7 @@ paths:
required: false required: false
schema: schema:
type: string type: string
maxLength: 64
description: 客服ID筛选 description: 客服ID筛选
- name: channelType - name: channelType
in: query in: query
@ -253,11 +341,25 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SessionListResponse' $ref: '#/components/schemas/SessionListResponse'
'400':
description: 请求参数错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
/api/sessions/{sessionId}: /api/sessions/{sessionId}:
get: get:
operationId: getSession operationId: getSession
summary: 获取会话详情 summary: 获取会话详情
description: |
获取指定会话的详细信息。
tags: tags:
- Session Management - Session Management
parameters: parameters:
@ -266,6 +368,9 @@ paths:
required: true required: true
schema: schema:
type: string type: string
minLength: 1
maxLength: 64
description: 会话ID
responses: responses:
'200': '200':
description: 成功 description: 成功
@ -273,17 +378,31 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SessionResponse' $ref: '#/components/schemas/SessionResponse'
'400':
description: 请求参数错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
'404': '404':
description: 会话不存在 description: 会话不存在
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
/api/sessions/{sessionId}/history: /api/sessions/{sessionId}/history:
get: get:
operationId: getSessionHistory operationId: getSessionHistory
summary: 获取会话消息历史 summary: 获取会话消息历史
description: |
获取指定会话的消息历史记录。
tags: tags:
- Session Management - Session Management
parameters: parameters:
@ -292,6 +411,9 @@ paths:
required: true required: true
schema: schema:
type: string type: string
minLength: 1
maxLength: 64
description: 会话ID
responses: responses:
'200': '200':
description: 成功 description: 成功
@ -299,12 +421,33 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/MessageListResponse' $ref: '#/components/schemas/MessageListResponse'
'400':
description: 请求参数错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
'404':
description: 会话不存在
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
/api/sessions/{sessionId}/accept: /api/sessions/{sessionId}/accept:
post: post:
operationId: acceptSession operationId: acceptSession
summary: 接入会话 summary: 接入会话
description: 客服接入待处理的会话 description: |
客服接入待处理的会话。
仅状态为 `pending` 的会话可被接入。
tags: tags:
- Session Management - Session Management
parameters: parameters:
@ -313,6 +456,9 @@ paths:
required: true required: true
schema: schema:
type: string type: string
minLength: 1
maxLength: 64
description: 会话ID
requestBody: requestBody:
required: true required: true
content: content:
@ -324,7 +470,11 @@ paths:
properties: properties:
csId: csId:
type: string type: string
minLength: 1
maxLength: 64
description: 客服ID description: 客服ID
example:
csId: "cs_001"
responses: responses:
'200': '200':
description: 接入成功 description: 接入成功
@ -333,23 +483,44 @@ paths:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
'400': '400':
description: 会话状态不正确 description: 会话状态不正确或参数错误
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
examples:
invalid_status:
value:
code: 400
message: "会话状态不正确"
missing_csId:
value:
code: 400
message: "客服ID不能为空"
'404': '404':
description: 会话不存在 description: 会话不存在
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
example:
code: 404
message: "会话不存在"
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
/api/sessions/{sessionId}/message: /api/sessions/{sessionId}/message:
post: post:
operationId: sendSessionMessage operationId: sendSessionMessage
summary: 发送消息 summary: 发送消息
description: 客服向会话发送消息 description: |
客服向会话发送消息。
仅状态为 `manual` 的会话可发送消息。
tags: tags:
- Session Management - Session Management
parameters: parameters:
@ -358,6 +529,9 @@ paths:
required: true required: true
schema: schema:
type: string type: string
minLength: 1
maxLength: 64
description: 会话ID
requestBody: requestBody:
required: true required: true
content: content:
@ -369,11 +543,20 @@ paths:
properties: properties:
content: content:
type: string type: string
minLength: 1
maxLength: 4096
description: 消息内容 description: 消息内容
msgType: msgType:
type: string type: string
enum:
- text
- image
- file
default: text default: text
description: 消息类型 description: 消息类型
example:
content: "您好,请问有什么可以帮助您的?"
msgType: "text"
responses: responses:
'200': '200':
description: 发送成功 description: 发送成功
@ -382,22 +565,39 @@ paths:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
'400': '400':
description: 会话状态不正确 description: 会话状态不正确或参数错误
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
examples:
invalid_status:
value:
code: 400
message: "会话状态不正确"
missing_content:
value:
code: 400
message: "消息内容不能为空"
'404': '404':
description: 会话不存在 description: 会话不存在
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
'500':
description: 服务器内部错误或消息发送失败
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
/api/sessions/{sessionId}/close: /api/sessions/{sessionId}/close:
post: post:
operationId: closeSession operationId: closeSession
summary: 关闭会话 summary: 关闭会话
description: |
关闭指定的会话。
tags: tags:
- Session Management - Session Management
parameters: parameters:
@ -406,6 +606,9 @@ paths:
required: true required: true
schema: schema:
type: string type: string
minLength: 1
maxLength: 64
description: 会话ID
responses: responses:
'200': '200':
description: 关闭成功 description: 关闭成功
@ -413,12 +616,24 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
'400':
description: 请求参数错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
'404': '404':
description: 会话不存在 description: 会话不存在
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $ref: '#/components/schemas/ApiResponse'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
components: components:
schemas: schemas:
@ -431,42 +646,89 @@ components:
code: code:
type: integer type: integer
description: 响应码0=成功非0=失败) description: 响应码0=成功非0=失败)
enum:
- 0
- 400
- 404
- 500
message: message:
type: string type: string
minLength: 1
maxLength: 256
description: 响应消息 description: 响应消息
data: data:
type: object type: object
description: 响应数据(可选) description: 响应数据(可选)
example:
code: 0
message: "success"
SessionListResponse: SessionListResponse:
allOf: allOf:
- $ref: '#/components/schemas/ApiResponse' - $ref: '#/components/schemas/ApiResponse'
- type: object - type: object
required:
- code
- message
- data
properties: properties:
code:
type: integer
enum:
- 0
message:
type: string
data: data:
type: array type: array
items: items:
$ref: '#/components/schemas/SessionInfo' $ref: '#/components/schemas/SessionInfo'
example:
code: 0
message: "success"
data:
- sessionId: "session_001"
customerId: "customer_001"
status: "manual"
channelType: "wechat"
SessionResponse: SessionResponse:
allOf: allOf:
- $ref: '#/components/schemas/ApiResponse' - $ref: '#/components/schemas/ApiResponse'
- type: object - type: object
required:
- code
- message
- data
properties: properties:
code:
type: integer
enum:
- 0
message:
type: string
data: data:
$ref: '#/components/schemas/SessionInfo' $ref: '#/components/schemas/SessionInfo'
SessionInfo: SessionInfo:
type: object type: object
required:
- sessionId
- customerId
- status
properties: properties:
sessionId: sessionId:
type: string type: string
minLength: 1
maxLength: 64
description: 会话ID description: 会话ID
customerId: customerId:
type: string type: string
minLength: 1
maxLength: 64
description: 客户ID description: 客户ID
kfId: kfId:
type: string type: string
maxLength: 64
description: 客服账号ID description: 客服账号ID
channelType: channelType:
type: string type: string
@ -485,9 +747,11 @@ components:
- closed - closed
manualCsId: manualCsId:
type: string type: string
maxLength: 64
description: 接待客服ID description: 接待客服ID
lastMessage: lastMessage:
type: string type: string
maxLength: 4096
description: 最后一条消息 description: 最后一条消息
lastMessageTime: lastMessageTime:
type: string type: string
@ -495,19 +759,35 @@ components:
description: 最后消息时间 description: 最后消息时间
messageCount: messageCount:
type: integer type: integer
minimum: 0
description: 消息数量 description: 消息数量
createdAt: createdAt:
type: string type: string
format: date-time format: date-time
description: 创建时间
updatedAt: updatedAt:
type: string type: string
format: date-time format: date-time
description: 更新时间
metadata:
type: object
description: 扩展元数据
MessageListResponse: MessageListResponse:
allOf: allOf:
- $ref: '#/components/schemas/ApiResponse' - $ref: '#/components/schemas/ApiResponse'
- type: object - type: object
required:
- code
- message
- data
properties: properties:
code:
type: integer
enum:
- 0
message:
type: string
data: data:
type: array type: array
items: items:
@ -515,12 +795,21 @@ components:
MessageInfo: MessageInfo:
type: object type: object
required:
- msgId
- sessionId
- senderType
- content
properties: properties:
msgId: msgId:
type: string type: string
minLength: 1
maxLength: 128
description: 消息ID description: 消息ID
sessionId: sessionId:
type: string type: string
minLength: 1
maxLength: 64
description: 会话ID description: 会话ID
senderType: senderType:
type: string type: string
@ -531,16 +820,25 @@ components:
- manual - manual
senderId: senderId:
type: string type: string
maxLength: 64
description: 发送者ID description: 发送者ID
content: content:
type: string type: string
minLength: 1
maxLength: 4096
description: 消息内容 description: 消息内容
msgType: msgType:
type: string type: string
description: 消息类型 description: 消息类型
enum:
- text
- image
- file
- event
createdAt: createdAt:
type: string type: string
format: date-time format: date-time
description: 创建时间
x-websocket: x-websocket:
path: /ws/cs/{csId} path: /ws/cs/{csId}