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

# 银行连接：持续访问、同意与续期

> 银行连接是用户授权读取单个银行数据的许可。Didit 提供连接状态查看、同意期限说明、续期方法，以及停止访问和删除数据的操作指引。

Didit 银行连接是某个人或企业授权您的应用读取一家银行数据的许可，包含同意日期、同步状态和账户信息。
完成 [Bank Link](https://docs.didit.me/zh/core-technology/bank-verification/bank-link.md) 后即会创建该连接，其有效期为银行和该用户允许的时长。

银行数据目前仅面向沙盒应用开放。在生产环境开通公告发布之前，生产应用的调用将返回 `404`。

## 一次性访问与持续访问

| | 一次性 | 持续 |
| - | - | - |
| `access` | `one_time`（默认） | `ongoing` |
| 运作方式 | 用户连接时读取一次数据。读取完成后，连接会自动结束：状态显示为 `revoked`，`status_reason: collection_complete`，`consent.ended_by: system`，并且 `sync.next_sync_at` 为 `null`。 | 访问权限保持开放，直到同意结束或有人将其停止。 |
| 之后的数据 | 在 `consent.retain_until` 所示日期之前，仍可通过相同的 endpoint 读取。刷新或续期请求会返回 `409 one_time_connection`：如需再次读取该银行，请创建新的链接。 | 根据银行不同，每天自动同步一到四次，另可按需进行实时同步。 |
| 计费 | 按每次完成的读取计费，参见[定价](https://docs.didit.me/zh/getting-started/bank-verification-pricing.md) | 按每月活跃连接计费，参见[定价](https://docs.didit.me/zh/getting-started/bank-verification-pricing.md) |

持续访问仅在银行允许的情况下才能在该银行生效。
可以查询[机构 endpoint](https://docs.didit.me/zh/standalone-apis/bank-institutions-list.md)，或阅读[覆盖范围页面](https://docs.didit.me/zh/core-technology/bank-verification/coverage.md)。
若银行无法保持访问开放，系统会告知终端用户该银行不允许持续访问，用户需要选择其他银行。
设置 `allow_one_time_fallback: true`，可使终端用户在自己的屏幕上确认访问范围缩小后，继续进行一次性读取：此时连接为 `one_time`。

![浅色主题下一次性 Bank Link 读取的最后界面：显示“您的银行数据已共享，企业仅接收了一次数据，且不会继续与银行保持连接”，并显示来自 Didit Test Bank 的 3 个共享账户](https://mintcdn.com/didit-0f962782/uVSV2mKMBQz2I1Fa/images/bank-verification/bank-link-one-time-shared-light.png?fit=max\&auto=format\&n=uVSV2mKMBQz2I1Fa\&q=85\&s=1d0eb009093502dfe64d49fe46a6b69a)

沙盒中一次性读取的最后一个界面：不会继续与银行保持连接。

## 状态

| `status` | 含义 | 数据可读 | 同步 | 计费 |
| - | - | - | - | - |
| `pending` | 链接已完成，首次同步正在运行。 | 尚不可读 | 运行中 | 否 |
| `active` | 同意有效，同步运行正常或正在重试。 | 是 | 是 | 是 |
| `renewal_required` | 同意已结束，或银行要求用户重新登录。`status_reason` 说明具体原因。 | 保留上次同步的数据 | 否 | 否 |
| `paused` | 余额不足以覆盖当月费用。 | 保留上次同步的数据 | 否 | 否 |
| `revoked` | 访问权限已被用户、银行或您停止，或在一次性读取完成后由 Didit 结束。`consent.ended_by` 说明由谁结束。 | 直到 `consent.retain_until` 为止 | 否 | 否 |
| `deleted` | 连接及其数据已被删除。 | 否 | 否 | 否 |
| `failed` | 首次同步从未成功。 | 否 | 否 | 否 |

`status_reason` 的取值为 `collection_complete`、`consent_expired`、`consent_lapsed`、`bank_requires_sign_in`、`revoked_by_end_user`、`revoked_by_bank`、`revoked_by_customer`、`insufficient_balance`、`paused_by_customer`（保留值，目前没有任何 endpoint 会设置它）和 `first_sync_failed` 之一。

## 同意

银行会设定同意的结束时间，最长不超过您请求的 `consent_days`。
每个连接都会在 `consent` 中显示真实日期：

* `expires_at` 和 `renew_by`：同意的结束时间。请在此之前续期，以免中断。
* `renewable_until`：同意结束后，同一连接仍可恢复的最后时刻。
* `renewed_count`、`version`、`scopes_granted` 和 `accounts_granted`：已授予的内容，以及续期的次数。

同意的有效期取决于银行允许的时长。
请以每个连接上的实际值为准，并参考机构上按银行列出的值。

## 续签

续签会保留连接 ID 和所有账户 ID，历史记录会延续，不会产生重复记录。

1. Didit 会在到期前 14 天、7 天和 1 天发送 `bank.connection.consent_expiring`。
2. 调用 [`POST /v3/bank/connections/{id}/renew/`](https://docs.didit.me/zh/standalone-apis/bank-connection-renew)。在剩余时间超过 30 天时，它返回 `409 renewal_not_needed`；在超过 `consent.renewable_until` 之后，它返回 `409 renewal_window_expired`。其他情况下，它返回 `201` 和续签链接。

将续签链接中的 `url` 发送给用户。用户会看到哪些数据将继续共享以及共享期限，需要在其银行登录一次，然后返回您的 `redirect_url`。`bank.connection.renewed` 会确认续签完成。
请参阅[续签银行同意](https://docs.didit.me/zh/use-cases/renew-bank-consent.md)。

如果用户任其同意失效，连接状态会变为 `renewal_required`。此时，数据仍可按最近一次同步的状态读取，且不产生任何费用。
超过 `consent.renewable_until` 之后，连接状态变为 `revoked`，并带有 `status_reason: consent_lapsed`，用户需要重新连接。

完整流程请参阅[续签银行同意](https://docs.didit.me/zh/use-cases/renew-bank-consent.md)。

## 停止访问

| 谁 | 如何操作 | 会发生什么 |
| - | - | - |
| 终端用户 | 在其银行中**Stop sharing** | `bank.connection.revoked`，其中 `ended_by: end_user` 或 `bank` |
| 您 | [`revoke_connection`](https://docs.didit.me/zh/standalone-apis/bank-connection-revoke) | 银行会立即停止获取数据。同意状态变为 `revocation_pending`，待银行确认后变为 `revoked`。已读取的数据在您删除该连接或 `consent.retain_until` 到期之前仍可读取。 |
| 您 | [`delete_connection`](https://docs.didit.me/zh/standalone-apis/bank-connection-delete) | 停止访问，并删除该连接及其账户、余额和交易数据。此操作不可撤销。 |

停止访问不等于删除。
请阅读[数据、同意与删除](https://docs.didit.me/zh/core-technology/bank-verification/data-consent-and-deletion.md)，了解删除具体会移除哪些内容。

## 已删除的连接

已删除的连接只返回 `id`、`status`（`deleted`）、`status_reason`、`created_at` 和 `erasure` 字段。
`status_reason` 的值为 `deleted_by_customer`、`consent_lapsed`、`retention_elapsed` 或 `application_deleted` 之一。
其他字段均不会返回。

## 重复项

新验证链接所解析出的账户，如果与同一 `end_user.reference`、同一家银行下您已共享的账户完全一致，则该链接会作为此连接的续期完成（`reused: true`），且不会重复收费。

其他任何重叠都会使该链接以 `failed` 结束，并返回 `duplicate_conflict` 和 `conflicts_with`，且不会存储任何内容，也不会收费。

请续期现有连接，或使用 `"duplicates": "allow"` 重新创建链接，以建立一个独立的第二个连接。

## 管理客户的连接

* 按筛选条件列出连接：[`GET /v3/bank/connections/`](https://docs.didit.me/zh/standalone-apis/bank-connections-list) 支持 `status`、`access`、`institution_id`、`country`、`vendor_data`、`end_user_reference`、`consent_expires_before` 和 `created_after` 参数。
* 查看连接费用：一次性读取的价格可在链接的 `quote` 和用量页面中查看；`billing.price_usd` 为持续连接的月度价格（一次性连接时为 `null`）。


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