实名认证部分修改
This commit is contained in:
parent
e9681e01a3
commit
3deceacdf8
@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:aliyun_face_plugin/aliyun_face_plugin.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:star_lock/app_settings/app_settings.dart';
|
||||
@ -10,79 +9,87 @@ import 'package:star_lock/tools/aliyunRealNameAuth/serviceAuthResult_entity.dart
|
||||
import 'package:star_lock/tools/baseGetXController.dart';
|
||||
|
||||
class AliyunRealNameAuthProvider {
|
||||
final aliyunFacePlugin = AliyunFacePlugin(); //实名认证初始化
|
||||
var infos = ''; //打印信息
|
||||
var metainfosMap = {}; //认证信息
|
||||
var certifyId = ''; //认证ID
|
||||
var getLockInfo = LockListInfoItemEntity(); //锁信息
|
||||
final Function(bool, int) onCertifyResultWithTime; //认证结果及下次认证时间
|
||||
AliyunRealNameAuthProvider({
|
||||
required this.getLockInfo,
|
||||
required this.onCertifyResultWithTime,
|
||||
});
|
||||
final AliyunFacePlugin aliyunFacePlugin = AliyunFacePlugin();
|
||||
final Function(bool, int) onCertifyResultWithTime; //认证结果及下次认证时间回调
|
||||
final LockListInfoItemEntity getLockInfo; //锁信息
|
||||
|
||||
AliyunRealNameAuthProvider(
|
||||
{required this.getLockInfo, required this.onCertifyResultWithTime});
|
||||
String infos = ''; //打印信息
|
||||
Map<String, dynamic> metainfosMap = {}; //认证信息
|
||||
String certifyId = ''; //认证ID
|
||||
|
||||
//初始化
|
||||
initAliyunRealNameAuth() {
|
||||
void initAliyunRealNameAuth() {
|
||||
aliyunFacePlugin.init();
|
||||
getMetaInfos();
|
||||
}
|
||||
|
||||
// 获取客户端metainfos,将信息发送到服务器端,调用服务器端相关接口获取认证ID,即CertifyId。
|
||||
// 获取客户端metainfos,将信息发送到服务器端,
|
||||
Future<void> getMetaInfos() async {
|
||||
String metainfos;
|
||||
|
||||
try {
|
||||
metainfos = await aliyunFacePlugin.getMetaInfos() ?? 'Unknown metainfos';
|
||||
final String metainfos =
|
||||
await aliyunFacePlugin.getMetaInfos() ?? 'Unknown metainfos';
|
||||
metainfosMap = jsonDecode(metainfos);
|
||||
infos = 'metainfos: $metainfos';
|
||||
AppLog.log(infos);
|
||||
await getFaceCertifyId();
|
||||
} on PlatformException {
|
||||
metainfos = 'Failed to get metainfos.';
|
||||
infos = '获取metainfos失败。';
|
||||
AppLog.log(infos);
|
||||
}
|
||||
|
||||
infos = "metainfos: $metainfos";
|
||||
AppLog.log(infos);
|
||||
getFaceCertifyId();
|
||||
}
|
||||
|
||||
// 获取人脸认证certifyId
|
||||
void getFaceCertifyId() async {
|
||||
LockCertifyEntity entity = await ApiRepository.to.getFaceCertifyId(
|
||||
//调用服务器端相关接口获取认证ID,即CertifyId
|
||||
Future<void> getFaceCertifyId() async {
|
||||
try {
|
||||
final LockCertifyEntity entity = await ApiRepository.to.getFaceCertifyId(
|
||||
lockId: getLockInfo.lockId ?? 0,
|
||||
keyId: getLockInfo.keyId ?? 0,
|
||||
metaInfo: metainfosMap);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
certifyId = entity.data!.certifyId!;
|
||||
startVerify();
|
||||
metaInfo: metainfosMap,
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
certifyId = entity.data!.certifyId!;
|
||||
await startVerify();
|
||||
} else {
|
||||
AppLog.log('获取certifyId失败: ${entity.errorCode}');
|
||||
}
|
||||
} catch (e) {
|
||||
AppLog.log('getFaceCertifyId中出现异常: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 调用认证接口,CertifyId需要调用服务器端接口获取。
|
||||
Future<void> startVerify() async {
|
||||
String verifyResult;
|
||||
try {
|
||||
// 每个CertifyId只能使用一次,否则会返回code: "2002(iOS), 1001(Android)"。
|
||||
verifyResult =
|
||||
await aliyunFacePlugin.verify("certifyId", certifyId) ?? '-1,error';
|
||||
final String verifyResult =
|
||||
await aliyunFacePlugin.verify('certifyId', certifyId) ?? '-1,error';
|
||||
infos = 'verifyResult: $verifyResult';
|
||||
AppLog.log(infos);
|
||||
await getServiceCheckCertify();
|
||||
} on PlatformException {
|
||||
verifyResult = '-2,exception';
|
||||
infos = '验证过程中出现异常。';
|
||||
AppLog.log(infos);
|
||||
}
|
||||
|
||||
infos = "verifyResult: $verifyResult";
|
||||
AppLog.log(infos);
|
||||
getServiceCheckCertify();
|
||||
}
|
||||
|
||||
// 检测certifyId是否完成认证
|
||||
// 检测certifyId是否完成认证
|
||||
Future<void> getServiceCheckCertify() async {
|
||||
ServiceAuthResultEntity entity =
|
||||
await ApiRepository.to.getServiceCheckCertify(
|
||||
certifyId: certifyId,
|
||||
keyId: getLockInfo.keyId ?? 0,
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
// 如果认证成功,则调用回调函数,将结果传递给调用处
|
||||
onCertifyResultWithTime(true, entity.data!.nextFaceValidateTime!);
|
||||
} else {
|
||||
// 如果认证失败
|
||||
// await startVerify();
|
||||
try {
|
||||
final ServiceAuthResultEntity entity =
|
||||
await ApiRepository.to.getServiceCheckCertify(
|
||||
certifyId: certifyId,
|
||||
keyId: getLockInfo.keyId ?? 0,
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
onCertifyResultWithTime(true, entity.data!.nextFaceValidateTime!);
|
||||
} else {
|
||||
AppLog.log('认证失败: ${entity.errorCode}');
|
||||
// 可选:在这里处理重试逻辑
|
||||
}
|
||||
} catch (e) {
|
||||
AppLog.log('getServiceCheckCertify中出现异常: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
class LockCertifyEntity {
|
||||
int? errorCode;
|
||||
String? description;
|
||||
String? errorMsg;
|
||||
Data? data;
|
||||
|
||||
LockCertifyEntity(
|
||||
{this.errorCode, this.description, this.errorMsg, this.data});
|
||||
|
||||
@ -13,6 +8,10 @@ class LockCertifyEntity {
|
||||
errorMsg = json['errorMsg'];
|
||||
data = json['data'] != null ? Data.fromJson(json['data']) : null;
|
||||
}
|
||||
int? errorCode;
|
||||
String? description;
|
||||
String? errorMsg;
|
||||
Data? data;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
@ -27,13 +26,12 @@ class LockCertifyEntity {
|
||||
}
|
||||
|
||||
class Data {
|
||||
String? certifyId;
|
||||
|
||||
Data({this.certifyId});
|
||||
|
||||
Data.fromJson(Map<String, dynamic> json) {
|
||||
certifyId = json['certifyId'];
|
||||
}
|
||||
String? certifyId;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
class ServiceAuthResultEntity {
|
||||
int? errorCode;
|
||||
String? description;
|
||||
String? errorMsg;
|
||||
Data? data;
|
||||
|
||||
ServiceAuthResultEntity(
|
||||
{this.errorCode, this.description, this.errorMsg, this.data});
|
||||
|
||||
@ -13,6 +8,10 @@ class ServiceAuthResultEntity {
|
||||
errorMsg = json['errorMsg'];
|
||||
data = json['data'] != null ? Data.fromJson(json['data']) : null;
|
||||
}
|
||||
int? errorCode;
|
||||
String? description;
|
||||
String? errorMsg;
|
||||
Data? data;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
@ -27,14 +26,13 @@ class ServiceAuthResultEntity {
|
||||
}
|
||||
|
||||
class Data {
|
||||
int? nextFaceValidateTime;
|
||||
|
||||
Data({this.nextFaceValidateTime});
|
||||
|
||||
Data.fromJson(Map<String, dynamic> json) {
|
||||
nextFaceValidateTime = json['nextFaceValidateTime'];
|
||||
}
|
||||
|
||||
Data({this.nextFaceValidateTime});
|
||||
int? nextFaceValidateTime;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['nextFaceValidateTime'] = nextFaceValidateTime;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user