//
//  GreenChannelVC.m
//  Open
//
//  Created by 雷俊博 on 2019/7/10.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "GreenChannelVC.h"
#import "Constants.h"
#import "UIScrollView+UITouch.h"
#import "UIImage+Custom.h"

#import "GreenChannelImageView.h"

#import "AlertView.h"
#import <ZJAnimationPopView.h>


#import "successViewController.h"
#import "AuthenticationGuideView.h"
#import "CaijiShareAlertView.h"

#import "WXApi.h"
#import "KKUserIdentifyViewController.h"
#import "KKSocialAuthSuccessController.h"


@interface GreenChannelVC ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    NSInteger _selectIndex;
    
    UIImage *_lastImage;
}

@property (nonatomic, strong)UIScrollView *scrollView;
@property (nonatomic, strong)NSMutableArray *imagesArray;

@property (nonatomic, strong)UIButton *commitBtn;

//scrollview
@property (nonatomic, strong)UIView *topView;
@property (nonatomic, strong)GreenChannelImageView *cardView;

@property (nonatomic, strong)UILabel *lb_title;

@property (nonatomic, strong)UILabel *lb_remind;

@property (nonatomic, strong)UILabel *lb_five;

@property (nonatomic, strong)UIButton *btn_CustomerService;

@property (nonatomic, strong)UIImagePickerController *imagePicker;

@property (nonatomic, strong)AlertView *alertView;

@end

@implementation GreenChannelVC
#pragma mark - life cycle
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [GTCountSDK trackCountEvent:@"home_SBAuth_greenChannelPage" withArgs:@{}];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.commitBtn];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.imagesArray addObject:self.lastVCImage];
    [self.cardView.btn_left setBackgroundImage:self.lastVCImage forState:UIControlStateNormal];
    _lastImage = self.lastVCImage;
    
    //起点发生变化
    self.edgesForExtendedLayout=UIRectEdgeBottom;
    
    [self configBackBtn];
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(45 * WIDTHRADIU);
    }];
}


#pragma mark - 导航栏返回按钮及点击事件
- (void)configBackBtn
{
    UIButton *backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backbtn.frame = CGRectMake(-50, 0, 40, 40);
    [backbtn setTitle:@"返回" forState:UIControlStateNormal];
    [backbtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backbtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [backbtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:6];
    
    
    
    if (self.state == GreenRenZheng) {
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:backbtn];
        
        self.navigationItem.leftBarButtonItem = backItem;
    }
}

- (void)backBtnClick:(UIButton *)btn
{
   // BOOL show = [[NSUserDefaults standardUserDefaults]boolForKey:@"SocialSecurityAuthenticationggreenVC"];
    
    //if (!show) {
        [AuthenticationGuideView showGuideViewWithimgHidden:YES Block:^(BOOL isBack) {
           // [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"SocialSecurityAuthenticationggreenVC"];
            //[[NSUserDefaults standardUserDefaults]synchronize];
            if (isBack) {
                
                
                [self.navigationController popViewControllerAnimated:YES];
            }
        }];
   // }else {
     //   [self.navigationController popViewControllerAnimated:YES];
    //}
    
    
    
}


#pragma mark - event response
- (void)btnClick:(UIButton *)sender
{
    NSLog(@"%ld",sender.tag);
    if (sender == self.commitBtn) {
        if (self.state == GreenRenZheng) {
            [self uploadData];
        }else if(self.state == GreenCaiJi){

            [self uploadData2];
        }
        
    }else {
        if (self.imagesArray.count == 0 && sender == self.cardView.btn_right) {
            [SVProgressHUD showInfoWithStatus:@"请先拍摄第一张照片"];
            return;
        }
        _selectIndex = sender.tag;

        [self getPhoto];
    }
  
   
}

