获取 API Key 配置
/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 同时发送。"
}
}请求参数
| 参数 | 位置 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|---|
uid | query | integer (int64) | 可选 | 要查询 API Key 的用户 ID。省略时查询当前登录用户;仅管理员可指定其他用户,普通用户传入该参数会返回权限错误。 完整参数定义 |
响应
HTTP 200
业务结果通过 HTTP 200 返回。查询成功时 data 为完整 API Key 记录;目标用户尚未开通时 data 为 null;普通用户尝试指定 uid 或登录凭证无效时返回字符串业务错误码。
application/json
oneOf
oneOf · 1 · object
| 字段 | 类型 | 必填 | 说明与约束 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
code | integer | 必填 | 查询完成时的成功状态码,固定为 0,包括用户尚未开通 API Key 的情况。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||
msg | string | 必填 | API Key 查询完成时返回的确认消息。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||
data | oneOf | 必填 | 目标用户的完整 API Key 配置;尚未开通 API Key 时为 null。 展开字段结构目标用户的完整 API Key 配置;尚未开通 API Key 时为 null。 oneOf · 1 · object
oneOf · 2 · string |
oneOf · 2 · object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
code | string | 必填 | 业务错误码: 约束 / 默认值 / 示例 |
msg | string | 必填 | 与业务错误码对应的中文权限或认证失败原因。 |
data | string | 必填 | 业务错误时固定为空字符串。 约束 / 默认值 / 示例 |
完整 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"