跳到主要内容

📲 iOS、Android & React Native

eKYC SDK 为 iOS (Swift / Objective-C)、Android (Kotlin / Java) 和 React Native 提供了原生封装。每个封装都呈现一个全屏 WebView,运行与托管桥接页上的Web SDK相同的生产引擎 — 因此,文档自动捕获和人脸主动活体检测在每个平台上行为一致,引擎改进无需更新即可到达您的应用,并且封装几乎不会增加您的二进制文件大小。

所有封装都公开相同的三个摄像头流程:

流程功能API 计费
documentCapture自动捕获文档并提交进行 OCR (身份证护照官方证件)0.75–1.25 IC
activeLiveness人脸主动活体检测挑战 + 服务器签名裁决1 IC
faceCapture自动捕获清晰的正脸自拍(无挑战)用于人脸验证 / 被动活体检测免费(仅捕获)

要求:运行时需要访问 https://iapp.co.th/sdk/webview.html 的互联网连接(eKYC 无论如何都需要 API 调用连接),以及一个摄像头。

iOS (Swift / Objective-C)

安装: Xcode → 文件 → 添加包依赖项…https://github.com/iapp-technology/iapp-ekyc-sdk → 产品 IappEkyc。需要 iOS 15+ 和 Info.plist 中的 NSCameraUsageDescription 条目。

import IappEkyc

let config = IappEkycConfig(apiKey: "YOUR_API_KEY", flow: .documentCapture)
config.documentType = .thaiIdFront // .thaiIdBack .passport .thaiDriverLicense .bookBank .thaiIdWithSignature
config.locale = .th // .en / .th / .zh

IappEkycSdk.present(from: self, config: config) { result in
switch result {
case .success(let outcome):
print(outcome.document?.rawJSON ?? [:]) // 完整的 OCR 响应
case .failure(let error as NSError)
where error.code == IappEkycErrorCode.cancelled.rawValue:
break // 用户取消
case .failure(let error):
print(error.localizedDescription) // error.code: IappEkycErrorCode
}
}

主动活体检测返回服务器签名裁决:

let config = IappEkycConfig(apiKey: "YOUR_API_KEY", flow: .activeLiveness)
IappEkycSdk.present(from: self, config: config) { result in
if case .success(let outcome) = result, let liveness = outcome.liveness {
// 在您的后端验证 verdictJSON + signature — 切勿在设备上信任
// `passed` 标志。
upload(liveness.verdictJSON, liveness.signature, liveness.selfieImageData)
}
}

Objective-C 通过委托使用相同的类:

@import IappEkyc;

IappEkycConfig *config = [[IappEkycConfig alloc] initWithApiKey:@"YOUR_API_KEY"
flow:IappEkycFlowTypeDocumentCapture];
config.documentType = IappEkycDocumentTypeThaiIdFront;
[IappEkycSdk presentFrom:self config:config delegate:self];
// 实现 IappEkycViewControllerDelegate: didFinishWithResult / didFailWithError / didCancel

Android (Kotlin / Java)

通过 JitPack 安装 — minSdk 24,并拥有最新版 Android System WebView:

// settings.gradle.kts
dependencyResolutionManagement {
repositories { google(); mavenCentral(); maven("https://jitpack.io") }
}
// app/build.gradle.kts
dependencies { implementation("com.github.iapp-technology:iapp-ekyc-sdk:v0.2.0") }

该库声明了 CAMERA 权限并在运行时自行请求。

val config = IappEkycConfig.Builder("YOUR_API_KEY").locale(EkycLocale.TH).build()

private val ekyc = registerForActivityResult(IappEkycContract()) { result ->
when (result) {
is IappEkycResult.DocumentCaptured -> handleOcr(result.rawJson)
is IappEkycResult.LivenessPassed ->
// 在您的后端验证 verdictJson + signature。
upload(result.verdictJson, result.signature, result.selfieImage)
is IappEkycResult.FaceCaptured -> useSelfie(result.image)
is IappEkycResult.Failed -> show(result.error) // error.code: EkycErrorCode
IappEkycResult.Cancelled -> {}
}
}

// 启动任何流程:
ekyc.launch(IappEkycRequest.DocumentCapture(config, EkycDocumentType.THAI_ID_FRONT))
ekyc.launch(IappEkycRequest.ActiveLiveness(config))
ekyc.launch(IappEkycRequest.FaceCapture(config))

Java 通过回调 API 完全支持:

IappEkyc.start(this,
new IappEkycRequest.DocumentCapture(config, EkycDocumentType.THAI_ID_FRONT),
new IappEkycCallback() {
@Override public void onResult(IappEkycResult result) { /* ... */ }
@Override public void onError(IappEkycError error) { /* ... */ }
@Override public void onCancelled() { }
});

React Native

安装(npm 包待发布 — 从检出安装)并安装 react-native-webview 依赖项:

git clone https://github.com/iapp-technology/iapp-ekyc-sdk
npm install ./iapp-ekyc-sdk/react-native react-native-webview
cd ios && pod install

iOS:添加 NSCameraUsageDescription。Android:添加 CAMERA 权限并在挂载流程之前请求。

import { useState } from 'react';
import { Button, Modal, PermissionsAndroid, Platform } from 'react-native';
import { IappEkycFlow } from '@iapp-technology/react-native-ekyc-sdk';

function KycScreen() {
const [active, setActive] = useState(false);

const start = async () => {
if (Platform.OS === 'android') {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) return;
}
setActive(true);
};

return (
<>
<Button title="Capture Thai ID" onPress={start} />
<Modal visible={active} animationType="slide" presentationStyle="fullScreen">
<IappEkycFlow
flow="documentCapture" // 'documentCapture' | 'activeLiveness' | 'faceCapture'
documentType="thaiIdFront"
apiKey="YOUR_API_KEY"
locale="th"
onResult={(result) => { setActive(false); console.log(result); }}
onError={(error) => setActive(false)} // error.code, e.g. 'INSUFFICIENT_CREDIT'
onCancel={() => setActive(false)}
/>
</Modal>
</>
);
}

共享行为

  • API 密钥安全 — 传递 apiKey: "" 并将 baseUrl 设置为您自己的后端,以将密钥保留在服务器端(代理模式)。密钥在加载后注入到桥接页,绝不会通过 URL 传递。详情:GitHub 上的 SECURITY.md
  • 主题和区域设置 — 与 Web SDK 相同的令牌和 en/th/zh 区域设置,通过各平台的配置对象传递。
  • 裁决 — 主动活体检测结果仅由服务器签名裁决证明:在信任 passed 之前,请在您的后端重新计算 HMAC。请参阅人脸主动活体检测
  • 取消 — 流程内的取消按钮、Android 返回按钮和 iOS 滑动手势消除都会被视为取消结果;关闭/卸载流程会将其干净地中止。
  • 桥接合同 — 完整的封装↔引擎协议已在 GitHub 上的 WEBVIEW_BRIDGE.md 中记录。