- (void)kehuchatClick:(UIButton *)sender
{
    
    //https://nginx.weface.com.cn/appH5/appoutlink/#/customer
    //tc.title = @"人工客服";
    

}
#pragma mark 处理自定义视图操作事件
- (void)handleCustomActionEnvent:(ZJAnimationPopView *)popView
{
    
}
#pragma mark - 绿色通道上传图片
- (void)uploadImageData {
    if (self.imagesArray.count < 2) {
        [SVProgressHUD showErrorWithStatus:@"要传2张自拍照片"];
        return;
    }
    NSString *path =@"";
    path =[IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/greenChannelVerify"];
    NSUserDefaults* userDefault=[NSUserDefaults standardUserDefaults];
    //雷俊博备注:这三个参数,是上个界面传过来,上个开发者将其存到本地;
     NSString *names =[userDefault objectForKey:@"name"];
    NSString *ID =[userDefault objectForKey:@"bak"];
    NSString *identifity =[userDefault objectForKey:@"identityNumber"];
    UIImage *lastImage = [UIImage imageWithCGImage:_lastImage.CGImage scale:1.0 orientation:UIImageOrientationUp];
    lastImage =  [UIImage imageByScalingAndCroppingForSize:CGSizeMake(360, 270) and:lastImage];
    NSData  *dateImage1 =UIImageJPEGRepresentation( lastImage,0.86);
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
    for (int i = 0; i < self.imagesArray.count; i++) {
        NSString * str = [self changeBase64:self.imagesArray[i]];
        [array addObject:str];
     }
    
    NSString *idPara = [Tools isBlankString:ID] ? @"" : ID;
    NSString *namePara = [Tools isBlankString:names] ? @"" : [EnercryTool A:names];
    NSString *identityPara = [Tools isBlankString:identifity] ? @"" : [EnercryTool A:identifity];
    NSString *imagePara = [EnercryTool encryptBase64:dateImage1];
    
    NSString *strPara = [NSString stringWithFormat:@"identityNumber=%@&name=%@&KkweInfo",identityPara,namePara];
    NSLog(@"%@",strPara);
    strPara =  [MyMD5 md5:strPara];
    
    NSString *senderPicPara = nil;
    
    if (array.count <1) {
        senderPicPara = @"";
    }else{
        senderPicPara = [array componentsJoinedByString:@","];
    }
    
    
    NSDictionary *params = @{
        @"flag":@2,
        @"id":idPara,
        @"name":namePara,
        @"identityNumber":identityPara,
        @"image":imagePara,
        @"sign":strPara,
        @"versionflag":@1,
//                             @"phoneNumber":telPhone,
        @"photoLstr":senderPicPara//1周 照片一逗号的形式隔开
    };
    [KKLoadingAnimationView show];
    [NetworkRequest SBAuthPost:path Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
    }];
    
}

