//
//  SMSVerificationController.m
//  Open
//
//  Created by 雷俊博 on 2020/7/30.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import <MobileCoreServices/MobileCoreServices.h>

#import "SMSVerificationController.h"
#import "UIView+frameAdjust.h"
#import "SMSVerificationTopView.h"
#import "ElectAccountOPenSuccessController.h"
#import "RechargeSuccessController.h"
#import "SaveSettingSuccessController.h"

#import "ElectronicAccountController.h"

#import "OPenAccountController.h"

#import "BCRegistInfoModel.h"

#import "BCBuyResultModel.h"
#import "BCRechargeSignAlertView.h"
#import "SignPasswayController.h"
#import "ProductRechargeController.h"
#import "BCRechargeFinishController.h"

#define TIMECOUNT 60
@interface SMSVerificationController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    NSString*SMS_SEQ;
    
    NSString*videoStr;
    NSString*fileName;
}

@property (nonatomic, strong)UIScrollView* scrollView;

@property (nonatomic, strong)SMSVerificationTopView* topView;

@property (nonatomic, copy)NSString*FUNCTION;

@property (nonatomic, copy)NSString*reqSerial;//比财充值交易流水号

@property (nonatomic, copy)NSString* preBankAccountNo;


@end

@implementation SMSVerificationController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:0 target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:bar];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.scrollView];
    
    
    if (self.type == SMSSendTypeBCSystemIdentify || self.type == SMSSendTypeBCOpenAccount) {
        [self timeCount];
    }else{
        [self smsBtnClick:self.topView.smsBtn];
    }
    
    
    
    
}

#pragma mark - 短信按钮倒计时
- (void)timeCount {
    __block NSInteger second = TIMECOUNT;
               //(1)
               dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
               //(2)
               dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quene);
               //(3)
               dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
               //(4)
               dispatch_source_set_event_handler(timer, ^{
                   dispatch_async(dispatch_get_main_queue(), ^{
                       if (second == 0) {
                           self.topView.smsBtn.userInteractionEnabled = YES;
                           self.topView.smsBtn.titleLabel.text = @"获取验证码";
                           [self.topView.smsBtn setTitle:[NSString stringWithFormat:@"获取验证码"] forState:UIControlStateNormal];
                           [self.topView.smsBtn setTitleColor:RGBCOLOR(23, 123, 206) forState:UIControlStateNormal];
                           second = TIMECOUNT;
                           //(6)
                           dispatch_cancel(timer);
                       } else {
                           self.topView.smsBtn.userInteractionEnabled = NO;
                           self.topView.smsBtn.titleLabel.text = [NSString stringWithFormat:@"重新发送(%ld)",(long)second];
                           [self.topView.smsBtn setTitle:[NSString stringWithFormat:@"重新发送(%ld)",(long)second] forState:UIControlStateNormal];
                             [self.topView.smsBtn setTitleColor:RGBCOLOR(197, 197, 197) forState:UIControlStateNormal];
                           second--;
                       }
                   });
               });
               //(5)
               dispatch_resume(timer);
}

