|
//
// IpuFaceCheckPlugin.m
// IpuFaceCheck
//
// Created by 黄玉林 on 2019/7/2.
// Copyright © 2019年 黄玉林. All rights reserved.
//
#import "IPUFaceCheckPlugin.h"
#import <IpuFaceCheck/IpuFaceCheck.h>
@interface IPUFaceCheckPlugin()<IpuFaceCheckViewControllerDelegate>
@end
@implementation IPUFaceCheckPlugin
/**
人脸识别
params[0] : appid - (string,必填)应用id。
params[1] : uid - (string,必填) 用户名称或者工号。
params[2] : imgtype - (int,可选) 图片类型(默认为0)
0、插件自定义人脸获取相机取图,
1、图片URL地址,
2、图片Base64位编码。
params[3] : picinfo - (string,可选,当imgtype = 1/2时必填) 图片数据。
当imgtype=0时,可不填;
当imgtype=1时,为图片URL;
当imgtype=2时,为图片Base64字符串;
*/
- (void)faceCheck:(NSArray *)params {
[self opreateParams:params isRegister:NO];
}
/**
人脸注册
params[0] : appid - (string,必填)应用id。
params[1] : uid - (string,必填) 用户名称或者工号。
params[2] : imgtype - (int,可选) 图片类型(默认为0)
0、插件自定义人脸获取相机取图,
1、图片URL地址,
2、图片Base64位编码。
params[3] : picinfo - (string,可选,当imgtype = 1/2时必填) 图片数据。
当imgtype=0时,可不填;
当imgtype=1时,为图片URL;
当imgtype=2时,为图片Base64字符串;
*/
- (void)faceRegister:(NSArray *)params {
[self opreateParams:params isRegister:YES];
}
- (void)opreateParams:(NSArray *)params isRegister:(BOOL)isRegister {
if (params.count < 1 || [params[0] isKindOfClass:[NSNull class]]) return;
if (params.count < 2 || [params[1] isKindOfClass:[NSNull class]]) return;
NSString *appid = params[0]; //@"5e7974ad46e0fb34ee660791";
NSString *uid = params[1];
int imgType = 0;
if (params.count > 2 && ![params[2] isKindOfClass:[NSNull class]]) {
imgType = [params[2] intValue];
}
NSString *host = [IPUMobileConfig getValue:@"face_host"];
if (imgType == 0) {
IpuFaceCheckViewController *viewController = [[IpuFaceCheckViewController alloc] init];
viewController.isRegister = isRegister;
viewController.appid = appid;
viewController.uid = uid;
viewController.host = host;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
UIViewController *vc = (UIViewController *)self.mobileDelegate;
[vc presentViewController:navigationController animated:YES completion:nil];
}else {
NSString * picInfo = nil;
if (params.count > 3 && ![params[3] isKindOfClass:[NSNull class]]) {
picInfo = params[3];
}
if (!picInfo) {
NSLog(@"IPUFaceCheck:imgtype = %d时,缺少picInfo字段内容!",imgType);
return;
}
__weak typeof(self) weakSelf = self;
[IpuFaceCheckSession ipuFaceCheckReceiveDataFromJS:host imgType:imgType picInfo:picInfo appid:params[0] uid:uid isRegister:isRegister callBack:^(BOOL success, NSDictionary *data) {
__strong typeof(weakSelf) strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *callBackDic = @{@"code":success ? @"0":@"1",@"info":(data[@"msg"]?:@"")};
[strongSelf callback:[IPUJSONHelper toJSONString:callBackDic]];
});
}];
}
}
#pragma -mark IpuFacecheckViewControllerDelegate
- (void)backMsg:(NSDictionary *)callBackDic {
[self callback:[IPUJSONHelper toJSONString:callBackDic]];
}
@end
|