//认证
- (void)uploadData
{
    if (self.imagesArray.count < 2) {
        [SVProgressHUD showErrorWithStatus:@"要传2张自拍照片"];
        return;
    }
    NSString *path =@"";
    path =[IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/greenChannelVerify"];
    NSUserDefaults* userDefault=[NSUserDefaults standardUserDefaults];
    //雷俊博备注:这三个参数,是上个界面传过来,上个开发者将其存到本地;
     NSString *names =[userDefault objectForKey:@"name"];
    NSString *ID =[userDefault objectForKey:@"bak"];
    NSString *identifity =[userDefault objectForKey:@"identityNumber"];
    UIImage *lastImage = [UIImage imageWithCGImage:_lastImage.CGImage scale:1.0 orientation:UIImageOrientationUp];
    lastImage =  [UIImage imageByScalingAndCroppingForSize:CGSizeMake(360, 270) and:lastImage];
    NSData  *dateImage1 =UIImageJPEGRepresentation( lastImage,0.86);
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
    for (int i = 0; i < self.imagesArray.count; i++) {
        NSString * str = [self changeBase64:self.imagesArray[i]];
        [array addObject:str];
     }
//    WeakSelf
    [KKLoadingAnimationView show];
    [CityNetManager  getaddressPhotoToThePath:path getID:ID FortheName:names theIdentityNumberPara:identifity image:dateImage1 andPhone:nil andArray:array completionHandle:^(verifyAdressModel *model, NSError *error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"当前线程%@",[NSThread currentThread]);
        
        
        if (error) {
            [SVProgressHUD showInfoWithStatus:@"网络异常"];
            return ;
        }
        if(model.code == 0)
        {
            
            [getPeopleID socialSate:1];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"ZLAuthenticationAssistant" object:nil userInfo:nil];
            
            if (model.RESULT) {
                
        
                NSData *dataBase64 =[[NSData alloc]initWithBase64EncodedString:model.RESULT options:0];
                UIImage *image = [UIImage imageWithData:dataBase64];
//                UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
//                successViewController *blueVC = [sb instantiateViewControllerWithIdentifier:@"successViewController"];
//                blueVC.imageView1 = self.imagesArray[0];
//                blueVC.imageView2 =image;
//                blueVC.name = self.ValidationName;
//                blueVC.idNumber = self.ValidationIdNumber;
//                blueVC.bak = self.bak;
//                blueVC.province = self.province;
//                blueVC.city = self.city;
//                blueVC.county = self.county;
//
//
//
//                [self.navigationController pushViewController:blueVC animated:YES];
                
                
                
                
                    KKSocialAuthSuccessController *blueVC = [KKSocialAuthSuccessController new];
                    blueVC.imageView1 = self.imagesArray[0];
                    blueVC.imageView2 = image;
                    blueVC.name = self.ValidationName;
                    blueVC.idNumber = self.ValidationIdNumber;
                    blueVC.bak = self.bak;
                    blueVC.province =self.province;
                    blueVC.city =self.city;
                    blueVC.county =self.county;
                    
                    
                
                    [self.navigationController pushViewController:blueVC animated:YES];
                
                return ;
                
                
                
                
            }
        }else if(model.code == 4 || model.code == 1012)
        {
            // 1.初始化
            ZJAnimationPopView *popView = [[ZJAnimationPopView alloc] initWithCustomView:self.alertView popStyle:ZJAnimationPopStyleScale dismissStyle:ZJAnimationDismissStyleScale];
            [self handleCustomActionEnvent:popView];
            __weak typeof(popView) weakPopView = popView;
            __weak typeof(self) weakSelf = self;
            self.alertView.canceSureActionBlock = ^(NSInteger tag) {
                
                [weakPopView dismiss];
                
                if (tag == 201) {
                    [weakSelf.cardView.btn_left setBackgroundImage:nil forState:UIControlStateNormal];
                    [weakSelf.cardView.btn_right setBackgroundImage:nil forState:UIControlStateNormal];
                    [weakSelf.imagesArray removeAllObjects];
                   self -> _lastImage = nil;
                    
                    [weakSelf btnClick:weakSelf.cardView.btn_left];
                }else if (tag == 200){
                    NSLog(@"进入人工审核界面");
                    UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    artificalViewController *artVC=[sb instantiateViewControllerWithIdentifier:@"artificalViewController"];
                    //留着
                    // artVC.failurePic = nil;
                    UIImage *image =weakSelf.imagesArray[0];
                   artVC.failurePic = image;
                    [weakSelf.navigationController pushViewController:artVC animated:YES];
                }
                
            };
            // 2.显示弹框
            [popView pop];
            return;
        }else if(model.code == 1015)
        {
            
            [SVProgressHUD showErrorWithStatus:@"您人脸数据未采集,请联系所在地社保部门"];
            return;
            
        }else if(model.code == 42){
            
            [SVProgressHUD showErrorWithStatus:@"请使用绿色通道"];
            return;
        }else if (model.code==28){//信息审核中
            UIAlertController *alertCon =[UIAlertController alertControllerWithTitle:@"信息正在审核中,请耐心等待!" message:nil preferredStyle:UIAlertControllerStyleAlert];
            [alertCon addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"%@",@"确定了!!!!!");
                for (UIViewController*vc in self.navigationController.viewControllers) {
                    if ([vc isKindOfClass:[KKUserIdentifyViewController class]]) {
                        KKUserIdentifyViewController*currentVC  = (KKUserIdentifyViewController *)vc;
                        [currentVC clearText];
                        [self.navigationController popToViewController:currentVC animated:YES];
                        break;
                    }
                }
             self.navigationController.navigationBar.translucent = YES;
                    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:27/255.0 green:132/255.0 blue:208/255.0 alpha:1.0]];
                if ([UIScreen mainScreen].bounds.size.height == 480) {
                    [self.navigationController setNavigationBarHidden:NO animated:YES];
                }
            }]];
            [self presentViewController:alertCon animated:YES completion:nil];
            return;
        }
        
        codeSelected *code = [codeSelected MustTakeReturn:model.code];
        [code returnCodeMethod];
    }];
    
}
//采集
- (void)uploadData2
{
    
    
    
   NSString *path =[IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/greenChannelInsert"];
    [KKLoadingAnimationView show];
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
    for (int i = 0; i < self.imagesArray.count; i++) {
        NSString * str = [self changImageBase64:self.imagesArray[i]];
        [array addObject:str];
    }
    [CityNetManager getSuccessSenderSocialMessageInsertInfo:path getName:self.social.nText privateStringIdentityNumber:self.social.idText andProvinceName:self.social.province.text andCityName:self.social.downTown.text andCountryName:self.social.area.text andTownName:self.social.village.text andvillageName:self.social.villageCommittee.text andTelephone:self.social.phoneNumber.text andCompanyName:self.social.Company.text andFlag:2 andVerifyType:self.social.ice andUimage:array ocrIMage:self.social.ocrBase64 ocrIMage_:self.social.ocrBase64_ completionHandle:^(verifyAdressModel * model, NSError * error) {
        [KKLoadingAnimationView dismiss];
        if(model.code == 0)
        {
            NSString *str =nil;
            if ([getPeopleID getpeopleLimited]  ==YES) {
                
                str =[NSString stringWithFormat:@"%@,采集成功",self.social.nameText.text];
            }else{
                
                str =[NSString stringWithFormat:@"%@,采集成功,请等待5个工作日审核身份，通过后，进行社保身份认证，认证通过后可正常领取养老金",self.social.nameText.text];
            }
            
            if ([model.bak isEqualToString:@"0"]) {
                str = nil;
                str =@"仅识别出一张人脸,按返回重新采集";
                UIAlertController *alertCon =[UIAlertController alertControllerWithTitle:str message:nil preferredStyle:UIAlertControllerStyleAlert];
                [alertCon addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                }]];
                
                [self presentViewController:alertCon animated:YES completion:nil];
                return;
            }else if ([model.bak isEqualToString:@"1"]){
                str = nil;
                str =@"仅识别出一张人脸,按返回重新采集";
                UIAlertController *alertCon =[UIAlertController alertControllerWithTitle:str message:nil preferredStyle:UIAlertControllerStyleAlert];
                [alertCon addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                }]];
                
                [self presentViewController:alertCon animated:YES completion:nil];
            }else if ([model.bak isEqualToString:@"2"]){
                    __weak typeof(self) weakSelf = self;
                
                [CaijiShareAlertView showAlertViewWithVC:self name:self.social.nameText.text  address:[NSString stringWithFormat:@"%@%@%@",self.social.province.text,self.social.downTown.text,self.social.area.text] block:^(CaiJiShareButtonType type) {
                    if (type == CaiJiShareButtonTypeWX) {
                        [weakSelf shareWebPageToPlatformType:UMSocialPlatformType_WechatSession];
                    }else if (type == CaiJiShareButtonTypeFriend){
                        [weakSelf shareWebPageToPlatformType:UMSocialPlatformType_WechatTimeLine];
                    }else if (type == CaiJiShareButtonTypeBack){
                        //2017年11月23日注释了
                       weakSelf.social.ocrBase64=nil;
                       weakSelf.social.ocrBase64_ =nil;
                       weakSelf.social.phoneNumber.text =@"";
                       [weakSelf.navigationController popToRootViewControllerAnimated:YES];
                    }
                }];
                
               
                
                
            }
            
           
        }else
        {
            
            codeSelected *code = [codeSelected MustTakeReturn:model.code];
            [code returnCodeMethod];
            return;
        }
    }];
}

