Skip to content

新增违禁词词条

1. 接口定位

  • 接口名称: 新增违禁词词条
  • 所属域: admin/sensitive-word
  • 业务目标: 批量新增违禁词词条,用于消息发送前拦截

2. 请求定义

  • Method: POST
  • Path: /adminx/sensitive_word/add
  • Content-Type: 推荐 application/json
  • operationID: 必填,请通过 Header operationID 传入
  • 鉴权: 需要 Header token,且必须是管理员 token
  • 幂等性: 非幂等;重复词条依赖数据库唯一索引控制

3. 请求参数

Body 参数

字段必填类型说明
wordsarray<object>词条列表

Header 参数

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

words 元素字段

字段必填类型说明
wordstring词条文本
categorystring分类
severityint32严重级别
enabledbool是否启用该词条

字段约束

  • 协议校验要求 words 非空。
  • 元素为 nullword 为空时会被忽略。
  • 同一次请求内会按规范化词条去重(大小写和首尾空白不敏感)。

4. 响应结构

通用响应包裹

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

data 字段

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

5. 业务规则

  • 同一请求内,词条按规范化后去重(大小写和首尾空白不敏感)。
  • 词条会写入创建人、创建时间和更新时间。
  • word 为空的元素会被忽略。
  • 新增后默认按请求中的 enabled 生效,不做额外覆盖。

6. 错误码与失败场景

错误码场景典型报错
1001words 为空words is empty
1001全部元素都无有效词条no valid words
-唯一索引冲突由数据库层返回错误
-批量写库失败由数据库层返回错误

7. 示例

fetch 请求示例

javascript
fetch("http://localhost:10011/adminx/sensitive_word/add", {
  method: "POST",
  headers: {
    operationID: "sensitive-word-add-001",
    token: "eyJhbGciOi...",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    words: [
      { word: "spam", category: "ad", severity: 2, enabled: true },
      { word: "fraud", category: "risk", severity: 3, enabled: true },
    ],
  }),
})
  .then((res) => res.json())
  .then((data) => console.log(data));

请求示例(JSON)

json
{
  "words": [
    { "word": "spam", "category": "ad", "severity": 2, "enabled": true },
    { "word": "fraud", "category": "risk", "severity": 3, "enabled": true }
  ]
}

成功响应示例

json
{
  "errCode": 0,
  "errMsg": "",
  "errDlt": "",
  "data": {}
}

失败响应示例

json
{
  "errCode": 1001,
  "errMsg": "ArgsError",
  "errDlt": "no valid words"
}

8. 时序流程

  1. 中间件校验管理员 token。
  2. 校验 words 非空。
  3. 对词条做 trim 和同请求去重。
  4. 补充 creatorcreateTimeupdateTime 后批量写库。
  5. 返回统一成功响应。

9. 变更记录

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