#pragma mark - 开户发短信请求
- (void)openAccountSMSRequest:(UIButton *)sender
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],AccountSMSRequest];
    
    NSDictionary*params = @{
        @"tel":self.prePhone,
    };
    
    NSLog(@"银数开户发短信url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    WeakSelf
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        NSString* describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            self->SMS_SEQ = [NSString stringWithFormat:@"%@",dic[@"SMS_SEQ"]];
            __block NSInteger second = TIMECOUNT;
                       //(1)
                       dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                       //(2)
                       dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quene);
                       //(3)
                       dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
                       //(4)
                       dispatch_source_set_event_handler(timer, ^{
                           dispatch_async(dispatch_get_main_queue(), ^{
                               if (second == 0) {
                                   sender.userInteractionEnabled = YES;
                                   sender.titleLabel.text = @"获取验证码";
                                   [sender setTitle:[NSString stringWithFormat:@"获取验证码"] forState:UIControlStateNormal];
                                   [sender setTitleColor:RGBCOLOR(23, 123, 206) forState:UIControlStateNormal];
                                   second = TIMECOUNT;
                                   //(6)
                                   dispatch_cancel(timer);
                               } else {
                                   sender.userInteractionEnabled = NO;
                                   sender.titleLabel.text = [NSString stringWithFormat:@"重新发送(%ld)",(long)second];
                                   [sender setTitle:[NSString stringWithFormat:@"重新发送(%ld)",(long)second] forState:UIControlStateNormal];
                                     [sender setTitleColor:RGBCOLOR(197, 197, 197) forState:UIControlStateNormal];
                                   second--;
                               }
                           });
                       });
                       //(5)
                       dispatch_resume(timer);
                       
                       [weakSelf.topView layoutIfNeeded];
               
        }else{
            NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
            NSLog(@"describe:%@",dic);
            NSString*code = nil;
            NSString*message = nil;
            if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                code = [NSString stringWithFormat:@"%@",dic[@"code"]];
            }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
            }
            
            if (code) {
                message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                
                if (message) {
                    [SVProgressHUD showErrorWithStatus:message];
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
         [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}


#pragma mark - 交易发短信请求
- (void)transactionSMSRequest:(UIButton *)sender
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],UserSMSRequest];
     SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
    NSString*acctNo = nil;
    NSString*tel = nil;
    if (self.type == SMSSendTypeRecharge) {
        acctNo = [Tools isBlankString:subModel.SIGCARD] ?@"" :subModel.SIGCARD;
        tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
    }else if (self.type == SMSSendTypeProPurchase){
        acctNo = [Tools isBlankString:subModel.CARDNBR] ?@"" :subModel.CARDNBR;
        tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
    }else if (self.type == SMSSendTypeWithDrawal){
        acctNo = [Tools isBlankString:subModel.SIGCARD] ?@"" :subModel.SIGCARD;
        tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
    }else if (self.type == SMSSendTypeProRedeem){
        acctNo = [Tools isBlankString:self.detailModel.ACCT_NO] ?@"" :self.detailModel.ACCT_NO;
        tel = [Tools isBlankString:self.buyedProModel.tel] ?@"" :self.buyedProModel.tel;
    }else if (self.type == SMSSendTypePhoneModtify){
        acctNo = [Tools isBlankString:subModel.SIGCARD] ?@"" :subModel.SIGCARD;
        tel = self.phone;
    }else if (self.type == SMSSendTypeTypeBindCardModify){
        acctNo = [Tools isBlankString:self.nBindCard] ?@"" :self.nBindCard;
        tel = subModel.MO_PHONE;
    }
     
    NSDictionary*params = @{
        @"accNo":acctNo,
        @"tel":tel,
        @"name":self.FUNCTION
    };
    
    NSLog(@"银数交易发短信url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    WeakSelf
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        NSString* describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            self->SMS_SEQ = [NSString stringWithFormat:@"%@",dic[@"SMS_SEQ"]];
            __block NSInteger second = TIMECOUNT;
                       //(1)
                       dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                       //(2)
                       dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quene);
                       //(3)
                       dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
                       //(4)
                       dispatch_source_set_event_handler(timer, ^{
                           dispatch_async(dispatch_get_main_queue(), ^{
                               if (second == 0) {
                                   sender.userInteractionEnabled = YES;
                                   sender.titleLabel.text = @"获取验证码";
                                   [sender setTitle:[NSString stringWithFormat:@"获取验证码"] forState:UIControlStateNormal];
                                   [sender setTitleColor:RGBCOLOR(23, 123, 206) forState:UIControlStateNormal];
                                   second = TIMECOUNT;
                                   //(6)
                                   dispatch_cancel(timer);
                               } else {
                                   sender.userInteractionEnabled = NO;
                                   sender.titleLabel.text = [NSString stringWithFormat:@"重新发送(%ld)",(long)second];
                                   [sender setTitle:[NSString stringWithFormat:@"重新发送(%ld)",(long)second] forState:UIControlStateNormal];
                                     [sender setTitleColor:RGBCOLOR(197, 197, 197) forState:UIControlStateNormal];
                                   second--;
                               }
                           });
                       });
                       //(5)
                       dispatch_resume(timer);
                       
                       [weakSelf.topView layoutIfNeeded];
               
        }else{
           NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
            NSLog(@"describe:%@",dic);
            NSString*code = nil;
            NSString*message = nil;
            if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                code = [NSString stringWithFormat:@"%@",dic[@"code"]];
            }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
            }
            
            if (code) {
                message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                
                if (message) {
                    [SVProgressHUD showErrorWithStatus:message];
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
         [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}


#pragma mark - 购买产品请求
- (void)buyProductRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSBuyProductRequest];
    
    SaveAccountSubUserInfoModel*infoModel = self.infoModel.SUBPACKS[0];
    
    NSString*value = [self.amount stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    int amount = value.intValue;
    NSDictionary*params = @{
        @"acctNo": infoModel.CARDNBR,
        @"amount":@(amount * 100),
        @"bank":@"乌当农商银行",
        @"idNo":self.infoModel.CUSTID,
        @"name":self.infoModel.NAME,
        @"proCode":self.productModel.RET_PRD_CODE,
        @"smsSeq":SMS_SEQ,
        @"smsCode":[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""],
        @"tel":infoModel.MO_PHONE,
        @"userId":@([getPeopleID PeopleID])
    };

    
    NSLog(@"银数购买产品url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        if ([state isEqualToString:@"200"]) {
//            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
          
            [self orderDetailInfoRequest:describe];
            return;
        }
        [KKLoadingAnimationView dismiss];
        
        
           NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
            NSLog(@"describe:%@",dic);
            NSString*code = nil;
            NSString*message = nil;
            if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                code = [NSString stringWithFormat:@"%@",dic[@"code"]];
            }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
            }
            
            if (code) {
                message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                
                if (message) {
                    [SVProgressHUD showErrorWithStatus:message];
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
        [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}


#pragma mark - 订单详情查询
- (void)orderDetailInfoRequest:(NSString *)order
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSOrderDetailQueryDetailRequest];

    NSString*acctNo = nil;
    if (self.type == SMSSendTypeProPurchase){
        SaveAccountSubUserInfoModel*infoModel = self.infoModel.SUBPACKS[0];
        acctNo = infoModel.CARDNBR;
    } else if (self.type == SMSSendTypeProRedeem){
        acctNo = self.detailModel.ACCT_NO;
    }
    NSDictionary*params = @{
        @"acctNo": acctNo,
        @"order":order
    };
    
    
    NSLog(@"银数产品购买/赎回查询url:%@",url);
    NSLog(@"params:%@",params);
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        if ([state isEqualToString:@"200"]) {
            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            if ( self.type == SMSSendTypeProPurchase) {
                [GTCountSDK trackCountEvent:@"save_wudangProPurchaseSuccessCount" withArgs:nil];
                self.detailModel = [ProductDetailModel mj_objectWithKeyValues:dic];
                NSString*value = [self.amount stringByReplacingOccurrencesOfString:@" " withString:@""];
                RechargeSuccessController*vc = [RechargeSuccessController new];
                vc.amount = value;
                vc.detailModel = self.detailModel;
                [self.navigationController pushViewController:vc animated:YES];
            }else if (self.type == SMSSendTypeProRedeem){
                [GTCountSDK trackCountEvent:@"save_wudangProReduceSuccessCount" withArgs:nil];
                [[NSNotificationCenter defaultCenter] postNotificationName:KKSBGETBalanceNotificationName object:nil];
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
           
        }else{
            NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
            NSLog(@"describe:%@",dic);
            NSString*code = nil;
            NSString*message = nil;
            if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                code = [NSString stringWithFormat:@"%@",dic[@"code"]];
            }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
            }
            
            if (code) {
                message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                
                if (message) {
                    [SVProgressHUD showErrorWithStatus:message];
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
         [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}


#pragma mark - 充值提现查询
- (void)transactionOrderQueryRequest:(NSString *)order
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YStransactionOrderQueryRequest];
    
    SaveAccountSubUserInfoModel*infoModel = self.infoModel.SUBPACKS[0];
    
    NSString* acctNo = nil;
    if (self.type == SMSSendTypeRecharge) {
        acctNo = infoModel.CARDNBR;
    }else if (self.type == SMSSendTypeWithDrawal){
        acctNo = infoModel.CARDNBR;
    }
    NSDictionary*params = @{
        @"acctNo": acctNo,
        @"order":order
    };

    
    NSLog(@"银数充值/提现查询url:%@",url);
    NSLog(@"params:%@",params);
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        if ([state isEqualToString:@"200"]) {
//            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            
            [[NSNotificationCenter defaultCenter] postNotificationName:KKSBGETBalanceNotificationName object:nil];
            if (self.type == SMSSendTypeRecharge) {
                [GTCountSDK trackCountEvent:@"save_wudangRechargeSuccessCount" withArgs:@{}];
                if (self.navigationController.tabBarController.selectedIndex == 0) {
                    [self.navigationController popToViewController:self.navigationController.viewControllers[2] animated:YES];
                }else if (self.navigationController.tabBarController.selectedIndex == 1){
                    self.navigationController.tabBarController.selectedIndex = 1;
                    [self.navigationController popToRootViewControllerAnimated:YES];
                }
            }else if (self.type == SMSSendTypeWithDrawal){
                [GTCountSDK trackCountEvent:@"save_wudangWithDrawalSuccessCount" withArgs:@{}];
                self.navigationController.tabBarController.selectedIndex = 1;
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
            
        }else{
            NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
            NSLog(@"describe:%@",dic);
           NSString*code = nil;
           NSString*message = nil;
           if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
               code = [NSString stringWithFormat:@"%@",dic[@"code"]];
           }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
               code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
           }
           
           if (code) {
               message = [KBankErrorCode showErrorMessageWithErrorCode:code];
               
               if (message) {
                   [SVProgressHUD showErrorWithStatus:message];
               }else{
                   [SVProgressHUD showErrorWithStatus:@"系统错误"];
               }
           }else{
               [SVProgressHUD showErrorWithStatus:@"系统错误"];
           }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
       [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}



#pragma mark - 开户请求
- (void)openAccountRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSOPenAccountRequest];
    NSString *uuid = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
//    NSString *address = [UserDefault objectForKey:@"locationAddress"];
//    NSString *locationCoordinate = [UserDefault objectForKey:@"locationCoordinate"];
    NSString * sex = nil;
    if ([self.ocrModel.sex isEqualToString:@"男"]) {
        sex = @"M";
    }else if ([self.ocrModel.sex isEqualToString:@"女"]){
        sex = @"F";
    }else{
        sex = @"M";
    }
    NSDictionary*params = @{
        @"address":![Tools isBlankString:self.ocrModel.address] ?self.ocrModel.address :@"",
        @"authority":![Tools isBlankString:self.ocrModel.authority] ?self.ocrModel.authority :@"",
        @"birthDate":![Tools isBlankString:self.ocrModel.birthDate] ? self.ocrModel.birthDate : @"",
        @"buscd":![Tools isBlankString:self.jobModel.jobCode] ?self.jobModel.jobCode :@"",
        @"cardNo":[self.cardNo stringByReplacingOccurrencesOfString:@" " withString:@""],
        @"deviceNo":uuid,
        @"geoLocation":@"",
        @"idNo":![Tools isBlankString:self.ocrModel.idno] ?self.ocrModel.idno :@"",
        @"locations":@"",
        @"mobileNo":self.prePhone,
        @"name":![Tools isBlankString:self.ocrModel.name] ?self.ocrModel.name :@"",
        @"nationality":![Tools isBlankString:self.ocrModel.nationality] ?self.ocrModel.nationality :@"",
        @"product":@"2004",
        @"riskLel":@"",
        @"riskYn":@"1",
        @"rsource":@"01",
        @"sex":sex,
        @"smsFlag":@"1",
        @"userId":@([getPeopleID PeopleID]),
        @"validCode":self.topView.tf_code.text,
        @"bank":@"乌当银行",
        @"validity":![Tools isBlankString:self.ocrModel.validity] ?self.ocrModel.validity :@"",
    };
    
    NSLog(@"银数开户url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
//            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            [GTCountSDK trackCountEvent:@"save_wudangElectAccountOPenSuccessCount" withArgs:@{}];
            [[NSNotificationCenter defaultCenter] postNotificationName:KKSBGETBalanceNotificationName object:nil];
            ElectAccountOPenSuccessController* vc = [ElectAccountOPenSuccessController new];
            vc.title = @"开户成功";
            vc.cardNo = [self.cardNo stringByReplacingOccurrencesOfString:@" " withString:@""];
            vc.from = self.from;
            vc.type = SaveFromTypeYinShu;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
            NSLog(@"describe:%@",dic);
            NSString*code = nil;
            NSString*message = nil;
            if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                code = [NSString stringWithFormat:@"%@",dic[@"code"]];
            }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
            }
            
            if (code) {
                message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                
                if (message) {
                    [SVProgressHUD showErrorWithStatus:message];
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
       [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}



#pragma mark - 充值请求
- (void)rechargeRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSRechargeRequest];
    SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
    NSString*acctNo = [Tools isBlankString:subModel.CARDNBR] ?@"" :subModel.CARDNBR;
    NSString*amount = [self.amount stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString*cardBind = [Tools isBlankString:subModel.SIGCARD] ?@"" :subModel.SIGCARD;
    NSString*idNo = [Tools isBlankString:self.infoModel.CUSTID] ?@"" :self.infoModel.CUSTID;
    NSString*name = [Tools isBlankString:self.infoModel.NAME] ?@"" :self.infoModel.NAME;
     NSString*tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
    NSDictionary*params = @{
        @"acctNo":acctNo,
        @"amount":amount,
        @"cardBind":cardBind,
        @"idNo":idNo,
        @"name":name,
        @"smsCode":self.topView.tf_code.text,
        @"smsSeq":SMS_SEQ,
        @"tel":tel
    };
    
    
    NSLog(@"银数充值url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
       
   AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
   NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
   NSLog(@"strHeader:%@",strHeader);
   [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
      
   [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
      
   } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
      
      NSLog(@"responseObject:%@",responseObject);
       NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
       NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
       NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
       if ([state isEqualToString:@"200"]) {
//           NSDictionary*dic = [Tools dencode:result];
           NSLog(@"result:%@",[Tools dencode:result]);
           [self transactionOrderQueryRequest:describe];
           return;
       }
       [KKLoadingAnimationView dismiss];
       NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
       NSLog(@"describe:%@",dic);
       NSString*code = nil;
       NSString*message = nil;
       if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
           code = [NSString stringWithFormat:@"%@",dic[@"code"]];
       }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
           code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
       }
       
       if (code) {
           message = [KBankErrorCode showErrorMessageWithErrorCode:code];
           
           if (message) {
               [SVProgressHUD showErrorWithStatus:message];
           }else{
               [SVProgressHUD showErrorWithStatus:@"系统错误"];
           }
       }else{
           [SVProgressHUD showErrorWithStatus:@"系统错误"];
       }
   } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
      [KKLoadingAnimationView dismiss];
      NSLog(@"error:%@",error);
      [SVProgressHUD showInfoWithStatus:@"网络异常"];
   }];
    
    
}


