RealNameAuthenticationViewController.m
12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
//
// RealNameAuthenticationViewController.m
// IVTMeLiveTwo
//
// Created by XRG on 16/9/5.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "RealNameAuthenticationViewController.h"
#import "AppDelegate.h"
#import "NSString+IVTMeString.h"
@interface RealNameAuthenticationViewController ()<UITextFieldDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
{
UIButton *currentButton;
NSData *imageData1;
NSData *imageData2;
NSData *imageData3;
}
@property (weak, nonatomic) IBOutlet UIScrollView *myScrollView;
@property (weak, nonatomic) IBOutlet UITextField *realNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *phoneNumberTextField;
@property (weak, nonatomic) IBOutlet UITextField *iCardNumberTextField;
@property (weak, nonatomic) IBOutlet UIButton *image1Button;
@property (weak, nonatomic) IBOutlet UIButton *referenceToButton;
@property (weak, nonatomic) IBOutlet UIButton *image2Button;
@property (weak, nonatomic) IBOutlet UIButton *image3Button;
@property (weak, nonatomic) IBOutlet UIButton *submitButton;
@property (strong, nonatomic) IBOutlet UIView *rejectView;
@property (weak, nonatomic) IBOutlet UILabel *rejectReasonLabel;
@property (strong, nonatomic) IBOutlet UIView *authenticationingView;
@property (strong, nonatomic) IBOutlet UIView *authenticationPostView;
@property (strong, nonatomic) IBOutlet UIView *referenceView;
@end
@implementation RealNameAuthenticationViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"认证";
self.myScrollView.hidden = YES;
[self doRequest];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
}
- (void)textFieldDidChange:(NSNotification *)notification{
UITextField *obj = notification.object;
if ([obj isEqual:self.realNameTextField]) {
if (obj.text.length > 10) {
obj.text = [obj.text substringToIndex:10];
}
}
else if ([obj isEqual:self.phoneNumberTextField]){
if (obj.text.length > 11) {
obj.text = [obj.text substringToIndex:11];
}
}
else if ([obj isEqual:self.iCardNumberTextField]){
if (obj.text.length > 18) {
obj.text = [obj.text substringToIndex:18];
}
}
}
- (IBAction)doTap:(id)sender {
[self.view endEditing:YES];
}
- (void)doRequest{
[HUDUtil showLoading];
[[IVTNetworkAPIClient sharedClient] getRealNameAuthenticationStatusSuccess:^(NSDictionary *successData) {
[HUDUtil hide];
// NSDictionary *dict = successData[@"checkInfoList"];
// if (dict) {
// NSInteger flag = [[dict valueForKey:@"isChecked"] integerValue];
// if (flag == 0) {
// self.myScrollView.hidden = YES;
// [self.authenticationingView removeFromSuperview];
// [self.authenticationPostView removeFromSuperview];
// self.rejectView.frame = CGRectMake(0, 100, kScreenWidth, 230);
// [self.view addSubview:self.rejectView];
// self.rejectReasonLabel.text = dict[@"reason"];
//// 0:未通过;1:通过;2:未审核
// }
// else if (flag == 1){
// self.myScrollView.hidden = YES;
// [self.authenticationingView removeFromSuperview];
// [self.rejectView removeFromSuperview];
// self.authenticationPostView.frame = CGRectMake(0, 100, kScreenWidth, 80);
// [self.view addSubview:self.authenticationPostView];
// }
// else if (flag == 2){
// self.myScrollView.hidden = YES;
// [self.authenticationPostView removeFromSuperview];
// [self.rejectView removeFromSuperview];
// self.authenticationingView.frame = CGRectMake(0, 100, kScreenWidth, 65);
// [self.view addSubview:self.authenticationingView];
// }
// }
// else{
self.myScrollView.hidden = NO;
[self.authenticationPostView removeFromSuperview];
[self.rejectView removeFromSuperview];
[self.authenticationingView removeFromSuperview];
// }
} error:^(NSDictionary *successData) {
NSString *msg = successData[@"description"];
[HUDUtil showError:msg];
} failure:^(NSError *failureError) {
[HUDUtil showError:@"网络异常"];
}];
}
- (IBAction)doImage1Button:(id)sender {
currentButton = self.image1Button;
[self photoClick];
}
- (IBAction)doReferenceToButton:(id)sender {
self.referenceView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
[[AppDelegate appDelegate].window addSubview:self.referenceView];
}
- (IBAction)hiddenReferenceView:(id)sender {
[self.referenceView removeFromSuperview];
}
- (IBAction)doImage2Button:(id)sender {
currentButton = self.image2Button;
[self photoClick];
}
- (IBAction)doImage3Button:(id)sender {
currentButton = self.image3Button;
[self photoClick];
}
- (void)photoClick{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (![UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] && ![UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"没找到摄像头" preferredStyle:UIAlertControllerStyleAlert];
[alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alertC animated:YES completion:^{
}];
}
else{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePicker animated:YES completion:nil];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alert animated:YES completion:^{
}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
UIImage *imagePicker = info[@"UIImagePickerControllerEditedImage"];
if ([currentButton isEqual:self.image1Button]) {
imageData1 = UIImageJPEGRepresentation(imagePicker, 0.4);
UIImage *image = [UIImage imageWithData:imageData1];
[self.image1Button setImage:image forState:UIControlStateNormal];
}
else if ([currentButton isEqual:self.image2Button]){
imageData2 = UIImageJPEGRepresentation(imagePicker, 0.4);
UIImage *image = [UIImage imageWithData:imageData2];
[self.image2Button setImage:image forState:UIControlStateNormal];
}
else if ([currentButton isEqual:self.image3Button]){
imageData3 = UIImageJPEGRepresentation(imagePicker, 0.4);
UIImage *image = [UIImage imageWithData:imageData3];
[self.image3Button setImage:image forState:UIControlStateNormal];
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)doSubmitButton:(id)sender {
if (self.realNameTextField.text != nil && self.phoneNumberTextField.text != nil && self.iCardNumberTextField.text != nil && imageData1 != nil && imageData2 != nil && imageData3 != nil) {
if (![self.realNameTextField.text isChinaName]) {
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请正确输入姓名" preferredStyle:UIAlertControllerStyleAlert];
[alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self.navigationController presentViewController:alertC animated:YES completion:nil];
return;
}
if (![self.phoneNumberTextField.text isMobileNumber]) {
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请正确输入手机号" preferredStyle:UIAlertControllerStyleAlert];
[alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self.navigationController presentViewController:alertC animated:YES completion:nil];
return;
}
if (![self.iCardNumberTextField.text accurateVerifyIDCardNumber]) {
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请正确输入身份证号码" preferredStyle:UIAlertControllerStyleAlert];
[alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self.navigationController presentViewController:alertC animated:YES completion:nil];
return;
}
[HUDUtil showLoading];
[[IVTNetworkAPIClient sharedClient] submitRealNameAuthenticationWithRealName:self.realNameTextField.text contact:self.phoneNumberTextField.text idCard:self.iCardNumberTextField.text handCardFile:imageData1 cardFileFront:imageData2 cardFileBack:imageData3 success:^(NSDictionary *successData) {
[HUDUtil showSuccess:@"认证成功"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} error:^(NSDictionary *successData) {
NSString *msg = successData[@"description"];
[HUDUtil showError:msg];
} failure:^(NSError *failureError) {
[HUDUtil showError:@"网络异常"];
}];
}
else{
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请正确输入认证信息" preferredStyle:UIAlertControllerStyleAlert];
[alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self.navigationController presentViewController:alertC animated:YES completion:nil];
}
}
- (IBAction)doReSubmitButton:(id)sender {
self.myScrollView.hidden = NO;
[self.authenticationPostView removeFromSuperview];
[self.rejectView removeFromSuperview];
[self.authenticationingView removeFromSuperview];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end