> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cbpayapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 用于 KYC/KYB 链接的自定义域名

> 使用企业自己的域名提供 KYC 和 KYB 验证链接，并自动完成 DNS 与 TLS 验证

两个环境的 API 完全一致——先在 test 环境构建，再通过切换基础 URL 和密钥上线。 [环境与测试 →](https://docs.cbpayapp.com/zh/environment-testing.md)

## 功能说明

活跃的企业账户可以为托管的 KYC/KYB 链接配置一个已验证的子域名。自定义域名只替换链接的主机名；创建邀请时，品牌和产品样式会随邀请冻结。这样可以发送类似 `https://verify.acme.example/...` 的链接，而不需要迁移验证流程。

企业 owner 可以在门户 **Settings → Styles → Custom domain**（`/settings/styles`）中自助管理，也可以通过 API 管理。

> [!NOTE]
>
> 请使用你控制的子域名，例如 `verify.acme.example`。不支持 apex 域名，因为验证要求使用 CNAME，而大多数 DNS 服务商不允许在 apex 上配置 CNAME。也不支持 IP 地址、私有主机名或 CBPay 自有后缀下的域名。

## 生命周期

```mermaid theme={"theme":{"light":"github-light","dark":"github-dark"}}
stateDiagram-v2
    [*] --> pending: POST /v1/account/verify-domains
    pending --> active: TXT + DNS-only CNAME 通过
    active --> active: TLS probe 成功
    active --> suspended: DNS 检查失败
    suspended --> active: TXT + CNAME 再次通过
    active --> [*]: DELETE domain
    suspended --> [*]: DELETE domain
```

| 状态 | `tls_status` | 含义 | 操作 |
| - | - | - | - |
| `pending` | `pending` | 域名已登记，但 DNS 尚未通过。 | 添加两个记录并调用 `verify`。 |
| `active` | `pending` | TXT 和 CNAME 已通过，证书正在签发。 | 等待 TLS agent，然后再次使用 `GET` 查询。 |
| `active` | `active` | DNS 和 HTTPS 已准备好。 | 新的 KYC/KYB 链接使用自定义主机。 |
| `suspended` | `pending` | DNS 发生确定性失败。 | 修正 DNS 后再次调用 `verify`；暂停期间链接使用规范主机。 |
| `active` | `failed` | TLS 无法签发或提供服务。 | 系统会自动重试签发；修正 TLS/DNS 后再次调用 `verify`。 |

## 配置 DNS

**1. 登记子域名**

使用企业 owner 的凭证：

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST https://api.qbank.cl/platform/v1/account/verify-domains \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"domain":"verify.acme.example"}'
```

`201` 响应包含准确的 target 和 TXT token：

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "vd_3f2b1a09",
  "domain": "verify.acme.example",
  "status": "pending",
  "tls_status": "pending",
  "instructions": {
    "cname_target": "custom-verify.cbpayapp.com",
    "cname_host": "verify.acme.example",
    "txt_host": "_cbpay-verify.verify.acme.example",
    "txt_value": "a1b2c3d4e5f60718293a4b5c6d7e8f90",
    "note": "Point the CNAME (DNS-only, no proxy) and publish the TXT, then call verify. Propagation may take a few minutes."
  },
  "hint": "add the DNS records, wait for propagation, then call verify"
}
```

**2. 发布两个 DNS 记录**

创建以下记录：

| 类型 | 名称 | Target/值 | 注意 |
| - | - | - | - |
| CNAME | `verify.acme.example` | 返回的 `cname_target` | 必须 DNS-only，不要代理。 |
| TXT | `_cbpay-verify.verify.acme.example` | 返回的 `txt_value` | 保留完整 token。 |

某些 DNS 服务商会隐藏 zone 后缀。验证前请确认最终的完整域名。

**3. 验证所有权和路由**

调用验证 endpoint：

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST https://api.qbank.cl/platform/v1/account/verify-domains/vd_3f2b1a09/verify \
  -H "Authorization: Bearer <token>"
```

DNS 可访问时始终返回 `200`，并分别给出 TXT 和 CNAME 的结果：

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "vd_3f2b1a09",
  "domain": "verify.acme.example",
  "status": "active",
  "tls_status": "pending",
  "checks": {
    "txt": {"ok": true, "detail": "token found"},
    "cname": {"ok": true, "detail": "points to origin"}
  },
  "hint": "domain verified; TLS is being provisioned"
}
```

**4. 等待 HTTPS 并确认**

TLS 会自动配置。只有真实 HTTPS probe 成功后，`tls_status` 才会变为 `active`：

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl https://api.qbank.cl/platform/v1/account/verify-domains \
  -H "Authorization: Bearer <token>"
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "domains": [{
    "id": "vd_3f2b1a09",
    "domain": "verify.acme.example",
    "status": "active",
    "tls_status": "active",
    "verified_at": "2026-12-02T14:00:00Z",
    "tls_active_at": "2026-12-02T14:06:00Z"
  }]
}
```

## 链接行为

* 只有 `status` 和 `tls_status` 都为 `active` 时，新链接才使用自定义主机。
* 邀请包含创建链接时的品牌和产品样式快照。
* 已发送的链接保留创建时的主机，不会追溯修改。
* 域名处于 pending、suspended、已删除、重新验证过期或 TLS 未激活时，链接回退到规范主机。
* DNS 检查失败或结果不明确时不会启用自定义主机。`503 dns_check_failed` 不改变已保存状态。
* v1 的 `resend-link` 仍发送规范主机。要使用自定义主机，请在域名 active 后重新创建相应的 KYC/KYB 链接。

## 限制和权限

v1 每个企业账户只支持**一个域名**。替换前必须先删除当前域名。已被其他账户占用的域名返回 `409 domain_claimed`，不会泄露对方账户。

只有活跃企业账户可以使用此功能。owner 可以创建、验证和删除域名；其他成员角色收到 `403 owner_required`。个人账户和被封禁账户会被拒绝。

## 删除或替换域名

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X DELETE https://api.qbank.cl/platform/v1/account/verify-domains/vd_3f2b1a09 \
  -H "Authorization: Bearer <token>"
```