#pragma mark - 提现请求
- (void)withDrawRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSWithDrawlRequest];
     SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
     NSString*acctNo = [Tools isBlankString:subModel.CARDNBR] ?@"" :subModel.CARDNBR;
     NSString*amount = [self.amount stringByReplacingOccurrencesOfString:@" " withString:@""];
     NSString*cardBind = [Tools isBlankString:subModel.SIGCARD] ?@"" :subModel.SIGCARD;
     NSString*idNo = [Tools isBlankString:self.infoModel.CUSTID] ?@"" :self.infoModel.CUSTID;
     NSString*name = [Tools isBlankString:self.infoModel.NAME] ?@"" :self.infoModel.NAME;
      NSString*tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
     NSDictionary*params = @{
         @"acctNo":acctNo,
         @"amount":amount,
         @"cardBind":cardBind,
         @"idNo":idNo,
         @"name":name,
         @"smsCode":self.topView.tf_code.text,
         @"smsSeq":SMS_SEQ,
         @"tel":tel
     };
     
     
     NSLog(@"银数提现url:%@",url);
     NSLog(@"params:%@",params);
     
     [KKLoadingAnimationView show];
        
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        if ([state isEqualToString:@"200"]) {
//            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            [self transactionOrderQueryRequest:describe];
            return;
        }
        [KKLoadingAnimationView dismiss];
        NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
        NSLog(@"describe:%@",dic);
        NSString*code = nil;
        NSString*message = nil;
        if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
            code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
            code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
        }
        
        if (code) {
            message = [KBankErrorCode showErrorMessageWithErrorCode:code];
            
            if (message) {
                [SVProgressHUD showErrorWithStatus:message];
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"系统错误"];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
       [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}

#pragma mark - 产品赎回请求
- (void)proReduceRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSProReduceRequest];
    
    
    NSString*acctNo = [Tools isBlankString:self.buyedProModel.accountNo] ?@"" :self.buyedProModel.accountNo;
    NSString*amount = [self.buyedProModel.account stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString*order = [Tools isBlankString:self.buyedProModel.Id] ?@"" :self.buyedProModel.Id;
    NSString*tel = [Tools isBlankString:self.buyedProModel.tel] ?@"" :self.buyedProModel.tel;
    NSDictionary*params = @{
        @"acctNo":acctNo,
        @"amount":amount,
        @"order":order,
        @"smsCode":self.topView.tf_code.text,
        @"smsSeq":SMS_SEQ,
        @"tel":tel
    };
        
        
    NSLog(@"银数产品赎回url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
       
   AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
   NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
   NSLog(@"strHeader:%@",strHeader);
   [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
      
   [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
      
   } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
      
      NSLog(@"responseObject:%@",responseObject);
       NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
       NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
       NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
       if ([state isEqualToString:@"200"]) {
//           NSDictionary*dic = [Tools dencode:result];
           NSLog(@"result:%@",[Tools dencode:result]);
            [self orderDetailInfoRequest:describe];
            return;
       }
       [KKLoadingAnimationView dismiss];
       NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
       NSLog(@"describe:%@",dic);
       NSString*code = nil;
       NSString*message = nil;
       if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
           code = [NSString stringWithFormat:@"%@",dic[@"code"]];
       }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
           code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
       }
       
       if (code) {
           message = [KBankErrorCode showErrorMessageWithErrorCode:code];
           
           if (message) {
               [SVProgressHUD showErrorWithStatus:message];
           }else{
               [SVProgressHUD showErrorWithStatus:@"系统错误"];
           }
       }else{
           [SVProgressHUD showErrorWithStatus:@"系统错误"];
       }
   } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
      [KKLoadingAnimationView dismiss];
      NSLog(@"error:%@",error);
       [SVProgressHUD showInfoWithStatus:@"网络异常"];
   }];
}


#pragma mark - 预留手机号修改请求
- (void)prePhoneModtifyRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSChangeAccountBindTel];
     
     
     SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
     NSString*acctNo = [Tools isBlankString:subModel.CARDNBR] ?@"" :subModel.CARDNBR;
     NSString*phone = [self.phone stringByReplacingOccurrencesOfString:@" " withString:@""];
     NSString*cardBind = [Tools isBlankString:subModel.SIGCARD] ?@"" :subModel.SIGCARD;
     NSString*idNo = [Tools isBlankString:self.infoModel.CUSTID] ?@"" :self.infoModel.CUSTID;
     NSString*name = [Tools isBlankString:self.infoModel.NAME] ?@"" :self.infoModel.NAME;
     NSDictionary*params = @{
         @"acctNo":acctNo,
         @"cardBind":cardBind,
         @"idNo":idNo,
         @"name":name,
         @"smsCode":self.topView.tf_code.text,
         @"smsSeq":SMS_SEQ,
         @"tel":phone
     };
         
         
     NSLog(@"银数预留手机号修改url:%@",url);
     NSLog(@"params:%@",params);
     
     [KKLoadingAnimationView show];
        
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        if ([state isEqualToString:@"200"]) {
             [KKLoadingAnimationView dismiss];
//            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            [[NSNotificationCenter defaultCenter] postNotificationName:KKSBGETBalanceNotificationName object:nil];
            [GTCountSDK trackCountEvent:@"save_wudangChangeBindPhoneSuccessCount" withArgs:nil];
            SaveSettingSuccessController*vc = [SaveSettingSuccessController new];
            vc.title = @"修改成功";
            vc.type = self.type;
            vc.phone = self.phone;
            [self.navigationController pushViewController:vc animated:YES];
            return;
        }
        [KKLoadingAnimationView dismiss];
        NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
        NSLog(@"describe:%@",dic);
        NSString*code = nil;
        NSString*message = nil;
        if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
            code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
            code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
        }
        
        if (code) {
            message = [KBankErrorCode showErrorMessageWithErrorCode:code];
            
            if (message) {
                [SVProgressHUD showErrorWithStatus:message];
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"系统错误"];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
        [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}

#pragma mark - 绑定银行卡修改
- (void)bindCardUpdateRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSUPDateBindCardRequest];
     
     
     SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
     NSString*acctNo = [Tools isBlankString:subModel.CARDNBR] ?@"" :subModel.CARDNBR;
    NSString*phone = [subModel.MO_PHONE stringByReplacingOccurrencesOfString:@" " withString:@""];
     NSString*cardBind = [Tools isBlankString:subModel.SIGCARD] ?@"" :subModel.SIGCARD;
     NSString*idNo = [Tools isBlankString:self.infoModel.CUSTID] ?@"" :self.infoModel.CUSTID;
     NSString*name = [Tools isBlankString:self.infoModel.NAME] ?@"" :self.infoModel.NAME;
     NSDictionary*params = @{
         @"acctNo":acctNo,
         @"cardBind":cardBind,
         @"idNo":idNo,
         @"name":name,
         @"newCardBind":self.nBindCard,
         @"smsCode":self.topView.tf_code.text,
         @"smsSeq":SMS_SEQ,
         @"tel":phone
     };
         
         
     NSLog(@"银数更换绑定银行卡url:%@",url);
     NSLog(@"params:%@",params);
     
     [KKLoadingAnimationView show];
        
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        if ([state isEqualToString:@"200"]) {
             [KKLoadingAnimationView dismiss];
//            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            [[NSNotificationCenter defaultCenter] postNotificationName:KKSBGETBalanceNotificationName object:nil];
            [GTCountSDK trackCountEvent:@"save_wudangChangeBindCardSuccessCount" withArgs:nil];
            SaveSettingSuccessController*vc = [SaveSettingSuccessController new];
            vc.title = @"修改成功";
            vc.type = self.type;
            vc.nBindCard = self.nBindCard;
            [self.navigationController pushViewController:vc animated:YES];
            return;
        }
        [KKLoadingAnimationView dismiss];
        NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
        NSLog(@"describe:%@",dic);
        NSString*code = nil;
        NSString*message = nil;
        if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
            code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
            code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
        }
        
        if (code) {
            message = [KBankErrorCode showErrorMessageWithErrorCode:code];
            
            if (message) {
                [SVProgressHUD showErrorWithStatus:message];
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"系统错误"];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
        [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}


#pragma mark - 比财实名短信验证
- (NSDictionary *)systemIdentifySMSRequestParams
{
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.idcardBackPhoto forKey:@"idcardBackPhoto"];
    [params setObject:self.idcardFrontPhoto forKey:@"idcardFrontPhoto"];
    [params setObject:@"2" forKey:@"transcoding"];
    [params setObject:self.bankNo forKey:@"bankCardNo"];
    [params setObject:self.bcPrePhone forKey:@"mobile"];
    
    return params;
}

