itecdn 5.x用户文档
itecdn 5.x / 用户 API

更新或重置 API Key

PUT/v1/api-key

更新当前登录用户的 API Key 配置;管理员可通过 uid 操作指定用户。请求体支持两种操作:通过 ip 设置最多 10 个 IPv4/IPv6 来源地址,传空字符串或 null 可清除白名单;通过 reset 重新生成 16 位 API Key 和 30 位 API Secret,旧凭证立即失效。目标用户必须已经开通 API Key。ip 与 reset 不应同时提交;若同时存在,服务端只执行 ip 分支而不会重置凭证。

身份认证

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 同时发送。"
  }
}

请求参数

未定义路径、查询或请求头参数。

请求体 · 必填

application/json

oneOf

oneOf · 1 · object

设置或清空 API Key 来源 IP 白名单。

字段类型必填说明与约束
ipstring必填

允许使用该 API Key 的来源 IP 白名单,最多 10 个 IPv4 或 IPv6 地址,多个地址以竖线 | 分隔;空字符串或 null 表示清除限制。

约束 / 默认值 / 示例
{
  "nullable": true
}
uidinteger (int64)可选

要修改 API Key 的用户 ID;省略时为当前登录用户,仅管理员可指定其他用户。

约束 / 默认值 / 示例
{
  "format": "int64",
  "minimum": 1
}
oneOf · 2 · object

重置 API Key 凭证对。

字段类型必填说明与约束
resetboolean必填

传 true 重新生成 API Key 和 API Secret;服务端以字段是否存在触发重置。

约束 / 默认值 / 示例
{
  "enum": [
    true
  ]
}
uidinteger (int64)可选

要重置 API Key 的用户 ID;省略时为当前登录用户,仅管理员可指定其他用户。

约束 / 默认值 / 示例
{
  "format": "int64",
  "minimum": 1
}
完整 Schema
{
  "oneOf": [
    {
      "type": "object",
      "required": [
        "ip"
      ],
      "properties": {
        "ip": {
          "type": "string",
          "nullable": true,
          "description": "允许使用该 API Key 的来源 IP 白名单,最多 10 个 IPv4 或 IPv6 地址,多个地址以竖线 `|` 分隔;空字符串或 null 表示清除限制。"
        },
        "uid": {
          "type": "integer",
          "format": "int64",
          "minimum": 1,
          "description": "要修改 API Key 的用户 ID;省略时为当前登录用户,仅管理员可指定其他用户。"
        }
      },
      "additionalProperties": false,
      "description": "设置或清空 API Key 来源 IP 白名单。"
    },
    {
      "type": "object",
      "required": [
        "reset"
      ],
      "properties": {
        "reset": {
          "type": "boolean",
          "enum": [
            true
          ],
          "description": "传 true 重新生成 API Key 和 API Secret;服务端以字段是否存在触发重置。"
        },
        "uid": {
          "type": "integer",
          "format": "int64",
          "minimum": 1,
          "description": "要重置 API Key 的用户 ID;省略时为当前登录用户,仅管理员可指定其他用户。"
        }
      },
      "additionalProperties": false,
      "description": "重置 API Key 凭证对。"
    }
  ]
}

示例

{
  "ip": "192.0.2.10|2001:db8::10"
}

请求体示例

{
  "ip": "string",
  "uid": 0
}

响应

HTTP 200

业务结果通过 HTTP 200 返回。IP 白名单修改成功时返回空业务数据;凭证重置成功时返回新 API Key 和 API Secret;目标用户未开通、IP 数量或格式不合法、普通用户指定 uid 或认证无效时返回字符串业务错误码。

application/json

oneOf

oneOf · 1 · object
字段类型必填说明与约束
codeinteger必填

成功状态码,来源 IP 白名单修改成功时固定为 0。

约束 / 默认值 / 示例
{
  "enum": [
    0
  ]
}
msgstring必填

来源 IP 白名单写入并提交后返回的确认消息。

约束 / 默认值 / 示例
{
  "enum": [
    "修改成功"
  ]
}
datastring必填

来源 IP 白名单修改成功时没有额外业务数据,固定为 null。

约束 / 默认值 / 示例
{
  "nullable": true,
  "enum": [
    null
  ]
}
oneOf · 2 · object
字段类型必填说明与约束
codeinteger必填

成功状态码,API Key 凭证重置成功时固定为 0。

约束 / 默认值 / 示例
{
  "enum": [
    0
  ]
}
msgstring必填

