Flutter身份验证与KYC扫描插件flutter_accurascan_kyc的使用

发布于 1周前 作者 h691938207 来自 Flutter

Flutter身份验证与KYC扫描插件flutter_accurascan_kyc的使用

Accura Scan OCR 用于光学字符识别。

Accura Scan Face Match 用于匹配两张脸,源脸和目标脸。它会对比用户自拍照片和文档上的照片。

Accura Scan Authentication 用于客户验证和认证。通过3D自拍技术解锁用户的真正身份。

以下是设置 Accura Scan SDK 到项目中的步骤:

注意事项:

pubspec.yaml 文件中添加 flutter_accurascan_kyc 作为依赖项。

dependencies:
  flutter_accurascan_kyc: ^x.x.x

导入 Flutter 库到文件中:

import 'package:flutter_accurascan_kyc/flutter_accurascan_kyc.dart';

1. 安卓设置

将以下权限添加到 Android 的 AndroidManifest.xml 文件中:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

在根 build.gradle 文件末尾的仓库中添加以下内容:

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io/' }
        maven { url 'https://developer.huawei.com/repo/' } // 添加华为 Maven
        maven {
            url 'https://jitpack.io'
            credentials { username 'jp_ssguccab6c5ge2l4jitaj92ek2' }
        }
    }
}

app/build.gradle 文件中添加以下内容:

packagingOptions {
   pickFirst 'lib/arm64-v8a/libcrypto.so'
   pickFirst 'lib/arm64-v8a/libssl.so'
   
   pickFirst 'lib/armeabi-v7a/libcrypto.so'
   pickFirst 'lib/armeabi-v7a/libssl.so'
   
   pickFirst 'lib/x86/libcrypto.so'
   pickFirst 'lib/x86/libssl.so'
   
   pickFirst 'lib/x86_64/libcrypto.so'
   pickFirst 'lib/x86_64/libssl.so'
}

2. iOS设置

  1. 使用命令安装 git-lfs
  2. 运行 pod install

iOS Info.plist 文件中添加以下权限:

<key>NSCameraUsageDescription</key>
<string>App usage camera for scan documents.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App usage photos for get document picture.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>App usage photos for save document picture.</string>

3. 设置 Accura Scan 许可证到项目中

Accura Scan 需要两个许可证以使用其完整功能。从这里生成您的 Accura 许可证。

对于安卓:

app/src/main 目录下创建 assets 文件夹,并将许可证文件添加到 assets 文件夹中。

- key.license // for Accura Scan OCR
- accuraface.license // for Accura Scan Face Match

对于 iOS:

将这两个许可证放置在项目的 Runner 目录中,并将许可证添加到目标中。

4. 从 SDK 获取许可证配置

这将返回许可证的所有活动功能。

Future<void> getMetaData() async{
  try {
    await AccuraOcr.getMetaData().then((value) =>
        setupConfigData(json.decode(value)));
  }on PlatformException{}
  if (!mounted) return;
}

5. 扫描MRZ文档的方法

Future<void> startMRZ() async {
  try {
    var config = [
      mrzselected,
    ];
    await AccuraOcr.startMRZ(config)
        .then((value) => {
      setState((){
        dynamic result = json.decode(value);
      })
    }).onError((error, stackTrace) => {
    });
  } on PlatformException {}
}

6. 扫描OCR文档的方法

Future<void> startOCR() async {
  try {
    var config = [
      widget.countrySelect['id'],
      cardSelected['id'],
      cardSelected['name'],
      cardSelected['type'],
    ];
    await AccuraOcr.startOcrWithCard(config)
        .then((value) =>
    {
      setState(() {
        dynamic result = json.decode(value);
      })
    })
        .onError((error, stackTrace) =>
    {
    });
  } on PlatformException {}
}

7. 扫描条形码的方法

Future<void> startBarcode() async{
  var config= barcodeSelected;
  await AccuraOcr.startBarcode([config]).then((value) => {
    setState((){
      dynamic result = json.decode(value);
    })
  });
}