- (void)systemIdentifySMSRequest:(UIButton *)sender
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCOCRImageUploadRequest];
    NSLog(@"比财实名url:%@",url);
    
    
    
    NSLog(@"params:%@",[self systemIdentifySMSRequestParams]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self systemIdentifySMSRequestParams] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
//            NSString *sendImgCode = [NSString stringWithFormat:@"%@",objc[@"result"][@"sendImgCode"]];
            
            [self timeCount];
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}


#pragma mark - 比财实名短信校验
- (NSDictionary *)systemIdentifyConfirmSMSRequestParams
{
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.topView.tf_code.text forKey:@"phoneCheckCode"];
    
    return params;
}

- (void)systemIdentifyConfirmSMSRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCQueryAuthCodeVerifyRequest];
    NSLog(@"比财实名认证短信校验url:%@",url);
    
    
    
    NSLog(@"params:%@",[self systemIdentifyConfirmSMSRequestParams]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self systemIdentifyConfirmSMSRequestParams] Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSString *needDetection = [NSString stringWithFormat:@"%@",objc[@"result"][@"needDetection"]];
            if ([needDetection isEqualToString:@"0"]) {
                
            }else if ([needDetection isEqualToString:@"1"]) {
                //[self queryRealNameAuthInfoRequest];
                [self bcCheckSystemValitifyDetectionLivingRequest];
                return;
            }
            
            
            
        }else{
            [self alertShow:describe];
        }
        [KKLoadingAnimationView dismiss];

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}



#pragma mark - 比财实名查询认证信息查询
- (void)queryRealNameAuthInfoRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCQueryAuthInfoRequest];
    NSLog(@"比财账户实名查询认证信息url:%@",url);
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    NSLog(@"params:%@",params);
    
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            [self bcCheckSystemValitifyDetectionLivingRequest];
            
            return;
            
        }else{
            [self alertShow:describe];
        }
        
        [KKLoadingAnimationView dismiss];

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
    
    
    
}

#pragma mark - 比财实名活体校验
- (void)bcCheckSystemValitifyDetectionLivingRequest {
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCCheckSystemValitifyDetectionLivingRequest];
    NSLog(@"比财账户实名活体校验url:%@",url);
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    NSLog(@"params:%@",params);
    
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"人脸认证提示" message:@"录制时请保持正脸对框且眨眼!" preferredStyle:UIAlertControllerStyleAlert];
               //默认只有标题 没有操作的按钮:添加操作的按钮 UIAlertAction
               
               UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                   NSLog(@"取消");
               }];
               //添加确定
               UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"确认认证" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull   action) {
                   NSLog(@"确定");
                   [self openCameraForVideo];
               }];
               //设置`确定`按钮的颜色
               [sureBtn setValue:[UIColor redColor] forKey:@"titleTextColor"];
               //将action添加到控制器
               [alertVc addAction:cancelBtn];
               [alertVc addAction :sureBtn];
               //展示
               [self presentViewController:alertVc animated:YES completion:nil];
            
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
    
}


#pragma mark - 比财 上传人脸活体检测video
- (NSDictionary *)uploadVideoRequestPara
{
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    
    NSString* fileName = [NSString stringWithFormat:@"%@.mp4",self.realName];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:videoStr forKey:@"uploadFile"];
    [params setObject:fileName forKey:@"fileName"];
    [params setObject:@(YES) forKey:@"flag"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    [params setObject:self.realName forKey:@"realName"];
    [params setObject:self.idcardNo forKey:@"userCardId"];
//    [params setObject:@"雷俊博" forKey:@"realName"];
//    [params setObject:@"411522199109276910" forKey:@"userCardId"];
//    [params setObject:@"340" forKey:@"orgId"];
    
    
    return params;
}

- (void)uploadVideoRequest
{
  
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCSystemValitifyDetectionLivingRequest];
    NSLog(@"比财账户实名活体检测url:%@",url);
    
    NSLog(@"params:%@",[self uploadVideoRequestPara]);
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self uploadVideoRequestPara] Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            NSString* verification = [NSString stringWithFormat:@"%@",objc[@"result"][@"verification"]];
            
            if ([verification isEqualToString:@"20"]) {
                
                [self bcRegistInfoShowBackRequest];
                return;
                
            }else if ([verification isEqualToString:@"30"]){
                [self alertShow:@"验证不匹配"];
            }
            
            
        }else{
            [self alertShow:describe];
        }
        
        [KKLoadingAnimationView dismiss];

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
    }];
    
}





#pragma mark -  比财 用户信息回显
- (void)bcRegistInfoShowBackRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCRegistInfoShowBackRequest];
    NSLog(@"比财账户用户信息回显url:%@",url);
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
//    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    [params setObject:@"340" forKey:@"orgId"];
    NSLog(@"params:%@",params);
    
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            BCRegistInfoModel* infoModel = [BCRegistInfoModel mj_objectWithKeyValues:objc[@"result"]];
            
            ElectronicAccountController* vc = [ElectronicAccountController new];
            vc.title = @"电子账户";
            vc.type = SaveFromTypeBiCai;
            vc.registerModel = infoModel;
            vc.bcInfoModel = self.bcInfoModel;
            vc.bankNo = self.bankNo;
            vc.bcPrePhone = self.bcPrePhone;
           
            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}


#pragma mark - 比财 开户提交(验证码)
- (NSDictionary *)bcCommitOpenAccountInfoRequestParams{
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    
    NSString* bankCardNum = [self.bankNo stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString* bankCardPhone = [self.prePhone stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString* bankName = [self.bankName stringByReplacingOccurrencesOfString:@" " withString:@""];

    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    [params setObject:self.registerModel.address forKey:@"residentAddress"];
    if (self.dutyModel) {
        [params setObject:self.dutyModel.dutyCode forKey:@"userDuty"];
    }
    if (self.industryModel) {
        [params setObject:self.industryModel.industryCode forKey:@"industry"];
    }
    
    [params setObject:bankCardNum forKey:@"bankCardNum"];
    [params setObject:bankCardPhone forKey:@"bankCardPhone"];
    [params setObject:bankName forKey:@"bankName"];
    
    return params;
}
- (void)bcCommitOpenAccountInfoRequest{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCCommitOpenAccountInfoRequest];
    
    NSLog(@"比财开户提交url:%@",url);
    NSLog(@"params:%@",[self bcCommitOpenAccountInfoRequestParams]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self bcCommitOpenAccountInfoRequestParams] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            NSString* apiPackSeq = objc[@"result"][@"apiPackSeq"];
            NSString* validateCodeSerialNum = objc[@"result"][@"validateCodeSerialNum"];
            
            self.apiPackSeq = apiPackSeq;
            self.validateCodeSerialNum = validateCodeSerialNum;
            
            [self timeCount];
            
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 比财 开户验证码确认
- (NSDictionary *)bcCommitOPenAccountValidateCodeRequestParams{
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    if (self.validateCodeSerialNum) {
        [params setObject:self.validateCodeSerialNum forKey:@"validateCodeSerialNum"];
    }
    [params setObject:[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"validateCode"];
    [params setObject:self.prePhone forKey:@"validatePhoneNum"];
    [params setObject:@([getPeopleID PeopleID]) forKey:@"uid"];
    
    return params;
}


- (void)bcCommitOPenAccountValidateCodeRequest{
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCCommitOPenAccountValidateCodeRequest];
    
    NSLog(@"比财开户确认url:%@",url);
    NSLog(@"params:%@",[self bcCommitOPenAccountValidateCodeRequestParams]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self bcCommitOPenAccountValidateCodeRequestParams] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            ElectAccountOPenSuccessController* vc = [ElectAccountOPenSuccessController new];
            vc.title = @"开户成功";
            vc.cardNo = [self.bankNo stringByReplacingOccurrencesOfString:@" " withString:@""];
            vc.type = SaveFromTypeBiCai;
            vc.bcInfoModel = self.bcInfoModel;
            [self.navigationController pushViewController:vc animated:YES];
            
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
    
    
}

#pragma mark - 比财 充值获取验证码

- (NSDictionary *)bcRechargeSendSMSMessageRequestPara {
    NSString*amount = [self.amount stringByReplacingOccurrencesOfString:@" " withString:@""];
    BCCardListModel *ccmodel = nil;
    if (self.bcAccountInfoModel.cardList.count > 0) {
        ccmodel = self.bcAccountInfoModel.cardList[0];
    }
    
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcAccountInfoModel.orgId forKey:@"orgId"];
    [params setObject:ccmodel.bankCardNum forKey:@"bankCardNum"];
    [params setObject:ccmodel.bankName forKey:@"bankName"];
    [params setObject:amount forKey:@"amount"];
    
    return params;
}

- (void)bcRechargeSendSMSMessageRequest {
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCRechargeSMSRequest];
    
    NSLog(@"比财充值提交url:%@",url);
    NSLog(@"params:%@",[self bcRechargeSendSMSMessageRequestPara]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self bcRechargeSendSMSMessageRequestPara] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            self.validateCodeSerialNum = objc[@"result"][@"validateCodeSerialNum"];
            self.reqSerial = objc[@"result"][@"reqSerial"];
           
           
            [self timeCount];
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
    
}


