实名认证部分修改

This commit is contained in:
Daisy 2024-05-22 10:41:44 +08:00
parent e9681e01a3
commit 3deceacdf8
3 changed files with 67 additions and 64 deletions

View File

@ -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();
}
// metainfosIDCertifyId
// 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(
//IDCertifyId
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');
}
}
}

View File

@ -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>{};

View File

@ -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;