响应为 `204 No Content`。链接立即回退到规范主机，TLS virtual host 会在下一次 agent 运行时删除。

## 错误

| HTTP | 代码 | 解决方法 |
| -: | - | - |
| 400 | `invalid_domain` | 使用至少两个 label 的公共 hostname；不要使用 IP、私有 hostname 或 underscore。请使用子域名，因为验证要求 CNAME，而 apex 上通常不支持 CNAME。 |
| 400 | `domain_not_allowed` | 移除 CBPay 自有后缀，或申请明确 allowlisted 的测试 hostname。 |
| 401 | `unauthorized` | 刷新凭证并以 Bearer 发送。 |
| 403 | `company_account_required` | 使用活跃企业账户。 |
| 403 | `account_blocked` | 联系授权 operator 恢复账户。 |
| 403 | `owner_required` | 使用企业 owner 的凭证。 |
| 404 | `domain_not_found` | 先列出账户域名并使用当前 ID。 |
| 409 | `domain_claimed` | 选择其他域名；所有权是唯一的。 |
| 409 | `domain_already_configured` | 替换前先删除当前域名。 |
| 429 | `too_many_requests` | 稍后再试；创建和验证分别限制为每账户每小时 10 次。 |
| 503 | `custom_domains_unavailable` | 当前环境尚未配置自定义域名。 |
| 503 | `dns_check_failed` | DNS 无法访问；等待并确认 nameserver 后再次调用 `verify`。 |

请参阅[错误](https://docs.cbpayapp.com/zh/errors.md)中的通用响应 envelope。

## 常见问题

> [accordion] DNS 传播需要多久？
>
> 取决于权威 nameserver 和 TTL。用公共 DNS 查询确认 TXT 和 CNAME 后再次调用 `verify`。`GET` 从不执行 DNS 检查。

> [accordion] 可以使用 Cloudflare 橙色代理吗？
>
> 不可以。CNAME 必须 DNS-only。代理会隐藏所需的 CNAME target，并可能阻止 TLS challenge 到达 origin。

> [accordion] 可以配置 apex 域名吗？
>
> 请使用 `verify.acme.example` 这样的子域名。验证流程要求 CNAME，而大多数 DNS 服务商不支持在 apex 上配置 CNAME。

> [accordion] 为什么 Google Maps autocomplete 变差了？
>
> Places 使用的 browser key 属于 CBPay。请联系 CBPay 支持或运营团队，为自定义主机 allowlist `https://verify.acme.example/*`。在 CBPay 完成 allowlist 前，autocomplete 可能退回手动输入；这与 DNS 验证独立。

> [accordion] 自定义主机会改变样式吗？
>
> 不会。邀请携带样式快照，域名只改变主机。

> [accordion] 为什么链接使用了规范主机？
>
> 域名可能仍在 pending、suspended、TLS pending，或因重新验证过期/删除。只有 active 且 TLS active 的域名才会使用。

另请参阅 [Product styles](https://docs.cbpayapp.com/zh/guides/product-styles.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.