- (void)getPhoto
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请选择获取图片操作" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    // 使用前置还是后置摄像头
    
//    UIAlertAction *photos = [UIAlertAction actionWithTitle:@"从相册中" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        self.imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
//        [self presentViewController:self.imagePicker animated:YES completion:nil];
//        
//    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *makePhotos = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
        self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        [self presentViewController: self.imagePicker animated:YES completion:nil];
     
    }];
    //[alert addAction:photos];
    [alert addAction:makePhotos];
    [alert addAction:cancel];
    
    [self presentViewController:alert animated:YES completion:^{
        
    }];
}



#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController: (UIImagePickerController *)picker
didFinishPickingMediaWithInfo: (NSDictionary *)info
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
          if (self.imagesArray.count == 2) {
              if (self->_selectIndex == 200) {
                  self->_lastImage = image;
                  [self.imagesArray replaceObjectAtIndex:0 withObject:image];
              }else if (self->_selectIndex == 201){
                  [self.imagesArray replaceObjectAtIndex:1 withObject:image];
              }
          }else if (self.imagesArray.count == 1){
              if (self->_selectIndex == 200) {
                  self->_lastImage = image;
                  [self.imagesArray replaceObjectAtIndex:0 withObject:image];
              }else if (self->_selectIndex == 201){
                  [self.imagesArray addObject:image];
              }
          }else if (self.imagesArray.count == 0){
              if (self->_selectIndex == 200) {
                  self->_lastImage = image;
                  [self.imagesArray addObject:image];
              }
          }
          
          
        if (self->_selectIndex == 200) {
              [self.cardView.btn_left setBackgroundImage:image forState:UIControlStateNormal];
          }else{
              [self.cardView.btn_right setBackgroundImage:image forState:UIControlStateNormal];
          }
          [self dismissViewControllerAnimated:YES completion:nil];
    });
  
}

