实名认证部分修改
This commit is contained in:
parent
e9681e01a3
commit
3deceacdf8
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取客户端metainfos,将信息发送到服务器端,调用服务器端相关接口获取认证ID,即CertifyId。
|
// 获取客户端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
|
//调用服务器端相关接口获取认证ID,即CertifyId
|
||||||
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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>{};
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user