Skip to content

连接器管理 API

连接器管理接口用于配置和管理社交登录、邮件和短信等认证通道。连接器使平台能够集成第三方身份提供商和消息服务。

所有接口均需要管理员令牌认证:Authorization: Bearer <admin_token>

连接器类型

类型说明
EmailEmail邮件连接器,用于发送验证码邮件
SmsSms短信连接器,用于发送验证码短信
SocialSocial社交登录连接器,如微信、GitHub、Google 等

获取连接器列表

GET /api/v1/connectors

获取所有已配置的连接器列表。

查询参数:

参数类型必填默认值说明
pageinteger1页码
page_sizeinteger20每页条数

请求示例:

bash
curl -X GET "https://your-domain/api/v1/connectors?page=1&page_size=10" \
  -H "Authorization: Bearer <admin_token>"

成功响应:

json
{
  "code": 0,
  "message": "success",
  "result": {
    "data": [
      {
        "id": "conn_001",
        "connector_id": "aliyun-dm",
        "type": "Email",
        "enabled": true,
        "config": {
          "access_key_id": "LTAI5t***",
          "access_key_secret": "***",
          "account_name": "noreply@example.com",
          "region": "cn-hangzhou"
        },
        "created_at": "2025-01-01T00:00:00Z",
        "updated_at": "2025-01-01T00:00:00Z"
      },
      {
        "id": "conn_002",
        "connector_id": "github",
        "type": "Social",
        "enabled": true,
        "config": {
          "client_id": "Iv1.abc***",
          "client_secret": "***"
        },
        "created_at": "2025-02-01T00:00:00Z",
        "updated_at": "2025-02-01T00:00:00Z"
      }
    ],
    "total": 3,
    "page": 1,
    "page_size": 10
  }
}

创建连接器

POST /api/v1/connectors

创建一个新的连接器实例。

请求体:

字段类型必填说明
connector_idstring连接器标识(如 aliyun-dmaliyun-smsgithubwechat
typestring连接器类型:EmailSmsSocial
configobject连接器配置(JSON 对象,结构因连接器而异)
enabledboolean是否启用,默认 false

请求示例(邮件连接器):

bash
curl -X POST https://your-domain/api/v1/connectors \
  -H "Authorization: Bearer <admin_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "connector_id": "aliyun-dm",
    "type": "Email",
    "config": {
      "access_key_id": "LTAI5tExample",
      "access_key_secret": "your-secret-key",
      "account_name": "noreply@example.com",
      "region": "cn-hangzhou"
    },
    "enabled": true
  }'

请求示例(社交登录连接器):

bash
curl -X POST https://your-domain/api/v1/connectors \
  -H "Authorization: Bearer <admin_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "connector_id": "github",
    "type": "Social",
    "config": {
      "client_id": "Iv1.abcdef123456",
      "client_secret": "your-github-client-secret"
    },
    "enabled": true
  }'

成功响应:

json
{
  "code": 0,
  "message": "success",
  "result": {
    "id": "conn_003",
    "connector_id": "github",
    "type": "Social",
    "enabled": true,
    "config": {
      "client_id": "Iv1.abcdef123456",
      "client_secret": "***"
    },
    "created_at": "2025-06-15T08:00:00Z",
    "updated_at": "2025-06-15T08:00:00Z"
  }
}

获取连接器详情

GET /api/v1/connectors/:id

根据连接器 ID 获取连接器详细信息。

路径参数:

参数类型说明
idstring连接器 ID

请求示例:

bash
curl -X GET https://your-domain/api/v1/connectors/conn_003 \
  -H "Authorization: Bearer <admin_token>"

成功响应:

json
{
  "code": 0,
  "message": "success",
  "result": {
    "id": "conn_003",
    "connector_id": "github",
    "type": "Social",
    "enabled": true,
    "config": {
      "client_id": "Iv1.abcdef123456",
      "client_secret": "***"
    },
    "created_at": "2025-06-15T08:00:00Z",
    "updated_at": "2025-06-15T08:00:00Z"
  }
}

更新连接器

PATCH /api/v1/connectors/:id

更新连接器配置。仅传入需要修改的字段。

路径参数:

参数类型说明
idstring连接器 ID

请求体:

字段类型必填说明
configobject连接器配置(全量替换)
enabledboolean是否启用

请求示例:

bash
curl -X PATCH https://your-domain/api/v1/connectors/conn_003 \
  -H "Authorization: Bearer <admin_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": false
  }'

成功响应:

json
{
  "code": 0,
  "message": "success",
  "result": {
    "id": "conn_003",
    "connector_id": "github",
    "type": "Social",
    "enabled": false,
    "config": {
      "client_id": "Iv1.abcdef123456",
      "client_secret": "***"
    },
    "created_at": "2025-06-15T08:00:00Z",
    "updated_at": "2025-06-15T14:00:00Z"
  }
}

删除连接器

DELETE /api/v1/connectors/:id

删除指定连接器。

路径参数:

参数类型说明
idstring连接器 ID

请求示例:

bash
curl -X DELETE https://your-domain/api/v1/connectors/conn_003 \
  -H "Authorization: Bearer <admin_token>"

成功响应:

json
{
  "code": 0,
  "message": "success",
  "result": null
}

测试连接器

POST /api/v1/connectors/:id/test

发送测试消息以验证连接器配置是否正确。

  • 对于 Email 类型连接器,会发送一封测试邮件。
  • 对于 Sms 类型连接器,会发送一条测试短信。
  • 对于 Social 类型连接器,会验证 OAuth 配置的有效性。

路径参数:

参数类型说明
idstring连接器 ID

请求示例:

bash
curl -X POST https://your-domain/api/v1/connectors/conn_001/test \
  -H "Authorization: Bearer <admin_token>"

成功响应:

json
{
  "code": 0,
  "message": "success",
  "result": {
    "result": "ok",
    "message": "测试消息发送成功"
  }
}

错误响应(配置有误):

json
{
  "code": 400,
  "message": "连接器测试失败",
  "result": "InvalidAccessKeyId: The AccessKeyId is invalid"
}

Released under the MIT License.