📦 Didit Kyc Onboarding — 端到端KYC身份验证
v1.0.0端到端KYC(了解你的客户)身份验证服务,用于入职真实用户。创建KYC工作流、生成验证URL,让用户完成身份证扫描、自拍及人脸比对,并检索验证决策。
详细分析 ▾
运行时依赖
版本
端到端KYC入职流程:工作流创建、会话生成、决策检索
安装命令
点击复制技能文档
端到端了解您的客户(KYC)验证。此技能创建KYC工作流,生成一个会话URL,真实用户在该URL完成身份证扫描+自拍+人脸比对,并检索验证决策。
用户体验流程:
- 收到验证链接
- 扫描身份证件(护照、身份证、驾照)
- 进行实时自拍
- 系统自动将自拍与证件照片比对
- 获得批准、拒绝或标记待审核
API参考:
- 工作流:https://docs.didit.me/management-api/workflows/create
- 会话:https://docs.didit.me/sessions-api/create-session
- 决策:https://docs.didit.me/sessions-api/retrieve-session
- 程序化注册:https://docs.didit.me/integration/programmatic-registration
- 完整API概述:https://docs.didit.me/sessions-api/management-api
认证
所有请求都需要x-api-key头。从Didit Business Console → API & Webhooks获取您的密钥,或通过程序化注册(见下文)。入门(还没有账户?)
如果您没有Didit API密钥,只需2次API调用即可创建一个:- 注册:
POST https://apx.didit.me/auth/v2/programmatic/register/包含{"email": "you@gmail.com", "password": "MyStr0ng!Pass"} - 检查邮箱 获取6位字符的OTP验证码
- 验证:
POST https://apx.didit.me/auth/v2/programmatic/verify-email/包含{"email": "you@gmail.com", "code": "A3K9F2"}→ 响应包含api_key
添加积分: GET /v3/billing/balance/ 查看余额,POST /v3/billing/top-up/ 包含 {"amount_in_dollars": 50} 获取Stripe结账链接。请参阅didit-verification-management技能获取完整平台管理(工作流、会话、用户、计费)。
快速开始 — 3次API调用完成KYC
import requests, timeAPI_KEY = "your_api_key" headers = {"x-api-key": API_KEY, "Content-Type": "application/json"} BASE = "https://verification.didit.me/v3"
# 1. 创建KYC工作流(一次性设置 — 复用workflow_id用于所有用户) workflow = requests.post(f"{BASE}/workflows/", headers=headers, json={ "workflow_label": "KYC Onboarding", "workflow_type": "kyc", "is_liveness_enabled": True, "is_face_match_enabled": True, "face_match_score_decline_threshold": 50, "max_retry_attempts": 3, }).json() workflow_id = workflow["uuid"]
# 2. 为特定用户创建会话 session = requests.post(f"{BASE}/session/", headers=headers, json={ "workflow_id": workflow_id, "vendor_data": "user-abc-123", "callback": "https://yourapp.com/verification-done", "language": "en", }).json() print(f"Send user to: {session['url']}") # 用户打开此URL → 扫描身份证 → 自拍 → 完成
# 3. 轮询获取决策(或使用webhooks) while True: decision = requests.get( f"{BASE}/session/{session['session_id']}/decision/", headers={"x-api-key": API_KEY}, ).json() status = decision["status"] if status in ("Approved", "Declined", "In Review"): break time.sleep(10)
print(f"Result: {status}") if status == "Approved": id_data = decision["id_verifications"][0] print(f"Name: {id_data['first_name']} {id_data['last_name']}") print(f"DOB: {id_data['date_of_birth']}") print(f"Document: {id_data['document_type']} ({id_data['issuing_country']})")
步骤1:创建KYC工作流
工作流定义运行哪些检查。为每个用例创建一个并复用于所有用户。POST https://verification.didit.me/v3/workflows/
API参考: https://docs.didit.me/management-api/workflows/create
推荐的KYC配置
| 参数 | 值 | 原因 |
|---|---|---|
workflow_type | "kyc" | 带ID+自拍的完整KYC模板 |
is_liveness_enabled | true | 防止欺骗(打印照片、屏幕) |
is_face_match_enabled | true | 将自拍与证件照片比对 |
face_match_score_decline_threshold | 50 | 匹配度低于50%→自动拒绝 |
is_aml_enabled | false | 设置true进行制裁/PEP筛查(+成本) |
max_retry_attempts | 3 | 用户失败后可重试3次 |
响应
{
"uuid": "d8d2fa2d-c69c-471c-b7bc-bc71512b43ef",
"workflow_label": "KYC Onboarding",
"workflow_type": "kyc",
"features": ["ocr", "liveness", "face_match"],
"total_price": "0.10",
"workflow_url": "https://verify.didit.me/..."
}
将uuid保存为您的workflow_id。
步骤2:为每个用户创建会话
每个用户获得自己的会话。会话生成一个唯一URL,用户在该URL完成验证。POST https://verification.didit.me/v3/session/
API参考: https://docs.didit.me/sessions-api/create-session
关键参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
workflow_id | uuid | 是 | 来自步骤1 |
vendor_data | string | 推荐 | 您的用户ID — 将会话链接到您的系统 |
callback | url | 推荐 | 验证后的重定向URL。Didit会附加?verificationSessionId=...&status=... |
language | string | 否 | UI语言(ISO 639-1)。省略则自动检测 |
contact_details.email | string | 否 | 预填邮箱用于通知 |
expected_details.first_name | string | 否 | 如果证件姓名不同会触发不匹配警告 |
expected_details.date_of_birth | string | 否 | YYYY-MM-DD格式 |
metadata | JSON字符串 | 否 | 与会话一起存储的自定义数据 |
响应
{
"session_id": "11111111-2222-3333-4444-555555555555",
"session_token": "abcdef123456",
"url": "https://verify.didit.me/session/abcdef123456",
"status": "Not Started",
"workflow_id": "d8d2fa2d-..."
}
将用户发送到url — 这是他们完成验证的地方(网页或移动端)。
步骤3:获取决策
用户完成验证后,检索结果。GET https://verification.didit.me/v3/session/{sessionId}/decision/
API参考: https://docs.didit.me/sessions-api/retrieve-session
两种方式获知准备就绪
选项A:Webhooks(生产环境推荐)
在Business Console → API & Webhooks配置webhook URL。Didit在决策就绪时发送包含session_id和status的POST请求。
选项B:轮询
每10-30秒轮询一次GET /v3/session/{id}/decision/。检查status — 当状态为Approved、Declined或In Review时停止。
决策响应字段
{
"session_id": "...",
"status": "Approved",
"features": ["ID_VERIFICATION", "LIVENESS", "FACE_MATCH"],
"id_verifications": [{
"status": "Approved",
"document_type": "PASSPORT",
"issuing_country": "USA",
"first_name": "John",
"last_name": "Doe",
"date_of_birth": "1990-01-15",
"document_number": "ABC123456",
"expiry_date": "2030-06-01",
"gender": "M",
"nationality": "USA",
"mrz": "P关键决策状态
| 状态 | 含义 | 操作 |
|---|---|---|
Approved | 所有检查通过 | 用户已验证 |
Declined | 一个或多个检查失败 | 查看warnings了解详情 |
In Review | 边缘结果 | 需要人工审核,或通过API自动决定 |
Not Started | 用户尚未打开链接 | 等待或提醒用户 |
In Progress | 用户正在完成验证 | 等待 |
Expired | 会话已过期(默认:7天) | 创建新会话 |
可选:决策后操作
手动批准或拒绝
PATCH https://verification.didit.me/v3/session/{sessionId}/update-status/
API参考: https://docs.didit.me/sessions-api/update-status
requests.patch(f"{BASE}/session/{session_id}/update-status/", headers=headers, json={"new_status": "Approved", "comment": "Manual review passed"})
请求重新提交
如果身份证照片模糊,让用户仅重做该步骤:requests.patch(f"{BASE}/session/{session_id}/update-status/", headers=headers, json={
"new_status": "Resubmitted",
"nodes_to_resubmit": [{"node_id": "feature_ocr", "feature": "OCR"}],
"send_email": True,
"email_address": "user@example.com",
})
阻止欺诈用户
requests.post(f"{BASE}/blocklist/add/", headers=headers, json={"session_id": session_id, "blocklist_face": True, "blocklist_document": True})
API参考: https://docs.didit.me/sessions-api/blocklist/add
生成PDF报告
response = requests.get(f"{BASE}/session/{session_id}/generate-pdf", headers={"x-api-key": API_KEY})
API参考: https://docs.didit.me/sessions-api/generate-pdf
KYC工作流变体
KYC + AML筛查
添加制裁/PEP筛查以捕获高风险个人:requests.post(f"{BASE}/workflows/", headers=headers, json={
"workflow_type": "kyc",
"is_liveness_enabled": True,
"is_face_match_enabled": True,
"is_aml_enabled": True,
"aml_decline_threshold": 80,
})
KYC + 电话 + 邮箱
在流程中添加联系方式验证:requests.post(f"{BASE}/workflows/", headers=headers, json={
"workflow_type": "kyc",
"is_liveness_enabled": True,
"is_face_match_enabled": True,
"is_phone_verification_enabled": True,
"is_email_verification_enabled": True,
})
KYC + NFC(芯片读取)
对于带NFC芯片的护照 — 最高保证:requests.post(f"{BASE}/workflows/", headers=headers, json={
"workflow_type": "kyc",
"is_liveness_enabled": True,
"is_face_match_enabled": True,
"is_nfc_enabled": True,
})
实用脚本
run_kyc.py — 命令行完整KYC设置
# 需要:pip install requests
export DIDIT_API_KEY="your_api_key"# 创建KYC工作流(一次性)
python scripts/run_kyc.py setup --label "My KYC" --liveness --face-match
# 为用户创建会话
python scripts/run_kyc.py session --workflow-id --vendor-data user-123
# 获取决策
python scripts/run_kyc.py decision
# 完整流程:一次命令创建工作流+会话
python scripts/run_kyc.py full --vendor-data user-123 --callback https://myapp.com/done
也可以导入使用:
from scripts.run_kyc import setup_kyc_workflow, create_kyc_session, get_decision