Flutter插件vnid的使用方法详解
Flutter插件vnid的使用方法详解
eKYC SDK by VNID for PVcomBank - Flutter
⚠️ 请求
- 最低iOS部署目标:13.0
- Xcode 15.3或更新版本
- Swift 5.10或更新版本
- 权限:相机、NFC、存储
- Android minSdkVersion:>= 24
- Android Gradle:>= 7
DART
iOS设置
1. 在Info.plist
文件中添加信息
您需要添加相机权限:
<key>NSCameraUsageDescription</key>
<string>Camera permission</string>
2. 将bshield.dat
文件添加到您的项目中
PVcomBank将为您提供此bshield.dat
文件。
⚠️ 重要提示
如果您编译项目并遇到以下错误:
- 未找到Pods
Alamofire
、CryptoSwift
、SnapKit
、lottie-ios
、KeychainSwift
、ObjectMapper
- 与
IPHONEOS_DEPLOYMENT_TARGET
相关 - Swift版本冲突
请在项目的Podfile
文件中添加以下内容:
post_install do |installer|
installer.pods_project.targets.each do |target|
if ["Alamofire", "CryptoSwift", "SnapKit", "lottie-ios", "KeychainSwift", "ObjectMapper"].include? "#{target}"
target.build_configurations.each do |config|
config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES"
end
end
if ["Alamofire", "KeychainSwift", "ObjectMapper"].include? "#{target}"
target.build_configurations.each do |config|
deployment_target = config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"]
if !deployment_target.nil? || !deployment_target.empty? || deployment_target.to_f < 12.0
config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = "12.0"
end
end
end
end
end
Android设置
1.
首先下载并解压缩附带的库pom文件到包含项目的目录。然后在项目的build.gradle
文件中配置路径,例如:
repositories {
google()
mavenCentral()
maven { url "https://maven.google.com" }
maven { url "https://jitpack.io" }
maven {
setUrl("$rootDir/repository")
}
maven {
url = uri("https://maven.pkg.github.com/pvcbdigibank/SDK-KYC-v2-ANDROID")
credentials {
username = ""
password = "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"
}
}
}
接下来,在项目的主模块的build.gradle
文件中添加库声明,例如:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.core:core-ktx:$corektx"
implementation "androidx.appcompat:appcompat:$appcompat"
implementation "com.google.android.material:material:$material"
implementation "androidx.constraintlayout:constraintlayout:$constraintlayout"
implementation "androidx.navigation:navigation-fragment-ktx:$navcomponent"
implementation "androidx.navigation:navigation-ui-ktx:$navcomponent"
//zxing ------------------------------------------------------------------------------------
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
//endzxing ------------------------------------------------------------------------------------
implementation ("com.pvcombank.sdk:kyc2:1.5.1")
implementation ("com.hugtm:kyclight:1.0.2")
}
2.
接下来配置访问SDK的证书,例如:
-Project
+ gradle
- app
- src
- main
- assets
bsheild.dat <- 证书文件
- release [main]
- assets
bsheild.dat <- 证书文件
同步Gradle以加载相关库。
使用
开设银行账户
只需手机号码和邮箱即可即时开设账户
Future<void> _startEKyc(email, phone, editable, requireEmail) async {
setState(
() {
kycStatus = "Starting KYC...";
},
);
try {
KycConfig config = KycConfig(
env: Environment.PROD,
debug: true,
appCode: "ONBOARD",
appId: "ONBOARD",
partnerUserId: "partner.user.id",
email: email,
phone: phone,
requireEmail: requireEmail);
await pvcomBankKyc.startKyc(config);
} catch (e) {
setState(() {
kycStatus = "Error starting KYC: $e";
});
}
}
回调
void _setupEventListener() {
pvcomBankKyc.eventStream.listen(
(event) {
print('Kyc received event: $event');
if (event is Map<String, dynamic>) {
//TODO: Your code here
}
},
onError: (error) {
print('Kyc error: $error');
setState(() {
kycStatus = "Error: $error";
});
},
);
}
完整示例Demo
import 'package:flutter/material.dart';
import 'package:vnid/vnid.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _vnidPlugin = Vnid();
bool debug = false;
bool requiredEmail = false;
bool editable = false;
String appID = "ONBOARD";
String appCode = "ONBOARD";
String email = "";
String phone = "";
String partnerUserID = "";
String error = "";
[@override](/user/override)
void initState() {
super.initState();
_setupEventListener();
}
void _setupEventListener() {
_vnidPlugin.eventStream.listen(
(event) {
print('Kyc received event: $event');
if (event is Map<String, dynamic>) {
setState(
() {
if (event['type'] == 'success') {
//TODO:
} else if (event['type'] == 'screen') {
//TODO:
} else if (event['type'] == 'error') {
//TODO:
}
},
);
}
},
onError: (error) {
print('Kyc error: $error');
setState(() {
//TODO:
});
},
);
}
Future<void> startKyc() async {
try {
await _vnidPlugin.startKyc(debug, appID, appCode, email, phone, editable,
partnerUserID, requiredEmail);
} catch (e) {}
}
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
Container(
margin: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: TextField(
onSubmitted: (String value) async {
setState(() {
appID = value;
});
},
obscureText: false,
decoration: const InputDecoration(
label: Text("AppID"),
border: OutlineInputBorder(),
),
controller: TextEditingController(text: appID),
),
),
Container(
margin: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: TextField(
onSubmitted: (String value) async {
setState(() {
appCode = value;
});
},
controller: TextEditingController(text: appCode),
obscureText: false,
decoration: const InputDecoration(
label: Text("appCode"),
border: OutlineInputBorder(),
),
),
),
Container(
margin: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: TextField(
onSubmitted: (String value) async {
setState(() {
email = value;
});
},
controller: TextEditingController(text: email),
obscureText: false,
decoration: const InputDecoration(
label: Text("Email"),
border: OutlineInputBorder(),
),
),
),
Container(
margin: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: TextField(
onSubmitted: (String value) async {
setState(() {
phone = value;
});
},
controller: TextEditingController(text: phone),
obscureText: false,
decoration: const InputDecoration(
label: Text("Phone"),
border: OutlineInputBorder(),
),
),
),
Container(
margin: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: TextField(
onSubmitted: (String value) async {
setState(() {
partnerUserID = value;
});
},
controller: TextEditingController(text: partnerUserID),
obscureText: false,
decoration: const InputDecoration(
label: Text("partnerUserID"),
border: OutlineInputBorder(),
),
),
),
Container(
margin: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: Row(
children: [
if (debug) const Text("PROD") else const Text("UAT"),
Switch(
value: debug,
onChanged: (bool value) {
setState(() {
debug = value;
});
},
),
],
),
),
Container(
margin: const EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: ElevatedButton(
onPressed: () {
startKyc();
},
child: const Text("Start"),
),
)
],
),
)),
),
);
}
}
更多关于Flutter插件vnid的使用方法详解的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter插件vnid的使用方法详解的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
vnid
是一个 Flutter 插件,但目前关于它的具体功能和用途的公开信息较少。根据插件的名称和一些常见的 Flutter 插件命名模式,我们可以推测它可能与以下功能相关:
-
唯一标识符生成:
vnid
可能是一个用于生成唯一标识符(Unique Identifier)的插件。在 Flutter 应用中,唯一标识符常用于跟踪用户、设备或数据记录。 -
网络通信:
vnid
可能与网络通信有关,例如用于处理虚拟网络接口(Virtual Network Interface)或网络标识符(Network Identifier)。 -
数据管理:
vnid
可能用于管理数据标识符,例如为数据库记录、文件或其他数据资源生成唯一的 ID。 -
第三方集成:
vnid
可能是某个第三方服务或 SDK 的 Flutter 封装,用于处理特定的功能或服务。
潜在使用场景
假设 vnid
是一个用于生成唯一标识符的插件,以下是一些潜在的使用场景:
-
用户跟踪:在应用中为每个用户生成唯一的标识符,用于跟踪用户行为和数据分析。
import 'package:vnid/vnid.dart'; String userId = Vnid.generateUniqueId(); print('User ID: $userId');
-
数据记录:为数据库中的每条记录生成唯一 ID,确保数据的唯一性和可追溯性。
String recordId = Vnid.generateUniqueId(); print('Record ID: $recordId');
-
设备标识:为设备生成唯一的标识符,用于设备管理和监控。
String deviceId = Vnid.generateUniqueId(); print('Device ID: $deviceId');
-
网络通信:在网络请求中使用唯一标识符,确保请求的唯一性和可追踪性。
String requestId = Vnid.generateUniqueId(); print('Request ID: $requestId');