#pragma mark - 比财 充值确认
- (NSDictionary *)bcConfirmRechargeInfoRequestPara {
    NSString*amount = [self.amount stringByReplacingOccurrencesOfString:@" " withString:@""];
    BCCardListModel *ccmodel = nil;
    if (self.bcAccountInfoModel.cardList.count > 0) {
        ccmodel = self.bcAccountInfoModel.cardList[0];
    }
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:self.bcAccountInfoModel.orgId forKey:@"orgId"];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    
    if (self.reqSerial) {
        [params setObject:self.reqSerial forKey:@"reqSerial"];
    }
    [params setObject:ccmodel.bankCardNum forKey:@"bankCardNum"];
    [params setObject:ccmodel.bankName forKey:@"bankName"];
    [params setObject:amount forKey:@"amount"];
    [params setObject:[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"validateCode"];
    if (self.validateCodeSerialNum) {
        [params setObject:self.validateCodeSerialNum forKey:@"validateCodeSerialNum"];
    }
    
    NSString*tel = ccmodel.bankCardPhone;
    if (tel) {
        [params setObject:tel forKey:@"phoneNum"];
    }
   
    
    
    return params;
}

- (void)bcConfirmRechargeInfoRequest {
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCConfirmRechargeSMSRequest];
    
    NSLog(@"比财充值确认url:%@",url);
    NSLog(@"params:%@",[self bcConfirmRechargeInfoRequestPara]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self bcConfirmRechargeInfoRequestPara] Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
//            NSString* orderStatus = [NSString stringWithFormat:@"%@",objc[@"result"][@"orderStatus"]];
            if ([describe isEqualToString:@"0"]) {
                BCRechargeFinishController* vc = [BCRechargeFinishController new];
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                
                NSString *orderMsgContent = [NSString stringWithFormat:@"%@",objc[@"result"][@"orderMsgContent"]];
                [self alertShow:orderMsgContent];
            }
            

            
           
            
        }else if ([state isEqualToString:@"204"]) {
//            if (self.reqSerial) {
//                [params setObject:self.reqSerial forKey:@"reqSerial"];
//            }
//            [params setObject:ccmodel.bankCardNum forKey:@"bankCardNum"];
//            [params setObject:ccmodel.bankName forKey:@"bankName"];
//            [params setObject:amount forKey:@"amount"];
//            [params setObject:[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"validateCode"];
//            if (self.validateCodeSerialNum) {
//                [params setObject:self.validateCodeSerialNum forKey:@"validateCodeSerialNum"];
//            }
            NSString *code = [NSString stringWithFormat:@"%@",objc[@"result"][@"code"]];
            if ([code isEqualToString:@"Y00016"]) {
                NSString *signType = [NSString stringWithFormat:@"%@",objc[@"result"][@"data"][@"signType"]];
                self.apiPackSeq = [NSString stringWithFormat:@"%@",objc[@"result"][@"data"][@"apiPackSeq"]];
                self.reqSerial = [NSString stringWithFormat:@"%@",objc[@"result"][@"data"][@"reqSerial"]];
                if ([signType isEqualToString:@"Z"]) {
                    [BCRechargeSignAlertView showWithVC:self title:describe block:^{
                        SignPasswayController* vc = [SignPasswayController new];
                        vc.title = @"代收通道签约";
                        vc.bcInfoModel = self.bcAccountInfoModel;
                        vc.reqSerial = self.reqSerial;
                        vc.validateCodeSerialNum = self.validateCodeSerialNum;
                        vc.validateCode = [self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""];
                        vc.apiPackSeq = objc[@"result"][@"apiPackSeq"];
                        vc.signType = signType;
                        vc.type = SaveFromTypeBiCai;
                        [self.navigationController pushViewController:vc animated:YES];
                    }];
                }else if ([signType isEqualToString:@"B"]) {
                    [self bcRechargeV1SignApplyVerifRequest];
                }
                    
            }else{
                [self alertShow:describe];
            }
            
            
        } else{
            [self alertShow:describe];
        }
        [KKLoadingAnimationView dismiss];
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
    
}


#pragma mark - 比财提现获取验证码
- (NSDictionary *)bcWithDrawSMSRequestPara {
//    NSString*amount = [self.amount stringByReplacingOccurrencesOfString:@" " withString:@""];
    BCCardListModel *ccmodel = nil;
    if (self.bcAccountInfoModel.cardList.count > 0) {
        ccmodel = self.bcAccountInfoModel.cardList[0];
    }
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:self.bcAccountInfoModel.orgId forKey:@"orgId"];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:ccmodel.bankCardPhone forKey:@"bankCardPhone"];
    [params setObject:ccmodel.bankCardNum forKey:@"bankCardNum"];
    [params setObject:self.amount forKey:@"amount"];
    
    
    return params;
}
- (void)bcWithDrawSMSRequest {
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCWithDrawalSMSRequest];
    
    NSLog(@"比财提现提交url:%@",url);
    NSLog(@"params:%@",[self bcWithDrawSMSRequestPara]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self bcWithDrawSMSRequestPara] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            self.validateCodeSerialNum = objc[@"result"][@"validateCodeSerialNum"];
            [self timeCount];
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 比财提现确认
- (NSDictionary *)bcWithDrawRequestPara {
    NSString*amount = [self.amount stringByReplacingOccurrencesOfString:@" " withString:@""];
    BCCardListModel *ccmodel = nil;
    if (self.bcAccountInfoModel.cardList.count > 0) {
        ccmodel = self.bcAccountInfoModel.cardList[0];
    }
    
    NSString* withDrawType = nil;
    if (amount.doubleValue < self.bcAccountInfoModel.balance.doubleValue) {
        withDrawType = @"0";
    }else{
        withDrawType = @"1";
    }
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:self.bcAccountInfoModel.orgId forKey:@"orgId"];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:ccmodel.bankCardNum forKey:@"bankCardNum"];
    [params setObject:ccmodel.bankName forKey:@"bankName"];
    [params setObject:ccmodel.bankCardPhone forKey:@"phoneNum"];
    [params setObject:amount forKey:@"amount"];
    [params setObject:[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"validateCode"];
    
    if (self.validateCodeSerialNum) {
        [params setObject:self.validateCodeSerialNum forKey:@"validateCodeSerialNum"];
    }
    
    [params setObject:withDrawType forKey:@"withDrawType"];
    
    
    return params;
}
- (void)bcWithDrawRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCConfirmWithDrawalSMSRequest];
    
    NSLog(@"比财提现确认url:%@",url);
    NSLog(@"params:%@",[self bcWithDrawRequestPara]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self bcWithDrawRequestPara] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            if (self.navigationController.tabBarController.selectedIndex == 0) {
                [self.navigationController popToViewController:self.navigationController.viewControllers[2] animated:YES];
            }else if (self.navigationController.tabBarController.selectedIndex == 1){
                self.navigationController.tabBarController.selectedIndex = 1;
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 产品赎回校验
- (NSDictionary *)checkBCProReduceRequestPara {
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:self.bcholdProRetModel.orgId forKey:@"orgId"];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcholdProRetModel.prdIndexId forKey:@"prdIndexId"];
    [params setObject:self.bcholdProRetModel.reqSerial forKey:@"reqSerial"];
    [params setObject:self.bcholdProRetModel.dynamicList.valueDate.fieldValue forKey:@"buyDate"];
    [params setObject:self.bcholdProRetModel.dynamicList.endDate.fieldValue forKey:@"expireDate"];
    return params;
}

