实名认证部分修改

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 'dart:convert';
import 'package:aliyun_face_plugin/aliyun_face_plugin.dart'; import 'package:aliyun_face_plugin/aliyun_face_plugin.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:star_lock/app_settings/app_settings.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'; import 'package:star_lock/tools/baseGetXController.dart';
class AliyunRealNameAuthProvider { class AliyunRealNameAuthProvider {
final aliyunFacePlugin = AliyunFacePlugin(); // AliyunRealNameAuthProvider({
var infos = ''; // required this.getLockInfo,
var metainfosMap = {}; // required this.onCertifyResultWithTime,
var certifyId = ''; //ID });
var getLockInfo = LockListInfoItemEntity(); // final AliyunFacePlugin aliyunFacePlugin = AliyunFacePlugin();
final Function(bool, int) onCertifyResultWithTime; // final Function(bool, int) onCertifyResultWithTime; //
final LockListInfoItemEntity getLockInfo; //
AliyunRealNameAuthProvider( String infos = ''; //
{required this.getLockInfo, required this.onCertifyResultWithTime}); Map<String, dynamic> metainfosMap = {}; //
String certifyId = ''; //ID
// void initAliyunRealNameAuth() {
initAliyunRealNameAuth() {
aliyunFacePlugin.init(); aliyunFacePlugin.init();
getMetaInfos(); getMetaInfos();
} }
// metainfosIDCertifyId // metainfos
Future<void> getMetaInfos() async { Future<void> getMetaInfos() async {
String metainfos;
try { try {
metainfos = await aliyunFacePlugin.getMetaInfos() ?? 'Unknown metainfos'; final String metainfos =
await aliyunFacePlugin.getMetaInfos() ?? 'Unknown metainfos';
metainfosMap = jsonDecode(metainfos); metainfosMap = jsonDecode(metainfos);
infos = 'metainfos: $metainfos';
AppLog.log(infos);
await getFaceCertifyId();
} on PlatformException { } on PlatformException {
metainfos = 'Failed to get metainfos.'; infos = '获取metainfos失败。';
AppLog.log(infos);
} }
infos = "metainfos: $metainfos";
AppLog.log(infos);
getFaceCertifyId();
} }
// certifyId //IDCertifyId
void getFaceCertifyId() async { Future<void> getFaceCertifyId() async {
LockCertifyEntity entity = await ApiRepository.to.getFaceCertifyId( try {
final LockCertifyEntity entity = await ApiRepository.to.getFaceCertifyId(
lockId: getLockInfo.lockId ?? 0, lockId: getLockInfo.lockId ?? 0,
keyId: getLockInfo.keyId ?? 0, keyId: getLockInfo.keyId ?? 0,
metaInfo: metainfosMap); metaInfo: metainfosMap,
if (entity.errorCode!.codeIsSuccessful) { );
certifyId = entity.data!.certifyId!; if (entity.errorCode!.codeIsSuccessful) {
startVerify(); certifyId = entity.data!.certifyId!;
await startVerify();
} else {
AppLog.log('获取certifyId失败: ${entity.errorCode}');
}
} catch (e) {
AppLog.log('getFaceCertifyId中出现异常: $e');
} }
} }
// CertifyId需要调用服务器端接口获取 // CertifyId需要调用服务器端接口获取
Future<void> startVerify() async { Future<void> startVerify() async {
String verifyResult;
try { try {
// CertifyId只能使用一次code: "2002(iOS), 1001(Android)" final String verifyResult =
verifyResult = await aliyunFacePlugin.verify('certifyId', certifyId) ?? '-1,error';
await aliyunFacePlugin.verify("certifyId", certifyId) ?? '-1,error'; infos = 'verifyResult: $verifyResult';
AppLog.log(infos);
await getServiceCheckCertify();
} on PlatformException { } on PlatformException {
verifyResult = '-2,exception'; infos = '验证过程中出现异常。';
AppLog.log(infos);
} }
infos = "verifyResult: $verifyResult";
AppLog.log(infos);
getServiceCheckCertify();
} }
// certifyId是否完成认证 // certifyId是否完成认证
Future<void> getServiceCheckCertify() async { Future<void> getServiceCheckCertify() async {
ServiceAuthResultEntity entity = try {
await ApiRepository.to.getServiceCheckCertify( final ServiceAuthResultEntity entity =
certifyId: certifyId, await ApiRepository.to.getServiceCheckCertify(
keyId: getLockInfo.keyId ?? 0, certifyId: certifyId,
); keyId: getLockInfo.keyId ?? 0,
if (entity.errorCode!.codeIsSuccessful) { );
// if (entity.errorCode!.codeIsSuccessful) {
onCertifyResultWithTime(true, entity.data!.nextFaceValidateTime!); onCertifyResultWithTime(true, entity.data!.nextFaceValidateTime!);
} else { } else {
// AppLog.log('认证失败: ${entity.errorCode}');
// await startVerify(); //
}
} catch (e) {
AppLog.log('getServiceCheckCertify中出现异常: $e');
} }
} }
} }