新凭证写入并使旧凭证失效后返回的确认消息。

约束 / 默认值 / 示例
{
  "enum": [
    "重置成功"
  ]
}
dataobject必填

重置后立即生效的新 API Key 凭证对。

约束 / 默认值 / 示例
{
  "required": [
    "api_key",
    "api_secret"
  ],
  "additionalProperties": false
}
展开字段结构

重置后立即生效的新 API Key 凭证对。

字段类型必填说明与约束
api_keystring必填

重置后新生成的 16 位访问标识。

约束 / 默认值 / 示例
{
  "minLength": 16,
  "maxLength": 16
}
api_secretstring必填

与新 API Key 配对的 30 位明文密钥。

约束 / 默认值 / 示例
{
  "minLength": 30,
  "maxLength": 30
}
oneOf · 3 · object
字段类型必填说明与约束
codestring必填

业务错误码:api-key-2 表示目标用户未开通 API Key,api-key-3 表示某个 IP 地址无效,api-key-5 表示白名单超过 10 个地址,message-27 表示普通用户尝试操作指定用户,login_required 表示认证无效。

约束 / 默认值 / 示例
{
  "enum": [
    "api-key-2",
    "api-key-3",
    "api-key-5",
    "message-27",
    "login_required"
  ]
}
msgstring必填

与业务错误码对应的中文配置、IP、权限或认证失败原因。

datastring必填

业务错误时固定为空字符串。

约束 / 默认值 / 示例
{
  "enum": [
    ""
  ]
}
完整 Schema
{
  "oneOf": [
    {
      "type": "object",
      "required": [
        "code",
        "msg",
        "data"
      ],
      "properties": {
        "code": {
          "type": "integer",
          "enum": [
            0
          ],
          "description": "成功状态码,来源 IP 白名单修改成功时固定为 0。"
        },
        "msg": {
          "type": "string",
          "enum": [
            "修改成功"
          ],
          "description": "来源 IP 白名单写入并提交后返回的确认消息。"
        },
        "data": {
          "type": "string",
          "nullable": true,
          "enum": [
            null
          ],
          "description": "来源 IP 白名单修改成功时没有额外业务数据,固定为 null。"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "code",
        "msg",
        "data"
      ],
      "properties": {
        "code": {
          "type": "integer",
          "enum": [
            0
          ],
          "description": "成功状态码,API Key 凭证重置成功时固定为 0。"
        },
        "msg": {
          "type": "string",
          "enum": [
            "重置成功"
          ],
          "description": "新凭证写入并使旧凭证失效后返回的确认消息。"
        },
        "data": {
          "type": "object",
          "required": [
            "api_key",
            "api_secret"
          ],
          "properties": {
            "api_key": {
              "type": "string",
              "minLength": 16,
              "maxLength": 16,
              "description": "重置后新生成的 16 位访问标识。"
            },
            "api_secret": {
              "type": "string",
              "minLength": 30,
              "maxLength": 30,
              "description": "与新 API Key 配对的 30 位明文密钥。"
            }
          },
          "additionalProperties": false,
          "description": "重置后立即生效的新 API Key 凭证对。"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "code",
        "msg",
        "data"
      ],
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "api-key-2",
            "api-key-3",
            "api-key-5",
            "message-27",
            "login_required"
          ],
          "description": "业务错误码:`api-key-2` 表示目标用户未开通 API Key,`api-key-3` 表示某个 IP 地址无效,`api-key-5` 表示白名单超过 10 个地址,`message-27` 表示普通用户尝试操作指定用户,`login_required` 表示认证无效。"
        },
        "msg": {
          "type": "string",
          "description": "与业务错误码对应的中文配置、IP、权限或认证失败原因。"
        },
        "data": {
          "type": "string",
          "enum": [
            ""
          ],
          "description": "业务错误时固定为空字符串。"
        }
      },
      "additionalProperties": false
    }
  ]
}

示例

{
  "code": 0,
  "msg": "重置成功",
  "data": {
    "api_key": "EXAMPLEAPIKEY001",
    "api_secret": "EXAMPLE_API_SECRET_00000000000"
  }
}

cURL 示例

根据文档生成;请替换主控地址、路径参数和凭证,并按上表补充查询参数。

curl --request PUT \
  "https://master.example.invalid/v1/api-key" \
  --header "access-token: YOUR_ACCESS_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"ip": "string", "uid": 0}'

查看完整接口 JSON