- (void)checkBCProReduceRequest {
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCCheckRedemptionRequest];
    
    NSLog(@"比财赎回校验url:%@",url);
    NSLog(@"params:%@",[self checkBCProReduceRequestPara]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self checkBCProReduceRequestPara] Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
        
            [self bcRedemptionSMSRequest];
            return;
        }else{
            [self alertShow:describe];
        }

        [KKLoadingAnimationView dismiss];
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
    
}


#pragma mark - 比财 赎回提交(验证码)
- (NSDictionary *)bcRedemptionSMSRequestPara {
    BCCardListModel *ccmodel = nil;
    if (self.bcAccountInfoModel.cardList.count > 0) {
        ccmodel = self.bcAccountInfoModel.cardList[0];
    }
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:self.bcholdProRetModel.orgId forKey:@"orgId"];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcholdProRetModel.prdIndexId forKey:@"prdIndexId"];
    [params setObject:self.bcholdProRetModel.reqSerial forKey:@"reqSerial"];
    [params setObject:ccmodel.bankCardPhone forKey:@"bankCardPhone"];
    [params setObject:ccmodel.bankCardNum forKey:@"bankCardNum"];
    [params setObject:self.bcholdProRetModel.dynamicList.amount.fieldValue forKey:@"amount"];
    
    
    return params;
}
- (void)bcRedemptionSMSRequest {
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCRedemptionRequest];
    
    NSLog(@"比财赎回提交url:%@",url);
    NSLog(@"params:%@",[self bcRedemptionSMSRequestPara]);
    [NetworkRequest Post6:url Params:[self bcRedemptionSMSRequestPara] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            self.validateCodeSerialNum = objc[@"result"][@"validateCodeSerialNum"];
            [self timeCount];
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 比财 赎回确认
-(NSDictionary *)bcRedemptionConfirmRequestPara {
   BCCardListModel *ccmodel = nil;
   if (self.bcAccountInfoModel.cardList.count > 0) {
       ccmodel = self.bcAccountInfoModel.cardList[0];
   }
   
   NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
   [params setObject:self.bcholdProRetModel.orgId forKey:@"orgId"];
   [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
   [params setObject:@([getPeopleID PeopleID]) forKey:@"uid"];
    [params setObject:self.bcAccountInfoModel.bankElecAccountNum forKey:@"bankElecAccountNum"];
    [params setObject:self.bcAccountInfoModel.bankCardPhone forKey:@"phoneNum"];
   [params setObject:self.bcholdProRetModel.prdIndexId forKey:@"prdIndexId"];
   [params setObject:self.bcholdProRetModel.reqSerial forKey:@"reqSerial"];
    [params setObject:self.bcholdProRetModel.dynamicList.amount.fieldValue forKey:@"amount"];
    [params setObject:[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"validateCode"];
    
    if (self.validateCodeSerialNum) {
        [params setObject:self.validateCodeSerialNum forKey:@"validateCodeSerialNum"];
    }
    
    
  
   
   
   return params;
}
- (void)bcRedemptionConfirmRequest {
   NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCRedemptionConfirmRequest];
   
   NSLog(@"比财赎回确认url:%@",url);
   NSLog(@"params:%@",[self bcRedemptionConfirmRequestPara]);
    [KKLoadingAnimationView show];
   [NetworkRequest Post6:url Params:[self bcRedemptionConfirmRequestPara] Success:^(id _Nonnull objc) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"objc:%@",objc);
       NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
       NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
       if ([state isEqualToString:@"200"]) {
           [self.navigationController popToRootViewControllerAnimated:YES];
           
       }else{
           [self alertShow:describe];
       }

   } Failure:^(NSError* error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
       [self alertShow:@"网络出小差了,请稍后重试"];
       
   }];
}


#pragma mark - 比财 购买校验
- (void)checkPurchaseRequest {
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCCheckPurchaseRequest];
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    [params setObject:@(self.bcInfoModel.productId) forKey:@"prdIndexId"];
    
    NSLog(@"比财购买校验url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
          
            
            [self bcPurchaseSMSRequest];
            return;
            
            
        }else{
            [self alertShow:describe];
        }
        
        [KKLoadingAnimationView dismiss];

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 比财 购买提交验证码
- (void)bcPurchaseSMSRequest {
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCPurchaseSMSRequest];
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    [params setObject:self.bcAccountInfoModel.bankCardPhone forKey:@"bankCardPhone"];
    [params setObject:self.bcAccountInfoModel.bankElecAccountNum forKey:@"bankCardNum"];
    [params setObject:self.amount forKey:@"amount"];
    
    NSLog(@"比财购买提交url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
          
            self.validateCodeSerialNum = objc[@"result"][@"validateCodeSerialNum"];
            
            [self timeCount];
            
        }else{
            [self alertShow:describe];
        }
        
        

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}
#pragma mark -比财  购买确认
- (void)bcPurchaseConfirmRequest {
    
        NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCConfirmPurchaseRequest];
        NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
        [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
        [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
        [params setObject:@(self.bcInfoModel.productId) forKey:@"prdIndexId"];
        [params setObject:self.amount forKey:@"amount"];
        [params setObject:self.bcAccountInfoModel.bankCardPhone forKey:@"phoneNum"];
        [params setObject:self.bcAccountInfoModel.bankElecAccountNum forKey:@"bankElecAccountNum"];
        [params setObject:[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"validateCode"];
    
        if (self.validateCodeSerialNum) {
            [params setObject:self.validateCodeSerialNum forKey:@"validateCodeSerialNum"];
        }
            
        
        [params setObject:@([getPeopleID PeopleID]) forKey:@"uid"];
        
        NSLog(@"比财购买确认url:%@",url);
        NSLog(@"params:%@",params);
        
        [KKLoadingAnimationView show];
        [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
            
            NSLog(@"objc:%@",objc);
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
            if ([state isEqualToString:@"200"]) {
              
                BCBuyResultModel* model = [BCBuyResultModel mj_objectWithKeyValues:objc[@"result"]];
                
                RechargeSuccessController*vc = [RechargeSuccessController new];
                vc.type = SaveFromTypeBiCai;
                vc.resultModel = model;
                [self.navigationController pushViewController:vc animated:YES];
                
                
            }else{
                [self alertShow:describe];
            }
            
            [KKLoadingAnimationView dismiss];

        } Failure:^(NSError* error) {
            [KKLoadingAnimationView dismiss];
            
            NSLog(@"error:%@",error);
            [self alertShow:@"网络出小差了,请稍后重试"];
            
        }];
        
}


#pragma mark - 充值签约申请-主动(获取验证码)
- (void)bcRechargeV1SignActiveApplyRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCRechargesignAtiveApplyV1Request];
    NSLog(@"比财充值签约申请-主动url:%@",url);
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcAccountInfoModel.orgId forKey:@"orgId"];
    
    BCCardListModel *ccmodel = nil;
    if (self.bcAccountInfoModel.cardList.count > 0) {
        ccmodel = self.bcAccountInfoModel.cardList[0];
    }
    if (ccmodel) {
        [params setObject:ccmodel.bankCardPhone forKey:@"phoneNum"];
        [params setObject:ccmodel.bankCardNum forKey:@"bankCardNum"];
        [params setObject:ccmodel.bankName forKey:@"bankName"];
    }
    
    
   
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            [self timeCount];
            self.apiPackSeq = objc[@"result"][@"apiPackSeq"];
            self.reqSerial = objc[@"result"][@"reqSerial"];
            self.preBankAccountNo = objc[@"result"][@"preBankAccountNo"];
            
        }else{
            [Tools showMessage:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [Tools showMessage:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 充值签约确认-主动(获取验证码)
- (void)bcRechargeV1SignActiveVerifRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCRechargesignAtiveVerifV1Request];
    NSLog(@"比财充值签约确认-主动url:%@",url);
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcAccountInfoModel.orgId forKey:@"orgId"];
    
    if (self.preBankAccountNo) {
        [params setObject:self.preBankAccountNo forKey:@"preBankAccountNo"];
    }
    
    if (self.validateCodeSerialNum) {
        [params setObject:self.validateCodeSerialNum forKey:@"validateCodeSerialNum"];
    }
    
    BCCardListModel *ccmodel = nil;
    if (self.bcAccountInfoModel.cardList.count > 0) {
        ccmodel = self.bcAccountInfoModel.cardList[0];
    }
    if (ccmodel) {
        [params setObject:ccmodel.bankCardNum forKey:@"bankCardNum"];
    }
    [params setObject:[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"validateCode"];
   
    NSLog(@"params:%@",params);
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:@"签约成功" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                for (UIViewController* vc in self.navigationController.viewControllers) {
                    if ([vc isKindOfClass:[ProductRechargeController class]]) {
                        [self.navigationController popToViewController:vc animated:YES];
                    }
                }
            }];
            
            [alertV addAction:confirm];
            
            [self presentViewController:alertV animated:YES completion:nil];
           
        }else{
            [Tools showMessage:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [Tools showMessage:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 充值签约确认 被动
- (void)bcRechargeV1SignApplyVerifRequest {
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCRechargesignApplyVerifV1Request];
    NSLog(@"比财充值签约确认-被动url:%@",url);
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcAccountInfoModel.orgId forKey:@"orgId"];
    
    if (self.reqSerial) {
        [params setObject:self.reqSerial forKey:@"reqSerial"];
    }
    
    if (self.validateCodeSerialNum) {
        [params setObject:self.validateCodeSerialNum forKey:@"validateCodeSerialNum"];
    }
    
    if (self.apiPackSeq) {
        [params setObject:self.apiPackSeq forKey:@"apiPackSeq"];
    }
    
    [params setObject:[self.topView.tf_code.text stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"validateCode"];
   
    NSLog(@"params:%@",params);
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            BCRechargeFinishController* vc = [BCRechargeFinishController new];
            [self.navigationController pushViewController:vc animated:YES];
           
        }else{
            [Tools showMessage:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [Tools showMessage:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 提示
- (void)alertShow:(NSString *)msg
{
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertV addAction:confirm];
        
        [self presentViewController:alertV animated:YES completion:nil];
        
    }else{
        UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertV show];
    }
}


#pragma mark - public methods
-(id)getXiblWithClassName:(NSString *)className
{
    return [[NSBundle mainBundle]loadNibNamed:className owner:self options:nil].lastObject;
}

#pragma mark - UIImagePickerControllerDelegate
/**
   UIImagePickerController代理 获取到媒体资源
 */
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
     NSString *mediaType = info[UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
        // 视频处理
        NSURL *videoUrl = info[UIImagePickerControllerMediaURL];//视频路径
        
        NSData*data = [NSData dataWithContentsOfURL:videoUrl];
         NSString *encodedImageStr = [GTMBase64 stringByEncodingData:data];
        NSLog(@"encodedImageStr.length:%ld",encodedImageStr.length);
        
        
//        UIImage *image = [self get_videoThumbImage:videoUrl];
        
        
        NSString * size = [NSString stringWithFormat:@"%ld kb", (long)[self getFileSize:[[videoUrl absoluteString] substringFromIndex:16]]];
        NSString *length = [NSString stringWithFormat:@"%.2f s", [self getVideoLength:videoUrl]];
           
           NSLog(@"-------------%@%@",size,length);
        //self.videoImageView.image = image;
        
        if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
            
//            if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([videoUrl path])) {
//                UISaveVideoAtPathToSavedPhotosAlbum([videoUrl path], self, @selector(video:didFinishSavingWithError:contextInfo:), nil);//保存视频到相簿
//            }
            videoStr =  [encodedImageStr stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];
            [self uploadVideoRequest];
        }
        
//       NSURL *newVideoUrl ; //一般.mp4
//          NSDateFormatter *formater = [[NSDateFormatter alloc] init];//用时间给文件全名，以免重复，在测试的时候其实可以判断文件是否存在若存在，则删除，重新生成文件即可
//          [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];
//          newVideoUrl = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingFormat:@"/Documents/output-%@.mp4", [formater stringFromDate:[NSDate date]]]] ;//这个是保存在app自己的沙盒路径里，后面可以选择是否在上传后删除掉。我建议删除掉，免得占空间。
//          [picker dismissViewControllerAnimated:YES completion:nil];
//          [self convertVideoQuailtyWithInputURL:videoUrl outputURL:newVideoUrl completeHandler:nil];

        
        
    }
    // 选择图片后手动销毁界面
    [picker dismissViewControllerAnimated:YES completion:nil];
}

