Files
mier_ios/SweetParty/主类/RoomAdd/SAIdentityAuthVC.m
2025-08-11 10:43:19 +08:00

119 lines
4.4 KiB
Objective-C
Executable File

//
// SAIdentityAuthVC.m
// SamaVoice
//
// Created by bj_szd on 2022/5/27.
//
#import "SAIdentityAuthVC.h"
@interface SAIdentityAuthVC ()
@property (weak, nonatomic) IBOutlet UITextField *nameTF;
@property (weak, nonatomic) IBOutlet UITextField *IDCardTF;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
@end
@implementation SAIdentityAuthVC
- (void)viewDidLoad {
[super viewDidLoad];
[self showNaviBarWithTitle:@"认证中心"];
UIImageView *bgImgV = [[UIImageView alloc] initWithImage:ImageNamed(@"home_bg")];
[self.view insertSubview:bgImgV atIndex:0];
[bgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
make.height.mas_equalTo(ScreenWidth/375*812);
}];
[self.confirmBtn setJianBianWithCGSize:CGSizeMake(ScreenWidth-15*2, 44)];
self.nameTF.attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:@"请输入真实姓名" attributes:@{NSForegroundColorAttributeName:HEXCOLOR(0x999999)}];
self.IDCardTF.attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:@"请输入身份证号" attributes:@{NSForegroundColorAttributeName:HEXCOLOR(0x999999)}];
}
- (IBAction)onConfirm:(id)sender {
[self jieBangMethod];
}
//认证
- (void)jieBangMethod {
if (self.nameTF.text.length==0) {
[MBProgressHUD showAutoMessage:@"姓名不能为空"];
return;
}
if (self.IDCardTF.text.length==0) {
[MBProgressHUD showAutoMessage:@"身份证号不能为空"];
return;
}
// if (![self cly_verifyIDCardString:self.IDCardTF.text]) {
// [MBProgressHUD showAutoMessage:@"身份证号格式不正确,请重新填写"];
// return;
// }
NSDictionary *dict = @{@"real_name":self.nameTF.text,
@"card_id":self.IDCardTF.text};
NSMutableDictionary *paras = [NSMutableDictionary dictionary];
[paras addEntriesFromDictionary:dict];
[SVProgressHUD showWithStatus:nil];
[RCMicHTTP postWithURLString:@"/api/player/real_name_authentication" parameters:paras response:^(RCMicHTTPResult *result) {
[SVProgressHUD dismiss];
if (result.success) {
if (result.errorCode == 200) {
[MBProgressHUD showAutoMessage:@"提交身份成功!"];
[BJUserManager bj_refreshUserInfo:nil];
[self.navigationController popViewControllerAnimated:YES];
}else {
[SVProgressHUD showInfoWithStatus:result.message];
}
}else {
[SVProgressHUD showInfoWithStatus:@"网络错误"];
}
}];
}
/**
校验身份证号码是否正确 返回BOOL值
@param idCardString 身份证号码
@return 返回BOOL值 YES or NO
*/
- (BOOL)cly_verifyIDCardString:(NSString *)idCardString {
NSString *regex = @"^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL isRe = [predicate evaluateWithObject:idCardString];
if (!isRe) {
//身份证号码格式不对
return NO;
}
//加权因子 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2
NSArray *weightingArray = @[@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3", @"7", @"9", @"10", @"5", @"8", @"4", @"2"];
//校验码 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2
NSArray *verificationArray = @[@"1", @"0", @"10", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2"];
NSInteger sum = 0;//保存前17位各自乖以加权因子后的总和
for (int i = 0; i < weightingArray.count; i++) {//将前17位数字和加权因子相乘的结果相加
NSString *subStr = [idCardString substringWithRange:NSMakeRange(i, 1)];
sum += [subStr integerValue] * [weightingArray[i] integerValue];
}
NSInteger modNum = sum % 11;//总和除以11取余
NSString *idCardMod = verificationArray[modNum]; //根据余数取出校验码
NSString *idCardLast = [idCardString.uppercaseString substringFromIndex:17]; //获取身份证最后一位
if (modNum == 2) {//等于2时 idCardMod为10 身份证最后一位用X表示10
idCardMod = @"X";
}
if ([idCardLast isEqualToString:idCardMod]) { //身份证号码验证成功
return YES;
} else { //身份证号码验证失败
return NO;
}
}
@end