View File

@ -1,9 +1,4 @@
class LockCertifyEntity { class LockCertifyEntity {
int? errorCode;
String? description;
String? errorMsg;
Data? data;
LockCertifyEntity( LockCertifyEntity(
{this.errorCode, this.description, this.errorMsg, this.data}); {this.errorCode, this.description, this.errorMsg, this.data});
@ -13,6 +8,10 @@ class LockCertifyEntity {
errorMsg = json['errorMsg']; errorMsg = json['errorMsg'];
data = json['data'] != null ? Data.fromJson(json['data']) : null; data = json['data'] != null ? Data.fromJson(json['data']) : null;
} }
int? errorCode;
String? description;
String? errorMsg;
Data? data;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{}; final Map<String, dynamic> data = <String, dynamic>{};
@ -27,13 +26,12 @@ class LockCertifyEntity {
} }
class Data { class Data {
String? certifyId;
Data({this.certifyId}); Data({this.certifyId});
Data.fromJson(Map<String, dynamic> json) { Data.fromJson(Map<String, dynamic> json) {
certifyId = json['certifyId']; certifyId = json['certifyId'];
} }
String? certifyId;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{}; final Map<String, dynamic> data = <String, dynamic>{};

View File

@ -1,9 +1,4 @@
class ServiceAuthResultEntity { class ServiceAuthResultEntity {
int? errorCode;
String? description;
String? errorMsg;
Data? data;
ServiceAuthResultEntity( ServiceAuthResultEntity(
{this.errorCode, this.description, this.errorMsg, this.data}); {this.errorCode, this.description, this.errorMsg, this.data});
@ -13,6 +8,10 @@ class ServiceAuthResultEntity {
errorMsg = json['errorMsg']; errorMsg = json['errorMsg'];
data = json['data'] != null ? Data.fromJson(json['data']) : null; data = json['data'] != null ? Data.fromJson(json['data']) : null;
} }
int? errorCode;
String? description;
String? errorMsg;
Data? data;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{}; final Map<String, dynamic> data = <String, dynamic>{};
@ -27,14 +26,13 @@ class ServiceAuthResultEntity {
} }
class Data { class Data {
int? nextFaceValidateTime;
Data({this.nextFaceValidateTime});
Data.fromJson(Map<String, dynamic> json) { Data.fromJson(Map<String, dynamic> json) {
nextFaceValidateTime = json['nextFaceValidateTime']; nextFaceValidateTime = json['nextFaceValidateTime'];
} }
Data({this.nextFaceValidateTime});
int? nextFaceValidateTime;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{}; final Map<String, dynamic> data = <String, dynamic>{};
data['nextFaceValidateTime'] = nextFaceValidateTime; data['nextFaceValidateTime'] = nextFaceValidateTime;