//图片上传
- (void)upLoadImage{
if(self.frontImage && self.backImage){
//性别
NSString *sexStr;
if ([sex.textField.text isEqualToString:@"男"]) {
sexStr = @"1";
}else if ([sex.textField.text isEqualToString:@"女"]){
sexStr = @"2";
}
//有效期
NSMutableString *effactStr = [NSMutableString stringWithFormat:@"%@-%@",beginString,endString];
[effactStr insertString:@"." atIndex:4];
[effactStr insertString:@"." atIndex:7];
[effactStr insertString:@"." atIndex:15];
[effactStr insertString:@"." atIndex:18];
NSDictionary *param =@{
@"customerNo":self.registerDict[@"result"][@"cusNo"],//客户号
@"customerName":userName.textField.text,//姓名
@"sex":sexStr,//性别
@"nationality":nation.textField.text,//民族
@"birth":birthdayStr,//出生日期
@"address":address.textView.text,//地址
@"idcardNo":idNo.textField.text,//身份证号
@"department":government.textField.text,//签发机关
@"validity":effactStr,//有效期
};
NSString *strparam =[param JSONFragment];
NSDictionary *parameters =@{@"param": strparam};
NSString *posturl =[NSString stringWithFormat:@"%@%@",SERVERURL,@"ocrIdUploadAction.action"];
YGWeakSelf
[self.manager POST:posturl parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//使用日期生成图片名称
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyyMMddHHmmssSSS";
NSString *fileName = [NSString stringWithFormat:@"%@.png",[formatter stringFromDate:[NSDate date]]];
//取出正面的图片
//NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"first.png"];
//UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath];
NSData *frontData = UIImagePNGRepresentation(self.frontImage);
[formData appendPartWithFileData:frontData name:@"upFile" fileName:fileName mimeType:@"image/png"];
//使用日期生成图片名称
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
formatter2.dateFormat = @"yyyyMMddHHmmssSSS";
NSString *fileName2 = [NSString stringWithFormat:@"%@.png",[formatter2 stringFromDate:[NSDate date]]];
//取出反面的图片
// NSString *fullPath2 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"second.png"];
// UIImage *savedImage2 = [[UIImage alloc] initWithContentsOfFile:fullPath2];
NSData *frontData2 = UIImagePNGRepresentation(self.backImage);
[formData appendPartWithFileData:frontData2 name:@"upFile" fileName:fileName2 mimeType:@"image/png"];
} success:^(NSURLSessionDataTask *task, id responseObject) {
//{
// result = "";
// success = 1;
//}
[ProgressHUD dismiss];
//上传图片成功执行回调
RbindCardViewController *bindCarVC = [[RbindCardViewController alloc] init];
bindCarVC.myHuixianDic = messageDic;
bindCarVC.myResultDic = weakSelf.registerDict;
[weakSelf.navigationController pushViewController:bindCarVC animated:YES];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
[ProgressHUD dismiss];
//上传图片失败执行回调
RbindCardViewController *bindCarVC = [[RbindCardViewController alloc] init];
bindCarVC.myHuixianDic = messageDic;
bindCarVC.myResultDic = weakSelf.registerDict;
[weakSelf.navigationController pushViewController:bindCarVC animated:YES];
}];
}else{
RbindCardViewController *bindCarVC = [[RbindCardViewController alloc] init];
bindCarVC.myHuixianDic = messageDic;
bindCarVC.myResultDic = self.registerDict;
[self.navigationController pushViewController:bindCarVC animated:YES];
}
}