创建 CC 过滤器
/v1/cc-filters为当前登录用户创建一个 CC 过滤器,创建前会按照当前账号的网站数量和系统配置检查可创建的站点关联对象配额;同一所属用户下过滤器名称不可重复。普通用户只能创建归属于自己的自定义过滤器,管理员可通过请求体指定所属用户或创建系统内置过滤器。req_rate 类型必须配置单 URI 请求上限,url_auth 类型必须配置 URL 鉴权参数;其他类型的扩展配置会以空对象保存。新增过滤器固定以启用状态和版本 1 写入。
身份认证
access-token
api-key + api-secret
认证定义
{
"AccessToken": {
"type": "apiKey",
"in": "header",
"name": "access-token",
"description": "通过登录接口获得的短期访问令牌。"
},
"ApiKey": {
"type": "apiKey",
"in": "header",
"name": "api-key",
"description": "API Key;必须和 api-secret 同时发送。"
},
"ApiSecret": {
"type": "apiKey",
"in": "header",
"name": "api-secret",
"description": "API Secret;必须和 api-key 同时发送。"
}
}请求参数
| 参数 | 位置 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|---|
internal | query | integer | 可选 | 兼容性权限检查参数。传 1 时要求管理员身份,否则返回 完整参数定义 |
请求体 · 必填
application/json
object
创建 CC 过滤器的 JSON 对象;未识别字段不会参与创建逻辑。
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
name | string | 必填 | 过滤器名称;服务端会过滤可执行的 HTML 内容,且要求处理后的名称非空、在所属用户下唯一。 约束 / 默认值 / 示例 |
des | string | 可选 | 过滤器备注;服务端会过滤可执行的 HTML 内容,省略时保存为空字符串。 约束 / 默认值 / 示例 |
type | string | 必填 | 过滤器实现类型,决定达到请求阈值后采用限速、验证、跳转、轮转或 URL 鉴权行为。 约束 / 默认值 / 示例 |
within_second | oneOf | 必填 | 请求统计窗口的秒数;接受非负整数或仅含十进制数字的字符串,不能为空。 展开字段结构请求统计窗口的秒数;接受非负整数或仅含十进制数字的字符串,不能为空。 oneOf · 1 · integeroneOf · 2 · string |
max_req | oneOf | 必填 | 在 展开字段结构在 oneOf · 1 · integeroneOf · 2 · string |
max_req_per_uri | oneOf | 可选 | 同一 URI 在统计窗口内允许的最大请求数; 展开字段结构同一 URI 在统计窗口内允许的最大请求数; oneOf · 1 · integeroneOf · 2 · string |
extra | object | 可选 | 过滤器扩展配置。仅 约束 / 默认值 / 示例 |
uid | integer (int64) | 可选 | 新过滤器所属用户的 ID;省略时为当前登录用户,仅管理员可指定该字段,否则返回 约束 / 默认值 / 示例 |
internal | integer | 可选 | 是否创建为系统内置过滤器:1 表示内置,0 表示用户自定义;省略时为 0,传 1 要求管理员身份,否则返回 约束 / 默认值 / 示例 |
enable | integer | 可选 | 兼容性输入字段,只接受 0 或 1;新增记录最终固定以启用状态 1 保存,即使这里传 0 也不会创建禁用记录。 约束 / 默认值 / 示例 |
oneOf · 1 · object
req_rate 过滤器的条件字段。
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
type | string | 可选 | 请求频率限制类型,要求同时提供单 URI 请求上限。 约束 / 默认值 / 示例 |
oneOf · 2 · object
url_auth 过滤器的条件字段。
| 字段 | 类型 | 必填 | 说明与约束 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type | string | 可选 | URL 鉴权类型,要求同时提供符合所选模式的扩展配置。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
extra | oneOf | 必填 | 根据 展开字段结构根据 oneOf · 1 · objectTypeA URL 鉴权扩展配置;未识别的附加键会一并序列化保存。
oneOf · 2 · objectTypeB URL 鉴权扩展配置;未识别的附加键会一并序列化保存。
|
oneOf · 3 · object
除请求频率限制和 URL 鉴权之外的过滤器类型。
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
type | string | 可选 | 无需额外条件字段的验证、跳转或轮转过滤器类型。 约束 / 默认值 / 示例 |
完整 Schema
{
"type": "object",
"required": [
"name",
"type",
"within_second",
"max_req"
],
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 255,
"description": "过滤器名称;服务端会过滤可执行的 HTML 内容,且要求处理后的名称非空、在所属用户下唯一。"
},
"des": {
"type": "string",
"maxLength": 255,
"default": "",
"description": "过滤器备注;服务端会过滤可执行的 HTML 内容,省略时保存为空字符串。"
},
"type": {
"type": "string",
"enum": [
"easy_click_filter",
"easy_slide_filter",
"req_rate",
"302_challenge",
"browser_verify_auto",
"slide_filter",
"captcha_filter",
"click_filter",
"url_auth",
"delay_jump_filter",
"rotate_filter"
],
"description": "过滤器实现类型,决定达到请求阈值后采用限速、验证、跳转、轮转或 URL 鉴权行为。"
},
"within_second": {
"oneOf": [
{
"type": "integer",
"minimum": 0
},
{
"type": "string",
"pattern": "^[0-9]+$"
}
],
"description": "请求统计窗口的秒数;接受非负整数或仅含十进制数字的字符串,不能为空。"
},
"max_req": {
"oneOf": [
{
"type": "integer",
"minimum": 0
},
{
"type": "string",
"pattern": "^[0-9]+$"
}
],
"description": "在 `within_second` 统计窗口内允许的最大请求数;接受非负整数或仅含十进制数字的字符串,不能为空。"
},
"max_req_per_uri": {
"oneOf": [
{
"type": "integer",
"minimum": 0
},
{
"type": "string",
"pattern": "^[0-9]+$"
}
],
"description": "同一 URI 在统计窗口内允许的最大请求数;`type=req_rate` 时必填且必须是非负整数或十进制数字字符串,其他类型省略或传空值时保存为 0。"
},
"extra": {
"type": "object",
"additionalProperties": true,
"description": "过滤器扩展配置。仅 `url_auth` 类型会保存该对象并要求完整的 URL 鉴权字段;其他类型会忽略传入内容并保存为空对象。"
},
"uid": {
"type": "integer",
"format": "int64",
"minimum": 1,
"description": "新过滤器所属用户的 ID;省略时为当前登录用户,仅管理员可指定该字段,否则返回 `cc_filter-56`。"
},
"internal": {
"type": "integer",
"enum": [
0,
1
],
"default": 0,
"description": "是否创建为系统内置过滤器:1 表示内置,0 表示用户自定义;省略时为 0,传 1 要求管理员身份,否则返回 `cc_filter-57`。"
},
"enable": {
"type": "integer",
"enum": [
0,
1
],
"default": 1,
"description": "兼容性输入字段,只接受 0 或 1;新增记录最终固定以启用状态 1 保存,即使这里传 0 也不会创建禁用记录。"
}
},
"oneOf": [
{
"required": [
"max_req_per_uri"
],
"properties": {
"type": {
"type": "string",
"enum": [
"req_rate"
],
"description": "请求频率限制类型,要求同时提供单 URI 请求上限。"
}
},
"description": "`req_rate` 过滤器的条件字段。"
},
{
"required": [
"extra"
],
"properties": {
"type": {
"type": "string",
"enum": [
"url_auth"
],
"description": "URL 鉴权类型,要求同时提供符合所选模式的扩展配置。"
},
"extra": {
"oneOf": [
{
"type": "object",
"required": [
"mode",
"key",
"sign_name",
"time_name",
"time_diff",
"sign_use_times"
],
"properties": {
"mode": {
"type": "string",
"enum": [
"TypeA"
],
"description": "URL 鉴权模式;TypeA 从独立的时间戳查询参数读取签名时间。"
},
"key": {
"type": "string",
"minLength": 16,
"maxLength": 32,
"description": "计算 URL 签名使用的密钥,长度必须为 16 至 32 个字符。"
},
"sign_name": {
"type": "string",
"minLength": 1,
"description": "请求 URL 中承载签名值的查询参数名,不能为空。"
},
"time_name": {
"type": "string",
"minLength": 1,
"description": "TypeA 模式下承载签名时间戳的查询参数名,不能为空。"
},
"time_diff": {
"oneOf": [
{
"type": "integer",
"minimum": 0,
"maximum": 3600
},
{
"type": "string",
"pattern": "^[0-9]+$"
}
],
"description": "签名时间与服务端时间允许的最大秒数差,必须为不超过 3600 的非负整数。"
},
"sign_use_times": {
"oneOf": [
{
"type": "integer",
"minimum": 0
},
{
"type": "string",
"pattern": "^[0-9]+$"
}
],
"description": "同一签名允许使用的次数,必须为非负整数或仅含十进制数字的字符串。"
}
},
"additionalProperties": true,
"description": "TypeA URL 鉴权扩展配置;未识别的附加键会一并序列化保存。"
},
{
"type": "object",
"required": [
"mode",
"key",
"sign_name",
"time_diff",
"sign_use_times"
],
"properties": {
"mode": {
"type": "string",
"enum": [
"TypeB"
],
"description": "URL 鉴权模式;TypeB 不要求独立的时间戳参数名。"
},
"key": {
"type": "string",
"minLength": 16,
"maxLength": 32,
"description": "计算 URL 签名使用的密钥,长度必须为 16 至 32 个字符。"
},
"sign_name": {
"type": "string",
"minLength": 1,
"description": "请求 URL 中承载签名值的查询参数名,不能为空。"
},
"time_diff": {
"oneOf": [
{
"type": "integer",
"minimum": 0,
"maximum": 3600
},
{
"type": "string",
"pattern": "^[0-9]+$"
}
],
"description": "签名时间与服务端时间允许的最大秒数差,必须为不超过 3600 的非负整数。"
},
"sign_use_times": {
"oneOf": [
{
"type": "integer",
"minimum": 0
},
{
"type": "string",
"pattern": "^[0-9]+$"
}
],
"description": "同一签名允许使用的次数,必须为非负整数或仅含十进制数字的字符串。"
}
},
"additionalProperties": true,
"description": "TypeB URL 鉴权扩展配置;未识别的附加键会一并序列化保存。"
}
],
"description": "根据 `mode` 选择 TypeA 或 TypeB 的 URL 鉴权配置。"
}
},
"description": "`url_auth` 过滤器的条件字段。"
},
{
"properties": {
"type": {
"type": "string",
"enum": [
"easy_click_filter",
"easy_slide_filter",
"302_challenge",
"browser_verify_auto",
"slide_filter",
"captcha_filter",
"click_filter",
"delay_jump_filter",
"rotate_filter"
],
"description": "无需额外条件字段的验证、跳转或轮转过滤器类型。"
}
},
"description": "除请求频率限制和 URL 鉴权之外的过滤器类型。"
}
],
"additionalProperties": true,
"description": "创建 CC 过滤器的 JSON 对象;未识别字段不会参与创建逻辑。"
}示例
{
"name": "请求频率限制",
"des": "限制短时间内对同一 URI 的重复请求",
"type": "req_rate",
"within_second": 60,
"max_req": 100,
"max_req_per_uri": 20
}请求体示例
{
"name": "string",
"des": "",
"type": "req_rate",
"within_second": 0,
"max_req": 0,
"max_req_per_uri": 0,
"extra": {},
"uid": 0,
"internal": 0,
"enable": 1
}响应
HTTP 200
业务结果通过 HTTP 200 返回。创建成功时返回新过滤器 ID;配额不足、名称或阈值不合法、类型条件字段缺失、URL 鉴权配置错误、管理员专属字段越权、系统维护或认证失效时返回字符串业务错误码,数据库事务会回滚。
application/json
oneOf
oneOf · 1 · object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
code | integer | 必填 | 成功状态码,过滤器创建并提交事务后固定为 0。 约束 / 默认值 / 示例 |
msg | string | 必填 | 过滤器记录创建成功后返回的确认消息。 约束 / 默认值 / 示例 |
data | integer (int64) | 必填 | 数据库为新 CC 过滤器生成的唯一 ID。 约束 / 默认值 / 示例 |
oneOf · 2 · object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
code | string | 必填 | 业务错误码:10 表示创建数量超过站点关联对象配额;11、13、14 表示名称为空、重复或缺失;16 至 18 表示类型为空、无效或缺失;19 至 27 表示统计窗口、总请求上限或单 URI 上限为空、格式错误或缺失;28、29 表示 enable 为空或超出 0/1;36 至 50 表示 URL 鉴权扩展配置缺失或无效,其中 49 表示 internal 超出 0/1;55 至 57 表示普通用户使用管理员专属参数; 约束 / 默认值 / 示例 |
msg | string | 必填 | 与业务错误码对应的中文配额、字段校验、URL 鉴权、权限、维护状态或认证失败原因。 |
data | string | 必填 | 业务错误时固定为空字符串。 约束 / 默认值 / 示例 |
完整 Schema
{
"oneOf": [
{
"type": "object",
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"type": "integer",
"enum": [
0
],
"description": "成功状态码,过滤器创建并提交事务后固定为 0。"
},
"msg": {
"type": "string",
"enum": [
"过滤器添加成功"
],
"description": "过滤器记录创建成功后返回的确认消息。"
},
"data": {
"type": "integer",
"format": "int64",
"minimum": 1,
"description": "数据库为新 CC 过滤器生成的唯一 ID。"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"type": "string",
"enum": [
"cc_filter-10",
"cc_filter-11",
"cc_filter-13",
"cc_filter-14",
"cc_filter-16",
"cc_filter-17",
"cc_filter-18",
"cc_filter-19",
"cc_filter-20",
"cc_filter-21",
"cc_filter-22",
"cc_filter-23",
"cc_filter-24",
"cc_filter-25",
"cc_filter-26",
"cc_filter-27",
"cc_filter-28",
"cc_filter-29",
"cc_filter-36",
"cc_filter-37",
"cc_filter-38",
"cc_filter-39",
"cc_filter-40",
"cc_filter-41",
"cc_filter-42",
"cc_filter-43",
"cc_filter-44",
"cc_filter-45",
"cc_filter-46",
"cc_filter-47",
"cc_filter-48",
"cc_filter-49",
"cc_filter-50",
"cc_filter-55",
"cc_filter-56",
"cc_filter-57",
"maintain",
"login_required"
],
"description": "业务错误码:10 表示创建数量超过站点关联对象配额;11、13、14 表示名称为空、重复或缺失;16 至 18 表示类型为空、无效或缺失;19 至 27 表示统计窗口、总请求上限或单 URI 上限为空、格式错误或缺失;28、29 表示 enable 为空或超出 0/1;36 至 50 表示 URL 鉴权扩展配置缺失或无效,其中 49 表示 internal 超出 0/1;55 至 57 表示普通用户使用管理员专属参数;`maintain` 表示当前禁止写操作,`login_required` 表示认证无效。"
},
"msg": {
"type": "string",
"description": "与业务错误码对应的中文配额、字段校验、URL 鉴权、权限、维护状态或认证失败原因。"
},
"data": {
"type": "string",
"enum": [
""
],
"description": "业务错误时固定为空字符串。"
}
},
"additionalProperties": false
}
]
}示例
{
"code": 0,
"msg": "过滤器添加成功",
"data": 10021
}cURL 示例
根据文档生成;请替换主控地址、路径参数和凭证,并按上表补充查询参数。
curl --request POST \
"https://master.example.invalid/v1/cc-filters" \
--header "access-token: YOUR_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{"name": "string", "des": "", "type": "req_rate", "within_second": 0, "max_req": 0, "max_req_per_uri": 0, "extra": {}, "uid": 0, "internal": 0, "enable": 1}'