新增默认群组
1. 接口定位
- 接口名称: 新增默认群组
- 所属域: admin/default/group
- 业务目标: 配置新注册用户自动加入的默认群组列表
2. 请求定义
- Method:
POST - Path:
/default/group/add - Content-Type: 推荐
application/json - operationID: 必填,请通过 Header
operationID传入 - 鉴权: 需要 Header
token,且必须是管理员 token - 幂等性: 非幂等
3. 请求参数
Header 参数
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| operationID | 是 | string | 链路追踪 ID |
| token | 是 | string | 管理员 token |
Body 参数
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| groupIDs | 是 | array<string> | 要加入默认入群池的群组 ID 列表 |
字段约束
groupIDs不能为空数组。groupIDs不能有重复值。- API 层会先去 OpenIM 查询群资料,确保所有
groupID都真实存在。 - 已存在于默认群组池中的
groupID不能重复添加。
4. 响应结构
通用响应包裹
| 字段 | 类型 | 说明 |
|---|---|---|
| errCode | int | 错误码,0 表示成功 |
| errMsg | string | 错误简述 |
| errDlt | string | 错误详情 |
| data | object | 业务数据 |
data 字段
- 成功时返回空对象。
5. 业务规则
- 与默认好友不同,默认群组新增在 API 层有额外的 OpenIM 校验。
- API 层会用默认 IM 管理员 token 调用
FindGroupInfo,如果返回群数量与groupIDs数量不一致,则直接报group id not found。 - RPC 层只负责管理员鉴权、重复校验和落库。
6. 错误码与失败场景
| 错误码 | 场景 | 典型报错 |
|---|---|---|
| 1001 | groupIDs 为空 | GroupIDs is empty 或 group ids is empty |
| 1001 | groupIDs 存在重复值 | GroupIDs has duplicate 或 group ids is duplicate |
| 1001 | 某些群组在 OpenIM 中不存在 | group id not found |
| - | 某些群组已在默认群组池中 | group id existed |
| - | 查询群资料失败 | 由 OpenIM 群资料链路返回 |
7. 示例
fetch 请求示例
javascript
fetch("http://localhost:10009/default/group/add", {
method: "POST",
headers: {
operationID: "550e8400-e29b-41d4-a716-446655440305",
token: "eyJhbGciOi...",
"Content-Type": "application/json",
},
body: JSON.stringify({
groupIDs: ["group_001", "group_002"],
}),
})
.then((res) => res.json())
.then((data) => console.log(data));请求示例(JSON)
json
{
"groupIDs": ["group_001", "group_002"]
}成功响应示例
json
{
"errCode": 0,
"errMsg": "",
"errDlt": "",
"data": {}
}失败响应示例
json
{
"errCode": 1001,
"errMsg": "ArgsError",
"errDlt": "group id not found"
}8. 时序流程
- 中间件校验管理员 token。
- 校验
groupIDs非空且无重复。 - API 层到 OpenIM 校验所有群组是否存在。
- RPC 层检查是否已存在于默认群组池。
- 批量写入默认群组配置。
9. 变更记录
- 2026-03-31: 首版发布,基于默认群组新增 API+RPC 双层校验逻辑补全文档。