/**
  用户取消操作
 */
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
//    手动销毁界面
    [picker dismissViewControllerAnimated:YES completion:nil];
}

//视频保存到相册之后的回调
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error) {
        // 保存失败
    }else {
        // 处理视频
        
    }
}


- (void) convertVideoQuailtyWithInputURL:(NSURL*)inputURL
                               outputURL:(NSURL*)outputURL
                         completeHandler:(void (^)(AVAssetExportSession*))handler
{
    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];
        //  NSLog(resultPath);
        exportSession.outputURL = outputURL;
        exportSession.outputFileType = AVFileTypeMPEG4;
        exportSession.shouldOptimizeForNetworkUse= YES;
        [exportSession exportAsynchronouslyWithCompletionHandler:^(void)
         {
             switch (exportSession.status) {
                 case AVAssetExportSessionStatusCancelled:
                     NSLog(@"AVAssetExportSessionStatusCancelled");
                     break;
                 case AVAssetExportSessionStatusUnknown:
                     NSLog(@"AVAssetExportSessionStatusUnknown");
                     break;
                 case AVAssetExportSessionStatusWaiting:
                     NSLog(@"AVAssetExportSessionStatusWaiting");
                     break;
                 case AVAssetExportSessionStatusExporting:
                     NSLog(@"AVAssetExportSessionStatusExporting");
                     break;
                 case AVAssetExportSessionStatusCompleted:
                 {   NSLog(@"AVAssetExportSessionStatusCompleted");
                     NSLog(@"%@",[NSString stringWithFormat:@"%f s", [self getVideoLength:outputURL]]);
                     NSLog(@"%@", [NSString stringWithFormat:@"%.2f kb", [self getFileSize:[outputURL path]]]);
                     NSData*data = [NSData dataWithContentsOfURL:outputURL];
                    NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
                    NSLog(@"encodedImageStr.length:%ld",encodedImageStr.length);
                 }
                     //UISaveVideoAtPathToSavedPhotosAlbum([outputURL path], self, nil, NULL);//这个是保存到手机相册
                     
                     //[self alertUploadVideo:outputURL];
                     break;
                 case AVAssetExportSessionStatusFailed:
                     NSLog(@"AVAssetExportSessionStatusFailed");
                     break;
             }
             
         }];
    
}



#pragma mark - event response
- (void)confirmBtnClick:(UIButton *)sender
{
//    [self bcRegistInfoShowBackRequest];
//    return;
    
    [self.view endEditing:YES];
    if (self.topView.tf_code.text.length != 6) {
        [Tools showMessage:@"请输入6位验证码"];
        return;
    }
    
    if (self.type == SMSSendTypeBCSystemIdentify  || self.type == SMSSendTypeBCOpenAccount || self.type == SMSSendTypeBCSignAtiveVerif || self.type == SMSSendTypeBCProPurchase) {
        
    }else if (self.type == SMSSendTypeBCRecharge){
//        if (self.validateCodeSerialNum == nil || self.reqSerial == nil) {
//            [Tools showMessage:@"验证码获取失败,请重新获取"];
//            return;
//        }
    }else if (self.type == SMSSendTypeBCWithDrawal) {
//        if (self.validateCodeSerialNum == nil) {
//            [Tools showMessage:@"验证码获取失败,请重新获取"];
//            return;
//        }
    }else if (self.type == SMSSendTypeBCProRedeem) {
//        if (self.validateCodeSerialNum == nil) {
//            [Tools showMessage:@"验证码获取失败,请重新获取"];
//            return;
//        }
    } else{
        
        
        if (SMS_SEQ == nil) {
            [Tools showMessage:@"验证码获取失败,请重新获取"];
            return;
        }
    }
    
    
    
    if (self.type == SMSSendTypeOpenAccount){
        [self openAccountRequest];
    }else if (self.type == SMSSendTypeRecharge){
        [self rechargeRequest];
    }else if (self.type == SMSSendTypeProPurchase){
        [self buyProductRequest];
    }else if (self.type == SMSSendTypeWithDrawal){
        NSLog(@"提现");
        [self withDrawRequest];
    }else if (self.type == SMSSendTypeProRedeem){
        [self proReduceRequest];
    }else if (self.type == SMSSendTypePhoneModtify){
        [self prePhoneModtifyRequest];
    }else if (self.type == SMSSendTypeTypeBindCardModify){
        [self bindCardUpdateRequest];
    }else if (self.type == SMSSendTypeBCSystemIdentify) {
        [self systemIdentifyConfirmSMSRequest];
    }else if (self.type == SMSSendTypeBCOpenAccount) {
        [self bcCommitOPenAccountValidateCodeRequest];
    }else if (self.type == SMSSendTypeBCRecharge) {
        [self bcConfirmRechargeInfoRequest];
    }else if (self.type == SMSSendTypeBCWithDrawal) {
        [self bcWithDrawRequest];
    }else if (self.type == SMSSendTypeBCProRedeem) {
        [self bcRedemptionConfirmRequest];
    }else if (self.type == SMSSendTypeBCProPurchase){
        [self bcPurchaseConfirmRequest];
    }else if (self.type == SMSSendTypeBCSignAtiveVerif) {
        [self bcRechargeV1SignActiveVerifRequest];
    }
    
    
    
}