// 用户选择取消
- (void) imagePickerControllerDidCancel: (UIImagePickerController *)picker
{
   [self dismissViewControllerAnimated:YES completion:nil];
   
}


#pragma mark - 分享
//网页分享
- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    if (![WXApi isWXAppInstalled]) {
        [Tools showMessage:@"请先安装微信!!!"];
        return;
    }
    
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    //创建网页内容对象
    NSString* thumbURL =  UMS_THUMB_IMAGE;
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:UMS_Title descr:UMS_Text thumImage:thumbURL];
    //设置网页地址
    shareObject.webpageUrl = UMS_WebLink;
    
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
        [self alertWithError:error];
    }];
}


- (void)alertWithError:(NSError *)error
{
    NSString *result = nil;
    if (!error) {
        result = [NSString stringWithFormat:@"分享成功"];
    }
    else{
        NSMutableString *str = [NSMutableString string];
        if (error.userInfo) {
            for (NSString *key in error.userInfo) {
                [str appendFormat:@"%@ = %@\n", key, error.userInfo[key]];
            }
        }
        if (error) {
            result = [NSString stringWithFormat:@"Share fail with error code: %d\n%@",(int)error.code, str];
            result = [NSString stringWithFormat:@"分享失败"];
        }
        else{
            result = [NSString stringWithFormat:@"Share fail"];
        }
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:result
                                                   delegate:nil
                                          cancelButtonTitle:NSLocalizedString(@"确定", @"确定")
                                          otherButtonTitles:nil];
    [alert show];
}


