Files
featherVoice/QXLive/Mine(音域)/Controller/设置/QXRealNameViewController.m
2025-10-20 09:43:10 +08:00

334 lines
16 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// QXRealNameViewController.m
// QXLive
//
// Created by 启星 on 2025/5/14.
//
#import "QXRealNameViewController.h"
#import "QXLoginTextField.h"
#import "UIButton+QX.h"
#import <TencentCloudHuiyanSDKFace/WBFaceVerifyCustomerService.h>
#import "QXMineNetwork.h"
#import "QXRealNameFinishedViewController.h"
#import "QXAlertView.h"
@interface QXRealNameViewController ()<WBFaceVerifyCustomerServiceDelegate>
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)QXLoginTextField *realTextField;
@property (nonatomic,strong)QXLoginTextField *idNumberTextField;
@property (nonatomic,strong)UIView *topView;
@property (nonatomic,strong)UIButton *firstBtn;
@property (nonatomic,strong)UIButton *secondBtn;
@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)UIButton *firstCommitBtn;
@property (nonatomic,strong)UILabel *secondTitleLabel;
@property (nonatomic,strong)UIButton *secondCommitBtn;
@property (nonatomic,strong)UIImageView *headerImageView;
@property (nonatomic,strong)UILabel *messageLabel;
@property (nonatomic,strong)NSString* access_token;
@property (nonatomic,strong)NSDictionary*realNamedict;
@end
@implementation QXRealNameViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)setNavgationItems{
[super setNavgationItems];
self.navigationItem.title = QXText(@"实名认证");
}
-(void)initSubViews{
if ([QXGlobal shareGlobal].loginModel.auth == 1) {
QXRealNameFinishedViewController*vc = [[QXRealNameFinishedViewController alloc] init];
[self.view addSubview:vc.view];
[self addChildViewController:vc];
return;
}
// self.topView = [[UIView alloc] initWithFrame:CGRectMake(16, NavContentHeight+5, SCREEN_WIDTH-32, 70)];
// self.topView.backgroundColor = [UIColor whiteColor];
// [self.topView addRoundedCornersWithRadius:9];
// [self.view addSubview:self.topView];
//
// self.firstBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.topView.width/2, self.topView.height)];
// [self.firstBtn setImage:[UIImage imageNamed:@"forgot_first_nor"] forState:(UIControlStateNormal)];
// [self.firstBtn setImage:[UIImage imageNamed:@"forgot_first_sel"] forState:(UIControlStateSelected)];
// [self.firstBtn setTitle:QXText(@"填写身份信息") forState:(UIControlStateNormal)];
// self.firstBtn.titleLabel.font = [UIFont systemFontOfSize:14];
// [self.firstBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateSelected)];
// [self.firstBtn setTitleColor:RGB16(0x949494) forState:(UIControlStateNormal)];
// self.firstBtn.userInteractionEnabled = NO;
// [self.firstBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleTop) imageTitleSpace:9];
// self.firstBtn.selected = YES;
// [self.topView addSubview:self.firstBtn];
//
// UIView *line = [[UIView alloc] initWithFrame:CGRectMake((self.topView.width-74)/2, 19, 74, 1.5)];
// line.backgroundColor = RGB16(0x949494);
// [self.topView addSubview:line];
//
// self.secondBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.firstBtn.right, 0, self.topView.width/2, self.topView.height)];
// [self.secondBtn setImage:[UIImage imageNamed:@"forgot_second_nor"] forState:(UIControlStateNormal)];
// [self.secondBtn setImage:[UIImage imageNamed:@"forgot_second_sel"] forState:(UIControlStateSelected)];
// [self.secondBtn setTitle:QXText(@"人脸识别") forState:(UIControlStateNormal)];
// self.secondBtn.titleLabel.font = [UIFont systemFontOfSize:14];
// [self.secondBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateSelected)];
// [self.secondBtn setTitleColor:RGB16(0x949494) forState:(UIControlStateNormal)];
// self.secondBtn.userInteractionEnabled = NO;
// [self.secondBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleTop) imageTitleSpace:9];
// [self.topView addSubview:self.secondBtn];
// self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.topView.bottom+8, SCREEN_WIDTH, SCREEN_HEIGHT-self.topView.bottom)];
// self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH*2, self.scrollView.height);
// self.scrollView.scrollEnabled = NO;
// self.scrollView.backgroundColor = [UIColor clearColor];
// [self.view addSubview:self.scrollView];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.font = [UIFont systemFontOfSize:12];
self.titleLabel.textColor = RGB16(0x999999);
self.titleLabel.numberOfLines = 0;
self.titleLabel.text = QXText(@"根据国家相关法律法规,用户需要进行实名认证,请输人您本人真实有效的信息,一旦认证完成后不可随意更改,请慎重填写,我们承诺将严格保护您的个人信息,不会对外泄漏");
[self.view addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.width.mas_equalTo(SCREEN_WIDTH-32);
make.top.mas_equalTo(NavContentHeight+12);
}];
self.realTextField = [[QXLoginTextField alloc] init];
self.realTextField.type = LoginTextTypeRealName;
self.realTextField.backgroundColor = RGB16(0xEFF2F8);
[self.realTextField addRoundedCornersWithRadius:11];
[self.view addSubview:self.realTextField];
[self.realTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.width.mas_equalTo(SCREEN_WIDTH-32);
make.top.equalTo(self.titleLabel.mas_bottom).offset(16);
make.height.mas_equalTo(44);
}];
self.idNumberTextField = [[QXLoginTextField alloc] init];
self.idNumberTextField.type = LoginTextTypeIdNumber;
self.idNumberTextField.backgroundColor = RGB16(0xEFF2F8);
[self.idNumberTextField addRoundedCornersWithRadius:11];
[self.view addSubview:self.idNumberTextField];
[self.idNumberTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.width.mas_equalTo(SCREEN_WIDTH-32);
make.top.equalTo(self.realTextField.mas_bottom).offset(16);
make.height.mas_equalTo(44);
}];
// self.firstCommitBtn = [[UIButton alloc] init];
// [self.firstCommitBtn setTitle:QXText(@"下一步") forState:(UIControlStateNormal)];
// self.firstCommitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
// self.firstCommitBtn.backgroundColor = QXConfig.themeColor;
// [self.firstCommitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
// [self.firstCommitBtn addRoundedCornersWithRadius:21];
// [self.firstCommitBtn addTarget:self action:@selector(nextAction) forControlEvents:(UIControlEventTouchUpInside)];
// [self.scrollView addSubview:self.firstCommitBtn];
// [self.firstCommitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.mas_equalTo(38);
// make.width.mas_equalTo(SCREEN_WIDTH-38*2);
// make.top.equalTo(self.idNumberTextField.mas_bottom).offset(20);
// make.height.mas_equalTo(43);
// }];
// self.secondTitleLabel = [[UILabel alloc] init];
// self.secondTitleLabel.font = [UIFont systemFontOfSize:16];
// self.secondTitleLabel.textColor = RGB16(0x333333);
// self.secondTitleLabel.numberOfLines = 0;
// self.secondTitleLabel.textAlignment = NSTextAlignmentCenter;
// self.secondTitleLabel.text = QXText(@"为了保证本人操作,请进行人脸验证");
// [self.scrollView addSubview:self.secondTitleLabel];
// [self.secondTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.mas_equalTo(SCREEN_WIDTH);
// make.width.mas_equalTo(SCREEN_WIDTH);
// make.top.equalTo(self.scrollView);
// make.height.mas_equalTo(24);
// }];
//
// self.headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_realname_user"]];
// [self.scrollView addSubview:self.headerImageView];
// [self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.mas_equalTo((SCREEN_WIDTH-223)/2+SCREEN_WIDTH);
// make.width.height.mas_equalTo(223);
// make.top.equalTo(self.secondTitleLabel.mas_bottom).offset(9);
// }];
//
// self.messageLabel = [[UILabel alloc] init];
// NSString *str = @"您知悉并同意应用提供者 \n· 收集、使用您本人的身份信息和人脸图像 \n· 向合法数据持有者核实您的身份信息 \n· 本操作数据仅用于身份核实,安全可靠";
// self.messageLabel.numberOfLines = 0;
// self.messageLabel.font = [UIFont systemFontOfSize:14];
// self.messageLabel.textColor = RGB16(0x666666);
// NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
// [attr yy_setFont:[UIFont boldSystemFontOfSize:16] range:[str rangeOfString:@"您知悉并同意应用提供者"] ];
// [attr yy_setColor:RGB16(0x333333) range:[str rangeOfString:@"您知悉并同意应用提供者"] ];
// NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
// style.lineSpacing = 5;
// [attr yy_setParagraphStyle:style range:NSMakeRange(0, str.length)];
// self.messageLabel.attributedText = attr;
// [self.scrollView addSubview:self.messageLabel];
// [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.mas_equalTo(40+SCREEN_WIDTH);
// make.width.mas_equalTo(SCREEN_WIDTH-80);
// make.top.equalTo(self.headerImageView.mas_bottom).offset(12);
// }];
self.secondCommitBtn = [[UIButton alloc] init];
self.secondCommitBtn.needEventInterval = 1;
[self.secondCommitBtn setTitle:QXText(@"立即开始验证") forState:(UIControlStateNormal)];
self.secondCommitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
self.secondCommitBtn.backgroundColor = QXConfig.themeColor;
[self.secondCommitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
[self.secondCommitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.secondCommitBtn addRoundedCornersWithRadius:21];
[self.view addSubview:self.secondCommitBtn];
[self.secondCommitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(38);
make.width.mas_equalTo(SCREEN_WIDTH-38*2);
make.top.equalTo(self.idNumberTextField.mas_bottom).offset(20);
make.height.mas_equalTo(43);
}];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
-(void)nextAction{
NSString *realName = self.realTextField.textField.text;
NSString *idNumber = self.idNumberTextField.textField.text;
if (realName.length == 0) {
showToast(QXText(@"请输入真实姓名"));
return;
}
if (idNumber.length == 0) {
showToast(QXText(@"请输入身份证号码"));
return;
}
if (idNumber.length != 18) {
showToast(QXText(@"请输入正确的身份证号码"));
return;
}
MJWeakSelf
[QXMineNetwork postRealNameInfoWithRealName:realName card_number:idNumber successBlock:^(NSDictionary * _Nonnull dict) {
weakSelf.realNamedict = dict;
// weakSelf.firstBtn.selected = NO;
// weakSelf.secondBtn.selected = YES;
// [weakSelf.scrollView setContentOffset:CGPointMake(SCREEN_WIDTH, 0) animated:YES];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
-(void)commitAction{
NSString *realName = self.realTextField.textField.text;
NSString *idNumber = self.idNumberTextField.textField.text;
if (realName.length == 0) {
showToast(QXText(@"请输入真实姓名"));
return;
}
if (idNumber.length == 0) {
showToast(QXText(@"请输入身份证号码"));
return;
}
if (idNumber.length != 18) {
showToast(QXText(@"请输入正确的身份证号码"));
return;
}
[self.view endEditing:YES];
MJWeakSelf
showLoadingInView(self.view);
[QXMineNetwork postRealNameInfoWithRealName:realName card_number:idNumber successBlock:^(NSDictionary * _Nonnull dict) {
hideLoadingInView(self.view);
weakSelf.realNamedict = dict;
[weakSelf startFace];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
hideLoadingInView(self.view);
showToast(msg);
}];
// [QXGlobal shareGlobal].isRealName = YES;
// [self.navigationController popViewControllerAnimated:YES];
}
-(void)startFace{
WBFaceVerifySDKConfig *config = [[WBFaceVerifySDKConfig alloc] init];
// config.theme = WBFaceVerifyThemeCustom;
config.useAdvanceCompare = YES;
config.recordVideo = YES;
NSString *nonce = [NSString stringWithFormat:@"%@",self.realNamedict[@"nonce"]];
NSString *sign = [NSString stringWithFormat:@"%@",self.realNamedict[@"sign"]];
NSString *appid = [NSString stringWithFormat:@"%@",self.realNamedict[@"appid"]];
NSString *orderNo = [NSString stringWithFormat:@"%@",self.realNamedict[@"orderNo"]];
NSString *licence = [NSString stringWithFormat:@"%@",self.realNamedict[@"licence"]];
NSString *faceId = [NSString stringWithFormat:@"%@",self.realNamedict[@"faceId"]];
NSString *user_id = [NSString stringWithFormat:@"%@",self.realNamedict[@"userid"]];
[WBFaceVerifyCustomerService sharedInstance].delegate = self;
[[WBFaceVerifyCustomerService sharedInstance] initAdvanceSDKWithUserId:user_id
nonce:nonce
sign:sign
appid:appid
orderNo:orderNo
apiVersion:@"1.0.0"
licence:licence
faceId:faceId
sdkConfig:config
success:^{
QXLOG(@"拉起成功");
[[WBFaceVerifyCustomerService sharedInstance] startWbFaceVeirifySdk];
}
failure:^(WBFaceError * _Nonnull error) {
QXLOG(@"拉起失败%@",error);
}];
}
-(void)authSuccess{
QXRealNameFinishedViewController*vc = [[QXRealNameFinishedViewController alloc] init];
[self.view addSubview:vc.view];
[self addChildViewController:vc];
[QXGlobal shareGlobal].loginModel.auth = 1;
[[QXGlobal shareGlobal]updateUserInfoWithMolde:[QXGlobal shareGlobal].loginModel];
}
-(void)wbfaceVerifyCustomerServiceDidFinishedWithFaceVerifyResult:(WBFaceVerifyResult *)faceVerifyResult{
if (faceVerifyResult.isSuccess) {
QXLOG(@"人脸核验通过");
MJWeakSelf
// QXAlertView *al = [[QXAlertView alloc] initWithFrame:CGRectMake(0, 0, ScaleWidth(300), ScaleWidth(175))];
// al.type = QXAlertViewTypeNoCancel;
// al.title = @"温馨提示";
// al.message = @"恭喜您获得内测资格将获得10万金币";
// al.commitBlock = ^{
[weakSelf authSuccess];
// };
// [[QXGlobal shareGlobal] showView:al popType:(PopViewTypeTopToCenter) tapDismiss:NO finishBlock:^{
//
// }];
/// 通知服务端实名验证结果
[QXMineNetwork postRealNameResultWithOrderNo:faceVerifyResult.orderNo successBlock:^(NSDictionary * _Nonnull dict) {
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}else{
showToast(@"实名认证失败");
}
}
@end