- (void)smsBtnClick:(UIButton *)sender
{
    
    if (self.type == SMSSendTypeOpenAccount) {
        [self openAccountSMSRequest:sender];
    }else if (self.type == SMSSendTypeRecharge){
        [self transactionSMSRequest:sender];
    }else if (self.type == SMSSendTypeProPurchase){
        [self transactionSMSRequest:sender];
    }else if (self.type == SMSSendTypeWithDrawal){
        [self transactionSMSRequest:sender];
    }else if (self.type == SMSSendTypeProRedeem){
        [self transactionSMSRequest:sender];
    }else if (self.type == SMSSendTypePhoneModtify){
        [self transactionSMSRequest:sender];
    }else if (self.type == SMSSendTypeTypeBindCardModify){
        [self transactionSMSRequest:sender];
    }else if (self.type == SMSSendTypeBCSystemIdentify) {
        [self systemIdentifySMSRequest:sender];
    }else if (self.type == SMSSendTypeBCOpenAccount) {
        [self bcCommitOpenAccountInfoRequest];
    }else if (self.type == SMSSendTypeBCRecharge) {
        [self bcRechargeSendSMSMessageRequest];
    }else if (self.type == SMSSendTypeBCWithDrawal) {
        [self bcWithDrawSMSRequest];
    }else if (self.type == SMSSendTypeBCProRedeem) {
        [self checkBCProReduceRequest];
    }else if (self.type == SMSSendTypeBCProPurchase) {
        [self checkPurchaseRequest];
    }else if (self.type == SMSSendTypeBCSignAtiveVerif) {
        [self bcRechargeV1SignActiveApplyRequest];
    }
}

#pragma mark - 私有方法
/**
  录制
 */
- (void)openCameraForVideo
{
    // 一般情况下用这个判断
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        // 该设备不支持拍照
        
        [Tools showMessage:@"该设备不支持录像"];
        return;
    }
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.mediaTypes =  [[NSArray alloc] initWithObjects:(NSString*)kUTTypeMovie,nil];
    picker.videoMaximumDuration = 4.0; // 视频的最大录制时长
    picker.videoQuality = UIImagePickerControllerQualityTypeMedium;
    //picker.showsCameraControls = NO;
    picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo; //相机的模式 拍照/摄像
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:nil];
    
    
}

/**
 获取视频缩略图
 */

- (UIImage *)get_videoThumbImage:(NSURL *)videoURL
{
    NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:videoURL options:opts];
    AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
    generator.appliesPreferredTrackTransform = YES;
    CMTime actualTime;
    NSError *error = nil;
    CGImageRef img = [generator copyCGImageAtTime:CMTimeMake(0, 600) actualTime:&actualTime error:&error];
    if (error) {
        return nil;
    }
    return [UIImage imageWithCGImage:img];
}

- (CGFloat) getFileSize:(NSString *)path
{
    NSLog(@"%@",path);
    NSFileManager *fileManager = [NSFileManager defaultManager];
    float filesize = -1.0;
    if ([fileManager fileExistsAtPath:path]) {
        NSDictionary *fileDic = [fileManager attributesOfItemAtPath:path error:nil];//获取文件的属性
        unsigned long long size = [[fileDic objectForKey:NSFileSize] longLongValue];
        filesize = 1.0*size/1024;
    }else{
        NSLog(@"找不到文件");
    }
    return filesize;
}//此方法可以获取文件的大小，返回的是单位是KB。
- (CGFloat) getVideoLength:(NSURL *)URL
{
    
    AVURLAsset *avUrl = [AVURLAsset assetWithURL:URL];
    CMTime time = [avUrl duration];
    int second = ceil(time.value/time.timescale);
    return second;
}

- (NSString *)getCurrentTimeStamp
{
   NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    // 设置想要的格式，hh与HH的区别:分别表示12小时制,24小时制

    [formatter setDateFormat:@"yyyyMMdd"];

    NSDate *dateNow = [NSDate date];

    //把NSDate按formatter格式转成NSString

    NSString *currentTime = [formatter stringFromDate:dateNow];

    return currentTime;
}


#pragma mark - getters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - cl_kTabBarHeight)];
        _scrollView.showsVerticalScrollIndicator = NO;
        //_scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake(ScreenWidth, 0);
        
        //顶部view
        SMSVerificationTopView* topView = [self getXiblWithClassName:@"SMSVerificationTopView"];
        topView.frame = CGRectMake(0, 0, ScreenWidth, 296);
        [topView.confirmBtn  addTarget:self action:@selector(confirmBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [topView.smsBtn addTarget:self action:@selector(smsBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        if (self.type == SMSSendTypeOpenAccount) {
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[self.prePhone substringToIndex:3],[self.prePhone substringFromIndex:self.prePhone.length - 4]];
        }else if (self.type == SMSSendTypeRecharge){
            SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
            NSString*tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeProPurchase){
            SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
            NSString*tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeWithDrawal){
            SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
            NSString*tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeProRedeem){
            NSString*tel = [Tools isBlankString:self.buyedProModel.tel] ?@"" :self.buyedProModel.tel;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypePhoneModtify){
            NSString*tel = [Tools isBlankString:self.phone] ?@"" :self.phone;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeTypeBindCardModify){
            SaveAccountSubUserInfoModel*subModel =self.infoModel.SUBPACKS[0];
            NSString*tel = [Tools isBlankString:subModel.MO_PHONE] ?@"" :subModel.MO_PHONE;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeBCSystemIdentify) {
            NSString*tel = [Tools isBlankString:[getPeopleID PeopleIphoneNmber]] ?@"" :[getPeopleID PeopleIphoneNmber];
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeBCOpenAccount) {
            NSString*tel = self.prePhone;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeBCRecharge) {
            BCCardListModel *ccmodel = nil;
            if (self.bcAccountInfoModel.cardList.count > 0) {
                ccmodel = self.bcAccountInfoModel.cardList[0];
            }
            
            NSString*tel = ccmodel.bankCardPhone;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeBCWithDrawal) {
            BCCardListModel *ccmodel = nil;
            if (self.bcAccountInfoModel.cardList.count > 0) {
                ccmodel = self.bcAccountInfoModel.cardList[0];
            }
            NSString*tel = ccmodel.bankCardPhone;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeBCProRedeem) {
            BCCardListModel *ccmodel = nil;
            if (self.bcAccountInfoModel.cardList.count > 0) {
                ccmodel = self.bcAccountInfoModel.cardList[0];
            }
            NSString*tel = ccmodel.bankCardPhone;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeBCProPurchase) {
            NSString*tel = self.bcAccountInfoModel.bankCardPhone;
            topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[tel substringToIndex:3],[tel substringFromIndex:tel.length - 4]];
        }else if (self.type == SMSSendTypeBCSignAtiveVerif) {
            if (self.bcAccountInfoModel.cardList.count > 0) {
                BCCardListModel* cardModel = self.bcAccountInfoModel.cardList[0];
                topView.lb_phone.text = [NSString stringWithFormat:@"%@****%@",[cardModel.bankCardPhone substringToIndex:3] ,[cardModel.bankCardPhone substringFromIndex:cardModel.bankCardPhone.length - 4]];
            }
        }
        
        
        self.topView = topView;
        [_scrollView addSubview:topView];
//        [topView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.offset(0);
//            make.left.mas_equalTo(0);
//            make.width.mas_equalTo(ScreenWidth);
//            make.height.mas_greaterThanOrEqualTo(50);
//            make.bottom.mas_equalTo(0);
//        }];
        
        
        _scrollView.contentSize = CGSizeMake(ScreenWidth, topView.maxY + 10);
    }
    return _scrollView;
}

- (NSString *)FUNCTION
{
    if (!_FUNCTION) {
        switch (self.type) {
            case SMSSendTypeOpenAccount:
                _FUNCTION = @"OpenBankD_OpenAccount";
                break;
            case SMSSendTypeRecharge:
            _FUNCTION = @"OpenBankD_Recharge";
            break;
            case SMSSendTypeProPurchase:
            _FUNCTION = @"OpenBankD_ProPurchase";
            break;
            case SMSSendTypeWithDrawal:
            _FUNCTION = @"OpenBankD_Withdraw";
            break;
            case SMSSendTypeProRedeem:
            _FUNCTION = @"OpenBankD_ProRedem";
            break;
            case SMSSendTypePhoneModtify:
            _FUNCTION = @"OpenBankD_UpdMobNo";
            break;
            case SMSSendTypeTypeBindCardModify:
            _FUNCTION = @"OpenBankD_UpdBindCard";
            break;
                
            default:
                break;
        }
    }
    return _FUNCTION;
}

/*
#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