8. 扫描银行卡的方法

Future<void> startBankCard() async{
  try{
    await AccuraOcr.startBankCard().then((value) => {
      setState((){
        dynamic result = json.decode(value);
      })
    });
  } on PlatformException {}
}

9. 获取两张人脸之间的匹配百分比的方法

Future<void> startFaceMatch() async{
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  try{
    var accuraConfs = {
      "face_uri":this.faceMatchURL
    };

    await AccuraFacematch.setFaceMatchFeedbackTextSize(18);
    await AccuraFacematch.setFaceMatchFeedBackframeMessage("Frame Your Face");
    await AccuraFacematch.setFaceMatchFeedBackAwayMessage("Move Phone Away");
    await AccuraFacematch.setFaceMatchFeedBackOpenEyesMessage("Keep Your Eyes Open");
    await AccuraFacematch.setFaceMatchFeedBackCloserMessage("Move Phone Closer");
    await AccuraFacematch.setFaceMatchFeedBackCenterMessage("Move Phone Center");
    await AccuraFacematch.setFaceMatchFeedbackMultipleFaceMessage("Multiple Face Detected");
    await AccuraFacematch.setFaceMatchFeedBackFaceSteadymessage("Keep Your Head Straight");
    await AccuraFacematch.setFaceMatchFeedBackLowLightMessage("Low light detected");
    await AccuraFacematch.setFaceMatchFeedBackBlurFaceMessage("Blur Detected Over Face");
    await AccuraFacematch.setFaceMatchFeedBackGlareFaceMessage("Glare Detected");

    await AccuraFacematch.setFaceMatchBlurPercentage(80);
    await AccuraFacematch.setFaceMatchGlarePercentage_0(-1);
    await AccuraFacematch.setFaceMatchGlarePercentage_1(-1);

    await AccuraFacematch.startFaceMatch([accuraConfs])
        .then((value) => {
      setState((){
        dynamic result = json.decode(value);
      })
    }).onError((error, stackTrace) => {
    });
  }on PlatformException{}
}

10. 仅进行人脸匹配的方法(可选)

打开相册 1 和 2

对于相册 1:

Future<void> openGallery() async{
  try{
    var accuraConfs = {
      "face1": this.facematchURI,
      "face2": this.facematchURI2
    };

    await AccuraOcr.getGallery1([accuraConfs]).then((value) => {
      setState(() {
        _result = json.decode(value);
        facematchURI = _result["Image"];
        if(_result.toString().contains("score")){
          Score = _result["score"];
        }
        print("RESULT:- $_result");
      })
    }).onError((error, stackTrace)=>{});
  } on PlatformException {}
  if(!mounted) return;
}

对于相册 2:

Future<void> openGallery2() async{
  try{
    var accuraConfs = {
      "face1": this.facematchURI,
      "face2": this.facematchURI2
    };
    await AccuraOcr.getGallery2([accuraConfs]).then((value) => {
      setState(() {
        _result = json.decode(value);
        facematchURI2 = _result["Image"];
        if(_result.toString().contains("score")){
          Score = _result["score"];
        }
        print("RESULT:- $_result");
      })
    }).onError((error, stackTrace)=>{});
  } on PlatformException {}
  if(!mounted) return;
}

打开摄像头进行人脸匹配 1 和 2

对于人脸匹配 1:

Future<void> openCamera() async{
  try{
    var accuraConfs = {
      "face1": this.facematchURI,
      "face2": this.facematchURI2
    };
    await AccuraFacematch.setFaceMatchFeedbackTextSize(18);
    await AccuraFacematch.setFaceMatchFeedBackframeMessage("Frame Your Face");
    await AccuraFacematch.setFaceMatchFeedBackAwayMessage("Move Phone Away");
    await AccuraFacematch.setFaceMatchFeedBackOpenEyesMessage("Keep Your Eyes Open");
    await AccuraFacematch.setFaceMatchFeedBackCloserMessage("Move Phone Closer");
    await AccuraFacematch.setFaceMatchFeedBackCenterMessage("Move Phone Center");
    await AccuraFacematch.setFaceMatchFeedbackMultipleFaceMessage("Multiple Face Detected");
    await AccuraFacematch.setFaceMatchFeedBackFaceSteadymessage("Keep Your Head Straight");
    await AccuraFacematch.setFaceMatchFeedBackLowLightMessage("Low light detected");
    await AccuraFacematch.setFaceMatchFeedBackBlurFaceMessage("Blur Detected Over Face");
    await AccuraFacematch.setFaceMatchFeedBackGlareFaceMessage("Glare Detected");
    await AccuraFacematch.setFaceMatchBlurPercentage(80);
    await AccuraFacematch.setFaceMatchGlarePercentage_0(-1);
    await AccuraFacematch.setFaceMatchGlarePercentage_1(-1);

    await AccuraFacematch.getCamera1([accuraConfs]).then((value) => {
      setState(() {
        _result = json.decode(value);
        facematchURI = _result["Image"];
        if(_result.toString().contains("score")){
          Score = _result["score"];
        }
        print("RESULT:- $_result");
      })
    });
  } on PlatformException {}
  if(!mounted) return;
}

对于人脸匹配 2:

Future<void> openCamera2() async{
  try{
    var accuraConfs = {
      "face1": this.facematchURI,
      "face2": this.facematchURI2
    };

    await AccuraFacematch.setFaceMatchFeedbackTextSize(18);
    await AccuraFacematch.setFaceMatchFeedBackframeMessage("Frame Your Face");
    await AccuraFacematch.setFaceMatchFeedBackAwayMessage("Move Phone Away");
    await AccuraFacematch.setFaceMatchFeedBackOpenEyesMessage("Keep Your Eyes Open");
    await AccuraFacematch.setFaceMatchFeedBackCloserMessage("Move Phone Closer");
    await AccuraFacematch.setFaceMatchFeedBackCenterMessage("Move Phone Center");
    await AccuraFacematch.setFaceMatchFeedbackMultipleFaceMessage("Multiple Face Detected");
    await AccuraFacematch.setFaceMatchFeedBackFaceSteadymessage("Keep Your Head Straight");
    await AccuraFacematch.setFaceMatchFeedBackLowLightMessage("Low light detected");
    await AccuraFacematch.setFaceMatchFeedBackBlurFaceMessage("Blur Detected Over Face");
    await AccuraFacematch.setFaceMatchFeedBackGlareFaceMessage("Glare Detected");
    await AccuraFacematch.setFaceMatchBlurPercentage(80);
    await AccuraFacematch.setFaceMatchGlarePercentage_0(-1);
    await AccuraFacematch.setFaceMatchGlarePercentage_1(-1);

    await AccuraFacematch.getCamera2([accuraConfs]).then((value) => {
      setState(() {
        _result = json.decode(value);
        facematchURI2 = _result["Image"];
        if(_result.toString().contains("score")){
          Score = _result["score"];
        }
        print("RESULT:- $_result");
      })
    });
  } on PlatformException {}
  if(!mounted) return;
}

示例代码

import 'package:flutter/material.dart';
import 'package:flutter_accurascan_kyc/flutter_accurascan_kyc.dart';

