设置违禁词策略
1. 接口定位
- 接口名称: 设置违禁词策略
- 所属域: admin/sensitive-word
- 业务目标: 配置 single/group 场景策略开关与动作
2. 请求定义
- Method:
POST - Path:
/adminx/sensitive_word/policy/set - Content-Type: 推荐
application/json - operationID: 必填,请通过 Header
operationID传入 - 鉴权: 需要 Header
token,且必须是管理员 token - 幂等性: 近似幂等;同一
scene会被 upsert 覆盖
3. 请求参数
Header 参数
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| operationID | 是 | string | 链路追踪 ID |
| token | 是 | string | 管理员 token |
Body 参数
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| policy | 是 | object | 策略 |
policy 字段:
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| scene | 是 | string | 场景:single 或 group |
| enabled | 是 | bool | 是否启用该场景策略 |
| action | 否 | string | 动作:reject 或 allow,默认 reject |
字段约束
- 协议校验要求
policy非空。 scene仅允许single/group。action为空时默认按reject处理。action仅允许reject/allow。
4. 响应结构
通用响应包裹
| 字段 | 类型 | 说明 |
|---|---|---|
| errCode | int | 错误码,0 表示成功 |
| errMsg | string | 错误简述 |
| errDlt | string | 错误详情 |
| data | object | 业务数据 |
data 字段
- 本接口成功时返回空对象(无业务字段)。
5. 业务规则
- 策略按
sceneupsert。 - 记录操作人和更新时间。
6. 错误码与失败场景
| 错误码 | 场景 | 典型报错 |
|---|---|---|
| 1001 | policy 为空 | policy is empty |
| 1001 | scene 非法 | scene must be single or group |
| 1001 | action 非法 | action must be reject or allow |
| - | 数据库写入失败 | 由数据库层返回原始错误 |
7. 示例
fetch 请求示例
javascript
fetch("http://localhost:10011/adminx/sensitive_word/policy/set", {
method: "POST",
headers: {
operationID: "sensitive-policy-set-001",
token: "eyJhbGciOi...",
"Content-Type": "application/json",
},
body: JSON.stringify({
policy: {
scene: "group",
enabled: true,
action: "reject",
},
}),
})
.then((res) => res.json())
.then((data) => console.log(data));请求示例(JSON)
json
{
"policy": {
"scene": "group",
"enabled": true,
"action": "reject"
}
}成功响应示例
json
{
"errCode": 0,
"errMsg": "",
"errDlt": "",
"data": {}
}失败响应示例
json
{
"errCode": 1001,
"errMsg": "ArgsError",
"errDlt": "action must be reject or allow"
}8. 时序流程
- 中间件校验管理员 token。
- 校验
policy、scene、action。 - 对
scene执行 upsert,并记录operator与updateTime。 - 返回统一成功响应。
9. 变更记录
- 2026-07-14: 文档重构为标准 admin API 模板,补齐 Header、响应结构、失败示例与时序流程。