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

# 银行卡四要素核验 API 对接说明

> Identity Authentication 集成指南 - XHuoAPI

本文将介绍一种 银行卡四要素核验 API 对接说明，它可用于输入银行卡号、姓名、开户证件号、开户手机号，校验信息的真实性和一致性。

## 申请流程

要使用 API，需要先到 [银行卡四要素核验 API](https://api.xhuoapi.ai/documents/02f77369-ec7b-4218-a956-d7a84982a626) 对应页面申请对应的服务，进入页面之后，点击「Acquire」按钮，如图所示：

![](https://cdn.xhuoapi.ai/q6ytrc.png)

如果你尚未登录或注册，会自动跳转到登录页面邀请您来注册和登录，登录注册之后会自动返回当前页面。

在首次申请时会有免费额度赠送，可以免费使用该 API。

## 基本使用

首先先了解下基本的使用方式，就是输入银行卡的卡号信息，便可获得处理后结果图片，首先需要简单地传递一个 `bank_card` 字段。我们接下来就可以在界面上填写对应的内容，如图所示：

<p>
  <img src="https://cdn.xhuoapi.ai/1pl0y5.png" width="500" className="m-auto" />
</p>

可以看到这里我们设置了 Request Headers，包括：

* `accept`：想要接收怎样格式的响应结果，这里填写为 `application/json`，即 JSON 格式。
* `authorization`：调用 API 的密钥，申请之后可以直接下拉选择。

另外设置了 Request Body，包括：

* `bank_card`：需要处理的银行卡号信息，是必选参数。
* `id_card`：开户证件号，是必选参数。
* `name`：用户的姓名，是必选参数。
* `phone`：预留手机号。
* `cert_type`：开户证件类型，需与开户证件一致。
* `encryption`：可选，敏感字段加密参数（如需上送密文）。

选择之后，可以发现右侧也生成了对应代码，如图所示：

<p>
  <img src="https://cdn.xhuoapi.ai/slajgv.png" width="500" className="m-auto" />
</p>

点击「Try」按钮即可进行测试，如上图所示，这里我们就得到了如下结果：

```json theme={null}
{
  "result": "0",
  "description": "认证通过"
}
```

返回结果一共有多个字段，介绍如下：

* `result `，认证结果码，收费情况如下。
  * 收费结果码：
    * 0: 认证通过
    * -1: 认证未通过
    * -4: 持卡人信息有误
    * -5: 未开通无卡支付
    * -6: 此卡被没收
    * -7: 无效卡号
    * -8: 此卡无对应发卡行
    * -9: 该卡未初始化或睡眠卡
    * -10: 作弊卡、吞卡
    * -11: 此卡已挂失
    * -12: 该卡已过期
    * -13: 受限制的卡
    * -14: 密码错误次数超限
    * -15: 发卡行不支持此交易
  * 不收费结果码：
    * -2: 姓名校验不通过
    * -3: 银行卡号码有误
    * -16: 验证中心服务繁忙
    * -17: 验证次数超限，请次日重试
* `description`，业务结果描述。

可以看出这张银行卡的银行卡号、姓名、开户证件号、开户手机号具有真实性和一致性。

另外如果想生成对应的对接代码，可以直接复制生成，例如 CURL 的代码如下：

```shell theme={null}
curl -X POST 'https://api.xhuoapi.ai/v1/identity/bankcard/check-4e' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "name": "***",
  "phone": "***",
  "id_card": "***",
  "bank_card": "***"
}'
```

Python 的对接代码如下：

```python theme={null}
import requests

url = "https://api.xhuoapi.ai/v1/identity/bankcard/check-4e"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "name": "胡印福",
    "phone": "***",
    "id_card": "***",
    "bank_card": "***"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)
```

## 错误处理

在调用 API 时，如果遇到错误，API 会返回相应的错误代码和信息。例如：

* `400 token_mismatched`：Bad request, possibly due to missing or invalid parameters.
* `400 api_not_implemented`：Bad request, possibly due to missing or invalid parameters.
* `401 invalid_token`：Unauthorized, invalid or missing authorization token.
* `429 too_many_requests`：Too many requests, you have exceeded the rate limit.
* `500 api_error`：Internal server error, something went wrong on the server.

### 错误响应示例

```json theme={null}
{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}
```

## 结论

通过本文档，您已经了解了如何使用 银行卡四要素核验 API 进行用于输入银行卡号、姓名、开户证件号、开户手机号，校验信息的真实性和一致性。希望本文档能帮助您更好地对接和使用该 API。如有任何问题，请随时联系我们的技术支持团队。