void main() {
  runApp(MaterialApp(
    home: HomePage(),
    debugShowCheckedModeBanner: false,
  ));
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  [@override](/user/override)
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  [@override](/user/override)
  void initState() {
    super.initState();
    _shareFlipImage();
  }

  _shareFlipImage() async {
    try {
      final ByteData bytes = await rootBundle.load('assets/images/flip.png');
      final Uint8List list = bytes.buffer.asUint8List();

      final tempDir = await getTemporaryDirectory();
      final file = await File('${tempDir.path}/flip.png').create();
      file.writeAsBytesSync(list);
      String file1 = file.toString();
      String ggg = file1.replaceAll("File: '", "");
      String fff = ggg.replaceAll("'", "");
      String filePath = "file://$fff";
      setState(() {
        MyApp.path = filePath;
      });
    } catch (e) {
      print('Share error: $e');
    }
  }

  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Accura KYC"),
        backgroundColor: Colors.red[800],
      ),
      body: Container(
          decoration: const BoxDecoration(
              image: DecorationImage(
                  image: AssetImage("assets/images/bg_home.png"),
                  fit: BoxFit.cover
              )
          ),
          child: SingleChildScrollView(
              child: Center(
                child: Column(
                  children: [
                    SizedBox(height: 30,),
                    GestureDetector(
                      onTap: () {
                        Navigator.push(context, MaterialPageRoute(builder: (context) => MyApp()));
                      },
                      child: Container(
                        height: 300,
                        width: MediaQuery.of(context).size.width - 50,
                        decoration: const BoxDecoration(
                          image: DecorationImage(
                            image: AssetImage("assets/images/OCR.jpg"),
                            // fit: BoxFit.cover,
                          ),
                        ),
                      ),
                    ),
                    GestureDetector(
                      child: Container(
                        height: 300,
                        width: MediaQuery.of(context).size.width - 50,
                        decoration: const BoxDecoration(
                          image: DecorationImage(
                            image: AssetImage("assets/images/Facematch.jpg"),
                            // fit: BoxFit.cover,
                          ),
                        ),
                      ),
                      onTap: () {
                        Navigator.push(context, MaterialPageRoute(builder: (context) => FaceMatch()));
                      },
                    )
                  ],
                ),
              )
          )
      ),
    );
  }
}

更多关于Flutter身份验证与KYC扫描插件flutter_accurascan_kyc的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter身份验证与KYC扫描插件flutter_accurascan_kyc的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


当然,以下是一个关于如何在Flutter项目中集成和使用flutter_accurascan_kyc插件来进行身份验证与KYC(Know Your Customer)扫描的示例代码。

首先,确保你已经在pubspec.yaml文件中添加了flutter_accurascan_kyc依赖:

dependencies:
  flutter:
    sdk: flutter
  flutter_accurascan_kyc: ^最新版本号  # 请替换为实际的最新版本号

然后,运行flutter pub get来安装依赖。

接下来,在你的Flutter应用中,你可以按照以下步骤来使用这个插件:

  1. 导入插件
import 'package:flutter_accurascan_kyc/flutter_accurascan_kyc.dart';
  1. 配置插件

在使用插件之前,你需要进行一些配置,比如设置API密钥等。这通常在应用的初始化阶段完成。

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  
  // 初始化插件(假设你需要提供API密钥)
  AccurascanKyc.instance.initialize('你的API密钥');

  runApp(MyApp());
}

注意:这里的'你的API密钥'需要替换为你从Accurascan获取的实际API密钥。

  1. 启动KYC扫描

在你的UI中,你可以添加一个按钮来启动KYC扫描。当用户点击按钮时,将调用插件的扫描功能。

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('KYC Scan Example'),
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () async {
              try {
                // 启动KYC扫描
                var result = await AccurascanKyc.instance.startScan(
                  context: context,
                  // 可以根据需要配置其他参数,比如扫描类型、界面定制等
                );

                // 处理扫描结果
                if (result != null) {
                  // 假设result是一个包含用户信息的对象
                  print('KYC Scan Result: ${result.toJson()}');
                }
              } catch (e) {
                // 处理错误
                print('Error during KYC scan: $e');
              }
            },
            child: Text('Start KYC Scan'),
          ),
        ),
      ),
    );
  }
}

在这个例子中,AccurascanKyc.instance.startScan方法会启动一个原生的KYC扫描界面。用户完成扫描后,结果会以某种形式返回(具体取决于插件的实现和API)。在这个例子中,我们简单地打印了结果,但你可以根据实际需求处理这个结果,比如保存到数据库或显示给用户。

请注意,实际的flutter_accurascan_kyc插件API可能会有所不同,因此你需要参考插件的官方文档来获取最准确的使用方法和参数配置。此外,由于KYC扫描通常涉及敏感信息,确保你的应用已经采取了适当的安全措施来保护用户数据。

回到顶部