上传身份证照片获取姓名和身份证号
在项目中做了一个上传身份证正面 之后可以默认填写 姓名和身份证号的功能 来分享一下
1.用到的接口 http://api2.juheapi.com/cardrecon/upload
2.废话就不说了直接上代码了 我用的是AFNetworking 请求的例子
1 #pragma mark - 数据请求返回信息 2 -(void)upLoadImageViewCheck{ 3 WS(weakSelf); 4 NSDictionary *dic = [NSMutableDictionary dictionary]; 5 [dic setValue:@"d839f530d3792eaca4b3393918a57475" forKey:@"key"]; 6 [dic setValue:@"2" forKey:@"cardType"]; 7 [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES]; 8 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 9 /// 请求的头设置 10 manager.requestSerializer = [AFJSONRequestSerializer serializer]; 11 manager.responseSerializer = [AFJSONResponseSerializer serializer]; 12 manager.requestSerializer.timeoutInterval =10.0f; 13 [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; 14 [manager.requestSerializer setValue:@"application/json; encoding=utf-8" forHTTPHeaderField:@"Content-Type"]; 15 16 NSString *url = [NSString stringWithFormat:@"%@",@"http://api2.juheapi.com/cardrecon/upload"]; 17 18 [manager POST:url parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { 19 20 NSData *data = [self compressImage:_cardImageBtn.currentImage toMaxFileSize:200]; 21 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 22 formatter.dateFormat = @"yyyyMMddHHmmss"; 23 NSString *str = [formatter stringFromDate:[NSDate date]]; 24 NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str]; 25 [formData appendPartWithFileData:data name:@"pic" fileName:fileName mimeType:@"image/jpg"]; 26 27 } success:^(AFHTTPRequestOperation *operation, id responseObject) { 28 [MBProgressHUD hideAllHUDsForView:KeyWindow animated:YES]; 29 30 if ([[responseObject valueForKey:@"error_code"] integerValue] ==0) { 31 NSDictionary *results = [responseObject valueForKey:@"result"]; 32 _nameField.text = [results allValues][0]; 33 _cardField.text = [results allValues][3]; 34 // [weakSelf hideOrShowThings:NO]; 35 36 } 37 else{ 38 [StringInittal showTextOnlyView:KeyWindow andMessage:@"请手动填写姓名和身份证号"]; 39 } 40 } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 41 [MBProgressHUD hideAllHUDsForView:KeyWindow animated:YES]; 42 [StringInittal showTextOnlyView:KeyWindow andMessage:@"请手动填写姓名和身份证号"]; 43 }]; 44 45 }
3.如看详细信息 请参考https://www.juhe.cn/docs/api/id/153/aid/493