#pragma mark - private methods
-(NSString *)changeBase64:(UIImage*)image
{
    CGSize imagesize = image.size;
    NSLog(@"%lf",image.size.height);
    NSLog(@"%lf",image.size.width);
    imagesize.height =50;
    imagesize.width =50;
    //对图片大小进行压缩--
    
    //    UIImage *image1=   [SecondSocialViewController imageCompressFitSizeScale:image targetSize:CGSizeMake(image.size.width/4, image.size.height/4)];
    
    UIImage *image1=    [UIImage imageByScalingAndCroppingForSize:CGSizeMake(483, 644) and:image];
    //照片是对的完全没有问题,如果想加快速度必须让戴海峰配合的去弄,否则毫无办法,因为把他放在网上转base64是可以转出来的,如果想提速只要调用上面的这个方法即可.否则毫无办法,上面两个方法都是可以的
    //这里的0.3决定了照片认证的精确值
    image1 =   [SecondSocialViewController image:image1 rotation:UIImageOrientationLeft];
    NSData *str2=UIImageJPEGRepresentation(image1, 0.4);
    
   
    NSString *str3=[EnercryTool encryptBase64:str2];

   
    return str3;
    
}




#pragma mark - getters and setters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - 45 * WIDTHRADIU)];
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.contentSize = CGSizeMake(ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - 45 * WIDTHRADIU);
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        [_scrollView addSubview:self.topView];
        [_scrollView addSubview:self.cardView];
        [_scrollView addSubview:self.lb_title];
        [_scrollView addSubview:self.lb_remind];
        [_scrollView addSubview:self.lb_five];
        [_scrollView addSubview:self.btn_CustomerService];
        [self setupUI];
    }
    return _scrollView;
}

- (void)setupUI
{
    [self.lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cardView.mas_bottom).offset(35 * WIDTHRADIU);
        make.left.offset(20 * WIDTHRADIU);
        make.height.offset(16 * WIDTHRADIU);
    }];
    [self.lb_remind mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_title.mas_bottom).offset(18 * WIDTHRADIU);
        make.left.equalTo(self.lb_title);
        make.right.equalTo( self.cardView);
    }];
    [self.lb_five mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_remind.mas_bottom).offset(10 * WIDTHRADIU);
        make.left.equalTo(self.lb_remind);
        make.height.offset(14 * WIDTHRADIU);
    }];
    [self.btn_CustomerService mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lb_five);
        make.left.equalTo(self.lb_five.mas_right).offset(10);
    }];
}
- (UIView *)topView
{
    if (!_topView) {
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width, 125 * WIDTHRADIU)];
        _topView.backgroundColor = K_MainColor;
    }
    return _topView;
}

