277 lines
9.4 KiB
Dart
277 lines
9.4 KiB
Dart
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||
import 'idcard_method_channel.dart';
|
||
|
||
/// 身份证信息数据模型
|
||
class IdCardInfo {
|
||
final String cardType; // 证件类型 (A-二代证, I/Y-外国人, J-港澳台)
|
||
final String name; // 中文姓名
|
||
final String nameEn; // 英文姓名
|
||
final String gender; // 性别
|
||
final String genderId; // 性别代码
|
||
final String nation; // 民族/国籍
|
||
final String nationId; // 民族代码/国籍代码/通行证号码
|
||
final String birthDate; // 出生日期
|
||
final String address; // 住址
|
||
final String idNumber; // 身份证号码/永久居留证号码
|
||
final String signOrgan; // 签发机关
|
||
final String beginTerm; // 有效期起始日期
|
||
final String validTerm; // 有效期截止日期
|
||
final String version; // 证件版本号
|
||
final String? photoBase64; // 头像JPG照片base64编码
|
||
final String? fingerprintBase64; // 指纹特征值base64编码
|
||
final List<int>? photo; // 照片数据(原始格式)
|
||
|
||
IdCardInfo({
|
||
required this.cardType,
|
||
required this.name,
|
||
this.nameEn = '',
|
||
required this.gender,
|
||
this.genderId = '',
|
||
required this.nation,
|
||
this.nationId = '',
|
||
required this.birthDate,
|
||
required this.address,
|
||
required this.idNumber,
|
||
required this.signOrgan,
|
||
this.beginTerm = '',
|
||
required this.validTerm,
|
||
this.version = '',
|
||
this.photoBase64,
|
||
this.fingerprintBase64,
|
||
this.photo,
|
||
});
|
||
|
||
/// 从Map创建IdCardInfo对象
|
||
factory IdCardInfo.fromMap(Map<String, dynamic> map) {
|
||
return IdCardInfo(
|
||
cardType: map['cardType'] ?? '',
|
||
name: map['name'] ?? '',
|
||
nameEn: map['nameEn'] ?? '',
|
||
gender: map['gender'] ?? '',
|
||
genderId: map['genderId'] ?? '',
|
||
nation: map['nation'] ?? '',
|
||
nationId: map['nationId'] ?? '',
|
||
birthDate: map['birthDate'] ?? '',
|
||
address: map['address'] ?? '',
|
||
idNumber: map['idNumber'] ?? '',
|
||
signOrgan: map['signOrgan'] ?? '',
|
||
beginTerm: map['beginTerm'] ?? '',
|
||
validTerm: map['validTerm'] ?? '',
|
||
version: map['version'] ?? '',
|
||
photoBase64: map['photoBase64'],
|
||
fingerprintBase64: map['fingerprintBase64'],
|
||
photo: map['photo'] != null ? List<int>.from(map['photo']) : null,
|
||
);
|
||
}
|
||
|
||
/// 从冒号分隔的字符串创建IdCardInfo对象
|
||
/// 根据接口文档格式:证件类型:中文姓名:英文姓名:性别:性别代码:民族:民族代码:出生日期:住址:身份证号码:签发机关:发卡日期:卡有效期:证件版本号:头像JPG照片base64编码:指纹特征值base64编码
|
||
factory IdCardInfo.fromColonString(String colonString) {
|
||
final parts = colonString.split(':');
|
||
// 确保至少有16个部分
|
||
while (parts.length < 16) {
|
||
parts.add('');
|
||
}
|
||
|
||
return IdCardInfo(
|
||
cardType: parts[0],
|
||
name: parts[1],
|
||
nameEn: parts[2],
|
||
gender: parts[3],
|
||
genderId: parts[4],
|
||
nation: parts[5],
|
||
nationId: parts[6],
|
||
birthDate: parts[7],
|
||
address: parts[8],
|
||
idNumber: parts[9],
|
||
signOrgan: parts[10],
|
||
beginTerm: parts[11],
|
||
validTerm: parts[12],
|
||
version: parts[13],
|
||
photoBase64: parts[14].isNotEmpty ? parts[14] : null,
|
||
fingerprintBase64: parts[15].isNotEmpty ? parts[15] : null,
|
||
);
|
||
}
|
||
|
||
/// 转换为Map
|
||
Map<String, dynamic> toMap() {
|
||
return {
|
||
'cardType': cardType,
|
||
'name': name,
|
||
'nameEn': nameEn,
|
||
'gender': gender,
|
||
'genderId': genderId,
|
||
'nation': nation,
|
||
'nationId': nationId,
|
||
'birthDate': birthDate,
|
||
'address': address,
|
||
'idNumber': idNumber,
|
||
'signOrgan': signOrgan,
|
||
'beginTerm': beginTerm,
|
||
'validTerm': validTerm,
|
||
'version': version,
|
||
'photoBase64': photoBase64,
|
||
'fingerprintBase64': fingerprintBase64,
|
||
'photo': photo,
|
||
};
|
||
}
|
||
|
||
@override
|
||
String toString() {
|
||
return 'IdCardInfo{cardType: $cardType, name: $name, nameEn: $nameEn, gender: $gender, genderId: $genderId, nation: $nation, nationId: $nationId, birthDate: $birthDate, address: $address, idNumber: $idNumber, signOrgan: $signOrgan, beginTerm: $beginTerm, validTerm: $validTerm, version: $version}';
|
||
}
|
||
}
|
||
|
||
/// 身份证读卡器平台接口
|
||
abstract class IdcardPlatform extends PlatformInterface {
|
||
/// 构造函数
|
||
IdcardPlatform() : super(token: _token);
|
||
|
||
static final Object _token = Object();
|
||
|
||
static IdcardPlatform _instance = MethodChannelIdcard();
|
||
|
||
/// 默认实例
|
||
static IdcardPlatform get instance => _instance;
|
||
|
||
/// 设置平台特定的实现
|
||
static set instance(IdcardPlatform instance) {
|
||
PlatformInterface.verifyToken(instance, _token);
|
||
_instance = instance;
|
||
}
|
||
|
||
/// 获取平台版本
|
||
Future<String?> getPlatformVersion() {
|
||
throw UnimplementedError('platformVersion() has not been implemented.');
|
||
}
|
||
|
||
/// 获取USB权限
|
||
/// [vid] - USB设备的厂商ID
|
||
/// [pid] - USB设备的产品ID
|
||
Future<int> getUsbPermission(int vid, int pid) {
|
||
throw UnimplementedError('getUsbPermission() has not been implemented.');
|
||
}
|
||
|
||
/// 打开设备
|
||
/// [portType] - 端口类型,如"USB", "COM", "SKT", "BTH", "AUTO"
|
||
/// [portPara] - 端口参数
|
||
/// [extendPara] - 扩展参数
|
||
/// 返回值:大于0表示成功(设备句柄),其他为失败
|
||
Future<int> openDevice({String portType = 'USB', String portPara = '', String extendPara = ''}) {
|
||
throw UnimplementedError('openDevice() has not been implemented.');
|
||
}
|
||
|
||
/// 设置当前设备(多设备操作)
|
||
/// [devHandle] - 设备句柄
|
||
/// 返回值:0表示成功;非0表示失败
|
||
Future<int> setCurrentDevice(int devHandle) {
|
||
throw UnimplementedError('setCurrentDevice() has not been implemented.');
|
||
}
|
||
|
||
/// 获取当前设备(多设备操作)
|
||
/// 返回值:返回当前设备的句柄
|
||
Future<int> getCurrentDevice() {
|
||
throw UnimplementedError('getCurrentDevice() has not been implemented.');
|
||
}
|
||
|
||
/// 获取接口库信息
|
||
/// 返回值:包含version和description的Map
|
||
Future<Map<String, String>> getLibraryInfo() {
|
||
throw UnimplementedError('getLibraryInfo() has not been implemented.');
|
||
}
|
||
|
||
/// 获取设备型号
|
||
/// 返回值:设备型号字符串
|
||
Future<String> getTerminalModel() {
|
||
throw UnimplementedError('getTerminalModel() has not been implemented.');
|
||
}
|
||
|
||
/// 设备轮询心跳
|
||
/// 返回值:0表示成功;非0表示失败
|
||
Future<int> terminalHeartBeat() {
|
||
throw UnimplementedError('terminalHeartBeat() has not been implemented.');
|
||
}
|
||
|
||
/// 获取接收数据
|
||
/// 返回值:最后一次通讯收到的数据
|
||
Future<List<int>> getLastRecvData() {
|
||
throw UnimplementedError('getLastRecvData() has not been implemented.');
|
||
}
|
||
|
||
/// 获取设备固件版本
|
||
/// 返回值:包含firmVersion和hardwareVersion的Map
|
||
Future<Map<String, String>> getTerminalFirmVersion() {
|
||
throw UnimplementedError('getTerminalFirmVersion() has not been implemented.');
|
||
}
|
||
|
||
/// 获取设备序列号
|
||
/// 返回值:设备序列号字符串
|
||
Future<String> getTerminalSn() {
|
||
throw UnimplementedError('getTerminalSn() has not been implemented.');
|
||
}
|
||
|
||
/// 关闭设备
|
||
/// 返回值:0表示成功;非0表示失败
|
||
Future<int> closeDevice() {
|
||
throw UnimplementedError('closeDevice() has not been implemented.');
|
||
}
|
||
|
||
/// 寻卡
|
||
Future<int> findCard() {
|
||
throw UnimplementedError('findCard() has not been implemented.');
|
||
}
|
||
|
||
/// 选卡
|
||
Future<int> selectCard() {
|
||
throw UnimplementedError('selectCard() has not been implemented.');
|
||
}
|
||
|
||
/// 读取身份证(新版接口,支持多种证件类型)
|
||
/// [cardType] - 读取卡类型:
|
||
/// 0x00:读取二代证或外国人或港澳台
|
||
/// 0x01:只读二代证
|
||
/// 0x02:只读外国人
|
||
/// 0x03:只读港澳台
|
||
/// 0x10-0x13:对应上述类型但包含指纹信息
|
||
/// [infoEncoding] - 返回信息的编码方式:
|
||
/// 0x01:GB18030编码(GBK)
|
||
/// 0x02:UTF16-LE编码
|
||
/// 0x03:UTF-8编码
|
||
/// [timeOut] - 读卡超时时间(毫秒),0表示不等待,>0表示等待放卡
|
||
/// 返回值:0表示成功;非0表示失败,成功时返回冒号分隔的身份证信息字符串
|
||
Future<Map<String, dynamic>> idReadCard({int cardType = 0x00, int infoEncoding = 0x01, int timeOut = 30000}) {
|
||
throw UnimplementedError('idReadCard() has not been implemented.');
|
||
}
|
||
|
||
/// 读取身份证(兼容旧版接口)
|
||
/// [cardType] - 卡片类型
|
||
/// [infoEncoding] - 信息编码
|
||
/// [timeOut] - 超时时间(毫秒)
|
||
Future<Map<String, dynamic>> readCard({int cardType = 1, int infoEncoding = 0, int timeOut = 30000}) {
|
||
throw UnimplementedError('readCard() has not been implemented.');
|
||
}
|
||
|
||
/// 读取身份证详细信息
|
||
Future<IdCardInfo> readCardInfo() {
|
||
throw UnimplementedError('readCardInfo() has not been implemented.');
|
||
}
|
||
|
||
/// 读取追加住址
|
||
/// 返回值:追加住址信息字符串
|
||
Future<String> readNewAddress() {
|
||
throw UnimplementedError('readNewAddress() has not been implemented.');
|
||
}
|
||
|
||
/// 获取SAM模块状态
|
||
/// 返回值:0表示成功;非0表示失败
|
||
Future<int> getSamStatus() {
|
||
throw UnimplementedError('getSamStatus() has not been implemented.');
|
||
}
|
||
|
||
/// 获取SAM模块编号字符串
|
||
/// 返回值:SAM模块编号字符串
|
||
Future<String> getSamIdStr() {
|
||
throw UnimplementedError('getSamIdStr() has not been implemented.');
|
||
}
|
||
}
|