跳到主要内容

入门指南

先决条件

在集成CDK之前,您需要:

  1. k-ID合规工作室账户 - 作为入职流程的一部分,您应该获得在https://portal.k-id.com登录的账户。
  2. 配置的产品 - 在合规工作室中创建和配置产品。更多信息,请查看合规工作室产品指南
  3. API密钥 - 获取适合环境(测试/生产)的产品API密钥

基本集成步骤

  1. 配置您的产品

    • 在开发者门户中设置权限、数据通知和品牌
    • 配置验证方法和可信成人偏好
    • 将配置推送到测试环境进行开发
  2. 生成组件URL

    • 进行API调用以为您的特定流程生成组件URL
    • 将返回的URL嵌入到应用程序内的iframe中
  3. 处理JavaScript事件或Webhook事件

    • 从前端监听嵌入组件的事件
    • 处理结果并相应地更新您的应用程序状态
    • 或者,事件也可以通过webhook调用接收。更多信息请参见Webhooks

快速开始示例 - 访问年龄验证

步骤1:生成组件URL(后端)

# Python/Flask示例 - 仅从后端调用
import requests
import os

@app.route('/api/generate-age-verification')
def generate_age_verification():
api_key = os.environ.get('KID_API_KEY') # 安全地存储在环境/密钥管理器中

response = requests.post( # 对于产品测试模式,确保您使用测试API密钥调用测试端点
'https://game-api.k-id.com/age-verification/perform-access-age-verification',
headers={
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
},
json={
'jurisdiction': 'GB',
'criteria': {
'ageCategory': 'ADULT'
}
}
)

return response.json()

步骤2:嵌入组件(前端)

<!-- HTML - 使用所需权限嵌入组件 -->
<div id="verification-container">
<iframe
id="verification-widget"
src="来自后端的VERIFICATION_URL"
width="100%"
height="600"
frameborder="0"
allow="camera;autoplay;payment;publickey-credentials-get;publickey-credentials-create">
</iframe>
</div>

步骤3:监听事件(前端)

// JavaScript - 处理验证事件
window.addEventListener('message', (event) => {
// 为安全起见验证来源
if (event.origin !== 'https://family.k-id.com') {
return;
}

console.log('验证事件:', event.data);

// 处理验证结果
if (event.data.eventType === 'Verification.Result') {
const result = event.data.data;

if (result.status === 'PASS') {
// 年龄验证成功
console.log('年龄已验证:', result.ageCategory);
console.log('使用的方法:', result.method);
// 授予对年龄限制内容的访问权限
} else if (result.status === 'FAIL') {
console.log('验证失败:', result.failureReason);
// 处理验证失败
}
}
});