- (UIButton *)commitBtn
{
    if (!_commitBtn) {
        _commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _commitBtn.backgroundColor = [UIColor colorWithHex:0x11a480];
        [_commitBtn setTitle:@"确认提交" forState:UIControlStateNormal];
        _commitBtn.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_commitBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _commitBtn;
}

- (GreenChannelImageView *)cardView
{
    if (!_cardView) {
        _cardView = [[GreenChannelImageView alloc]initWithFrame:CGRectMake(10 * WIDTHRADIU, 20 * WIDTHRADIU, ScreenWidth - 20 * WIDTHRADIU, 237 * WIDTHRADIU)];
        _cardView.backgroundColor = [UIColor whiteColor];
        _cardView.layer.cornerRadius = 10 * WIDTHRADIU;
        _cardView.layer.shadowColor = RGBCOLOR(23, 123, 205).CGColor;
        _cardView.layer.shadowOffset = CGSizeMake(0, 0);
        _cardView.layer.shadowOpacity = 0.25;
        _cardView.layer.shadowRadius = 2.0;
        [_cardView.btn_left addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_cardView.btn_right addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cardView;
}

- (UILabel *)lb_title
{
    if (!_lb_title) {
        _lb_title = [[UILabel alloc]init];
        _lb_title.text = @"绿色通道:";
        _lb_title.font = [UIFont systemFontOfSize:16 * WIDTHRADIU];
        _lb_title.textColor = [UIColor colorWithHex:0x808080];
        _lb_title.numberOfLines = 0;
    }
    return _lb_title;
}

- (UILabel *)lb_remind
{
    if (!_lb_remind) {
        _lb_remind = [[UILabel alloc]init];
        NSString *text1 = @"1、生病人群（如：卧床不起、重大疾病）等其他特殊人群;\n";
        NSString *text2 = @"2、80岁以上老人、退伍军人;\n";
        NSString *text3 = @"3、正视摄像头，注意光线和角度，确保人脸清晰度;\n";
        NSString *text4 = @"4、拍摄两张正面照片;";
        
        NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:10 * WIDTHRADIU];
        
        NSMutableAttributedString *attributedString1 = [[NSMutableAttributedString alloc] initWithString:text1 attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
        NSMutableAttributedString *attributedString2 = [[NSMutableAttributedString alloc] initWithString:text2 attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
        NSMutableAttributedString *attributedString3 = [[NSMutableAttributedString alloc] initWithString:text3 attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
         NSMutableAttributedString *attributedString4 = [[NSMutableAttributedString alloc] initWithString:text4 attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
        [attributedString1 appendAttributedString:attributedString2];
        [attributedString1 appendAttributedString:attributedString3];
        [attributedString1 appendAttributedString:attributedString4];
        
        NSRange range = [[[[text1 stringByAppendingString:text2] stringByAppendingString:text3] stringByAppendingString:text4] rangeOfString:[[[text1 stringByAppendingString:text2] stringByAppendingString:text3] stringByAppendingString:text4]];
        [attributedString1 addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x999999],
                                           NSFontAttributeName:[UIFont systemFontOfSize:14 * WIDTHRADIU]} range:range];
        _lb_remind.attributedText = attributedString1;
        _lb_remind.numberOfLines = 0;
    }
    return _lb_remind;
}
- (UILabel *)lb_five
{
    if (!_lb_five) {
        _lb_five = [[UILabel alloc]init];
        _lb_five.text = @"5、有疑问请联系人工客服。";
        _lb_five.font = [UIFont systemFontOfSize:14 * WIDTHRADIU
                         ];
        _lb_five.textColor = [UIColor colorWithHex:0x999999];
    }
    return _lb_five;
}

- (UIButton *)btn_CustomerService
{
    if (!_btn_CustomerService) {
        _btn_CustomerService = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_CustomerService setImage:[UIImage imageNamed:@"Greenchannel_customerserviceicon_normal"] forState:UIControlStateNormal];
        [_btn_CustomerService setTitle:@"转人工咨询" forState:UIControlStateNormal];
        _btn_CustomerService.titleLabel.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        [_btn_CustomerService setTitleColor:K_MainColor forState:UIControlStateNormal];
        [_btn_CustomerService layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4 * WIDTHRADIU];
        [_btn_CustomerService addTarget:self action:@selector(kehuchatClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_CustomerService;
}

- (UIImagePickerController *)imagePicker
{
    if (!_imagePicker) {
        _imagePicker = [[UIImagePickerController alloc]init];
        _imagePicker.delegate = self;
        _imagePicker.allowsEditing = YES;
        
        
    }
    
    return _imagePicker;
}

- (NSMutableArray *)imagesArray
{
    if (!_imagesArray) {
        _imagesArray = [[NSMutableArray alloc]initWithCapacity:2];
        
    }
    return _imagesArray;
}

- (AlertView *)alertView
{
    if (!_alertView) {
        _alertView = [[AlertView alloc]initWithFrame:CGRectMake(0, 0, 230 * WIDTHRADIU, 161 * WIDTHRADIU)];
    }
    return _alertView;
}
/*
#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
