实现
startOcr 方法会打开原生的证件采集流程,将图像发送至 QI Tech 的 OCR API,并返回已处理图像的密钥。
Mobile Token
我们使用 Mobile Token 让您的应用以已认证的方式 访问我们的 API。它通常已经通过邮件发送给您。如果您尚未收到您的 token,请发送邮件至 suporte.caas@qitech.com.br。
注意
每个环境(sandbox 和 production)需要不同的 Mobile Token。
方法签名
Future<OcrReturnValues> startOcr(
CaaSEnvironment environment,
String mobileToken,
CaaSDocumentType document, {
OcrOptions? options,
})
前三个参数是位置参数且为必填。自定义项是可选的,通过命名参数 options 传入,详见 OcrOptions 对象。
最小示例
import 'package:flutter_kyc_qitech/flutter_kyc_qitech.dart';
final _qitechFlutterKycPlugin = FlutterKycQitech();
final result = await _qitechFlutterKycPlugin.startOcr(
CaaSEnvironment.sandbox,
'<YOUR_MOBILE_TOKEN_SENT_BY_QITECH>',
CaaSDocumentType.cnh,
);
for (final item in result.documentRecognitionResponse) {
print('${item.documentType}: ${item.ocrKey ?? item.ocrFrontKey ?? item.ocrBackKey}');
}
完整示例
import 'package:flutter/material.dart';
import 'package:flutter_kyc_qitech/flutter_kyc_qitech.dart';
class OcrButton extends StatelessWidget {
const OcrButton({super.key});
static const String _mobileToken = '<YOUR_MOBILE_TOKEN_SENT_BY_QITECH>';
Future<void> _startOcr() async {
final plugin = FlutterKycQitech();
try {
final result = await plugin.startOcr(
CaaSEnvironment.sandbox,
_mobileToken,
CaaSDocumentType.cnh,
options: OcrOptions(
sessionId: '<SESSION_ID>',
fontColor: '#FFFFFF',
backgroundColor: '#000000',
fontFamily: CaaSFontFamily.openSans,
showIntroductionScreens: true,
showSuccessScreen: false,
audioConfiguration: FaceReconAudioConfiguration.enable,
onboardingTextConfiguration: OnboardingTextConfiguration(
onboardingTitle: 'Dicas Importantes',
onboardingFirstLabel: 'Vá para um local iluminado',
onboardingSecondLabel: 'Retire o documento do plástico',
onboardingThirdLabel: 'Garanta que o documento está corretamente enquadrado',
),
logLevel: CaaSLogLevel.debug,
),
);
for (final item in result.documentRecognitionResponse) {
if (item.ocrKey != null) {
print('Ocr key: ${item.ocrKey} document type: ${item.documentType}');
}
if (item.ocrFrontKey != null) {
print('Ocr front key: ${item.ocrFrontKey} document type: ${item.documentType}');
}
if (item.ocrBackKey != null) {
print('Ocr back key: ${item.ocrBackKey} document type: ${item.documentType}');
}
}
} catch (e) {
// startOcr 会抛出一个包含错误信息的 String
print('Erro ao executar o OCR: $e');
}
}
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: _startOcr,
child: const Text('Capturar documento'),
);
}
}
注意
请在您的应用中启用 Portrait 和 Landscape Right 方向支持,以保证 iOS 原生 SDK 正常工作。
按证件类型划分的采集流程
document 参数决定用户需要完成的采集次数,以及返回结果包含的条目数量。
| 证件类型 | 采集次数 | 返回结果 |
|---|---|---|
CaaSDocumentType.cnhFull | 1(展开的 CNH) | 1 个条目,含 ocrKey |
CaaSDocumentType.cnhDigital | 1(电子 CNH 的 PDF) | 1 个条目,含 ocrKey |
CaaSDocumentType.address | 1(居住证明) | 1 个条目,含 ocrKey |
CaaSDocumentType.rgCinDigital | 1(电子 RG/CIN 的 PDF) | 1 个条目,含 ocrKey |
CaaSDocumentType.cnh | 2(正面和背面) | 2 个条目:ocrFrontKey 和 ocrBackKey |
CaaSDocumentType.rg | 2(正面和背面) | 2 个条目:ocrFrontKey 和 ocrBackKey |
CaaSDocumentType.rne | 2(正面和背面) | 2 个条目:ocrFrontKey 和 ocrBackKey |
CaaSDocumentType.crnm | 2(正面和背面) | 2 个条目:ocrFrontKey 和 ocrBackKey |
示例应用
插件仓库在 flutter_kyc_qitech/example 下包含一个可直接运行的示例应用,演示了三个 SDK 的使用。运行前,请在 example 目录下创建 .env 文件并填入以下凭证,然后连接真机执行 flutter pub get 和 flutter run:
FACERECON_API_URL_SANDBOX=''
FACERECON_API_KEY_SANDBOX=''
OCR_MOBILE_TOKEN_SANDBOX=''
DEVICE_SCAN_API_URL_SANDBOX=''
DEVICE_SCAN_API_KEY_SANDBOX=''
如果您尚未收到凭证,请联系 suporte.caas@qitech.com.br。