iOS、Android & React Native
适用于 iOS (Swift / Objective-C)、Android (Kotlin / Java) 和 React Native 的原生封装会打开一个全屏 WebView,从托管页面运行与 Web SDK 相同的引擎,因此各平台的采集行为一致,引擎更新无需发布新版本即可到达您的应用。运行时需要摄像头,并能联网访问 https://iapp.co.th/sdk/webview.html。
所有封装都提供相同的流程:
documentCapture自动采集证件并提交 OCR(身份证、护照、官方证件)。0.75–1.25 IC。activeLiveness执行人脸主动活体检测挑战,并返回服务器签名的判定结果。1 IC。faceCapture自动拍摄清晰的正脸自拍(无挑战),用于人脸验证或被动活体检测。免费(仅拍摄)。
安装并运行流程
- iOS
- Android
- React Native
- 需要 iOS 15+,并在
Info.plist中添加NSCameraUsageDescription。 - 在 Xcode 中选择 File → Add Package Dependencies…,输入
https://github.com/iapp-technology/iapp-ekyc-sdk,添加 product IappEkyc。 - 启动流程并处理结果。
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
- 需要 minSdk 24 和最新的 Android System WebView(建议 Chrome/WebView ≥ 100)。
- 添加 JitPack 仓库和依赖。
- 注册 contract 并启动任一流程。该库已声明
CAMERA权限,并在运行时自行请求。
// 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") }
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 ≥ 0.72 和
react-native-webview≥ 13.6。npm 包尚未发布,请从克隆的仓库安装。 - iOS:添加
NSCameraUsageDescription。Android:添加CAMERA权限,并在挂载流程之前请求。 - 在全屏 Modal 中渲染
IappEkycFlow。
git clone https://github.com/iapp-technology/iapp-ekyc-sdk
npm install ./iapp-ekyc-sdk/react-native react-native-webview
cd ios && pod install
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。SECURITY.md - 主题与语言:与 Web SDK 相同的令牌和
en/th/zh语言,通过各平台的配置对象设置。 - 活体判定:只有服务器签名的判定结果才能证明通过。信任
passed之前,请在您的后端重新计算其 HMAC;参见人脸主动活体检测。 - 取消:流程内的取消按钮、Android 返回键和 iOS 下滑关闭都会返回取消结果;关闭或卸载流程会干净地中止它。
- 桥接协议:封装与引擎之间的完整协议见 WEBVIEW_BRIDGE.md。