Skip to content

设置违禁词策略

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 参数

字段必填类型说明
operationIDstring链路追踪 ID
tokenstring管理员 token

Body 参数

字段必填类型说明
policyobject策略

policy 字段:

字段必填类型说明
scenestring场景:singlegroup
enabledbool是否启用该场景策略
actionstring动作:rejectallow,默认 reject

字段约束

  • 协议校验要求 policy 非空。
  • scene 仅允许 single/group
  • action 为空时默认按 reject 处理。
  • action 仅允许 reject/allow

4. 响应结构

通用响应包裹

字段类型说明
errCodeint错误码,0 表示成功
errMsgstring错误简述
errDltstring错误详情
dataobject业务数据

data 字段

  • 本接口成功时返回空对象(无业务字段)。

5. 业务规则

  • 策略按 scene upsert。
  • 记录操作人和更新时间。

6. 错误码与失败场景

错误码场景典型报错
1001policy 为空policy is empty
1001scene 非法scene must be single or group
1001action 非法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. 时序流程

  1. 中间件校验管理员 token。
  2. 校验 policysceneaction
  3. scene 执行 upsert,并记录 operatorupdateTime
  4. 返回统一成功响应。

9. 变更记录

  • 2026-07-14: 文档重构为标准 admin API 模板,补齐 Header、响应结构、失败示例与时序流程。