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

获取 API Key 配置

GET/v1/api-key

获取当前登录用户的 API Key 配置;管理员可通过 uid 查询指定用户。接口直接返回数据库中保存的 API Key、API Secret 和来源 IP 白名单,不会对密钥做掩码;调用方不得把响应写入日志、前端持久化存储或转发给无关方。目标用户尚未开通 API Key 时请求仍成功,data 返回 null。

身份认证

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

请求参数

参数位置类型必填说明与约束
uidqueryinteger (int64)可选

要查询 API Key 的用户 ID。省略时查询当前登录用户;仅管理员可指定其他用户,普通用户传入该参数会返回权限错误。

完整参数定义
{
  "name": "uid",
  "in": "query",
  "required": false,
  "description": "要查询 API Key 的用户 ID。省略时查询当前登录用户;仅管理员可指定其他用户,普通用户传入该参数会返回权限错误。",
  "schema": {
    "type": "integer",
    "format": "int64",
    "minimum": 1
  },
  "example": 2
}

响应

HTTP 200

业务结果通过 HTTP 200 返回。查询成功时 data 为完整 API Key 记录;目标用户尚未开通时 data 为 null;普通用户尝试指定 uid 或登录凭证无效时返回字符串业务错误码。

application/json

oneOf

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

查询完成时的成功状态码,固定为 0,包括用户尚未开通 API Key 的情况。

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

API Key 查询完成时返回的确认消息。

约束 / 默认值 / 示例
{
  "enum": [
    "获取成功"
  ]
}
dataoneOf必填

目标用户的完整 API Key 配置;尚未开通 API Key 时为 null。

展开字段结构

目标用户的完整 API Key 配置;尚未开通 API Key 时为 null。

oneOf · 1 · object
字段类型必填说明与约束
idinteger (int64)必填

API Key 配置记录的唯一 ID。

约束 / 默认值 / 示例
{
  "format": "int64"
}
uidinteger (int64)必填

该 API Key 所属用户的 ID。

约束 / 默认值 / 示例
{
  "format": "int64"
}
api_keystring必填

调用 API 时通过 api-key 请求头提交的 16 位访问标识。

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

与 API Key 配对、通过 api-secret 请求头提交的 30 位明文密钥。

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

允许使用该密钥的来源 IP 白名单,多个地址以竖线 | 分隔;null 或空字符串表示不限制来源 IP。

约束 / 默认值 / 示例
{
  "nullable": true
}
oneOf · 2 · string
oneOf · 2 · object
字段类型必填说明与约束
codestring必填

业务错误码:task-5 表示普通用户尝试查询指定用户的 API Key,login_required 表示登录态或 API Key 认证无效。

约束 / 默认值 / 示例
{
  "enum": [
    "task-5",
    "login_required"
  ]
}
msgstring必填

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

datastring必填

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

约束 / 默认值 / 示例
{
  "enum": [
    ""
  ]
}
完整 Schema
{
  "oneOf": [
    {
      "type": "object",
      "required": [
        "code",
        "msg",
        "data"
      ],
      "properties": {
        "code": {
          "type": "integer",
          "enum": [
            0
          ],
          "description": "查询完成时的成功状态码,固定为 0,包括用户尚未开通 API Key 的情况。"
        },
        "msg": {
          "type": "string",
          "enum": [
            "获取成功"
          ],
          "description": "API Key 查询完成时返回的确认消息。"
        },
        "data": {
          "description": "目标用户的完整 API Key 配置;尚未开通 API Key 时为 null。",
          "oneOf": [
            {
              "type": "object",
              "required": [
                "id",
                "uid",
                "api_key",
                "api_secret",
                "api_ip"
              ],
              "properties": {
                "id": {
                  "type": "integer",
                  "format": "int64",
                  "description": "API Key 配置记录的唯一 ID。"
                },
                "uid": {
                  "type": "integer",
                  "format": "int64",
                  "description": "该 API Key 所属用户的 ID。"
                },
                "api_key": {
                  "type": "string",
                  "minLength": 16,
                  "maxLength": 16,
                  "description": "调用 API 时通过 `api-key` 请求头提交的 16 位访问标识。"
                },
                "api_secret": {
                  "type": "string",
                  "minLength": 30,
                  "maxLength": 30,
                  "description": "与 API Key 配对、通过 `api-secret` 请求头提交的 30 位明文密钥。"
                },
                "api_ip": {
                  "type": "string",
                  "nullable": true,
                  "description": "允许使用该密钥的来源 IP 白名单,多个地址以竖线 `|` 分隔;null 或空字符串表示不限制来源 IP。"
                }
              },
              "additionalProperties": false
            },
            {
              "type": "string",
              "nullable": true,
              "enum": [
                null
              ]
            }
          ]
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "code",
        "msg",
        "data"
      ],
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "task-5",
            "login_required"
          ],
          "description": "业务错误码:`task-5` 表示普通用户尝试查询指定用户的 API Key,`login_required` 表示登录态或 API Key 认证无效。"
        },
        "msg": {
          "type": "string",
          "description": "与业务错误码对应的中文权限或认证失败原因。"
        },
        "data": {
          "type": "string",
          "enum": [
            ""
          ],
          "description": "业务错误时固定为空字符串。"
        }
      },
      "additionalProperties": false
    }
  ]
}

示例

{
  "code": 0,
  "msg": "获取成功",
  "data": {
    "id": 1,
    "uid": 2,
    "api_key": "EXAMPLEAPIKEY001",
    "api_secret": "EXAMPLE_API_SECRET_00000000000",
    "api_ip": "192.0.2.10|198.51.100.20"
  }
}

cURL 示例

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

curl --request GET \
  "https://master.example.invalid/v1/api-key" \
  --header "access-token: YOUR_ACCESS_TOKEN"

查看完整接口 JSON