// // LDLinkAliPayViewController.m // YouHuiProject // // Created by 小花 on 2018/7/31. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LDLinkAliPayViewController.h" #import "WLCaptcheButton.h" @interface LDLinkAliPayViewController () { NSString *_phone; } @property (nonatomic, strong) UIScrollView *scrollView; @property (nonatomic, strong) WLCaptcheButton *captcheButton; @end @implementation LDLinkAliPayViewController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configUI]; [self request]; } - (void)configNavigationBar { NSString *navText = self.isUpdate?@"修改支付宝":@"绑定支付宝"; [self.navigationBar setNavTitle:navText]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)configUI { [self.view addSubview:self.scrollView]; NSArray *titles = @[@"真实姓名",@"支付宝账号",@"手机号码",@"验证码"]; for (int i = 0; i < titles.count; i++) { UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(Fitsize(15), Fitsize(50)+Fitsize(41)*i, SCREEN_WIDTH-Fitsize(30), 1)]; line.backgroundColor = [UIColor YHColorWithHex:0xE5E5E5]; [self.scrollView addSubview:line]; UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(Fitsize(15), 0, Fitsize(100), Fitsize(20))]; title.font = [UIFont systemFontOfSize:Fitsize(16)]; title.textColor = [UIColor YHColorWithHex:0x333333]; title.text = titles[i]; title.bottom = line.top-Fitsize(10); [self.scrollView addSubview:title]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(Fitsize(114), Fitsize(20)+Fitsize(22+20)*i, Fitsize(200), Fitsize(20))]; textField.centerY = title.centerY; textField.textColor = [UIColor YHColorWithHex:0x333333]; textField.font = [UIFont systemFontOfSize:Fitsize(16)]; textField.tag = 1000+i; if (i == 0) { if (self.isUpdate) { textField.text = @"加载中..."; }else { textField.placeholder = @"请输入真实姓名"; } textField.clearButtonMode = UITextFieldViewModeAlways; } if (i == 1) { if (self.isUpdate) { textField.text = @"加载中..."; }else { textField.placeholder = @"请输入支付宝账号"; } textField.clearButtonMode = UITextFieldViewModeAlways; } if (i == 2) { textField.text = @"加载中..."; textField.enabled = NO; textField.textColor = [UIColor YHColorWithHex:0x333333]; } if (i == 3) { textField.keyboardType = UIKeyboardTypeNumberPad; textField.width = Fitsize(150); self.captcheButton = [[WLCaptcheButton alloc] init]; self.captcheButton.layer.borderWidth = 1; self.captcheButton.layer.cornerRadius = Fitsize(12); self.captcheButton.layer.borderColor = [UIColor YHColorWithHex:0xFA2C36].CGColor; [self.captcheButton setTitleColor:[UIColor YHColorWithHex:0xFA2C36] forState:UIControlStateNormal]; [self.captcheButton setTitle:@"获取验证码" forState:UIControlStateNormal]; self.captcheButton.titleLabel.font = [UIFont systemFontOfSize:12]; self.captcheButton.frame = CGRectMake(0, 0, Fitsize(84), Fitsize(22)); self.captcheButton.centerY = textField.centerY; self.captcheButton.right = SCREEN_WIDTH-16; self.captcheButton.identifyKey = @"linkAlikey"; [self.captcheButton addTarget:self action:@selector(sendCodeAction:) forControlEvents:UIControlEventTouchUpInside]; [self.scrollView addSubview:self.captcheButton]; textField.placeholder = @"请输入验证码"; textField.clearButtonMode = UITextFieldViewModeAlways; UIButton *linkBtn = [[UIButton alloc] initWithFrame:CGRectMake(Fitsize(16), line.bottom+Fitsize(87), SCREEN_WIDTH-Fitsize(32), Fitsize(42))]; linkBtn.backgroundColor = [UIColor homeRedColor]; linkBtn.layer.cornerRadius = Fitsize(4); NSString *btnTitle = @"确定"; [linkBtn setTitle:btnTitle forState:UIControlStateNormal]; [linkBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; linkBtn.titleLabel.font = [UIFont systemFontOfSize:Fitsize(16)]; linkBtn.centerX = line.centerX; [linkBtn addTarget:self action:@selector(linkAction) forControlEvents:UIControlEventTouchUpInside]; [self.scrollView addSubview:linkBtn]; } [self.scrollView addSubview:textField]; } } - (void)request { if (self.isUpdate) { NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/modifyAlipayAccountPage",BaseURL]; [LDHttp post:url params:nil success:^(id json) { UITextField *phoneField = (UITextField *)[self.scrollView viewWithTag:1000+2]; NSString *accountStr = json[@"data"][@"phone"]; _phone = accountStr; NSString *newAccountStr; newAccountStr = [accountStr stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"]; phoneField.text = newAccountStr; UITextField *nameField = (UITextField *)[self.scrollView viewWithTag:1000+0]; nameField.text = json[@"data"][@"real_name"]; UITextField *accountField = (UITextField *)[self.scrollView viewWithTag:1000+1]; accountField.text = json[@"data"][@"alipay_account"]; } failure:^(NSError *error) { }]; }else { UITextField *nameField = (UITextField *)[self.scrollView viewWithTag:1000+0]; [nameField becomeFirstResponder]; NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/getPhoneBindAlipay",BaseURL]; [LDHttp post:url params:nil success:^(id json) { UITextField *phoneField = (UITextField *)[self.scrollView viewWithTag:1000+2]; NSString *accountStr = json[@"phone"]; _phone = accountStr; NSString *newAccountStr; newAccountStr = [accountStr stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"]; phoneField.text = newAccountStr; } failure:^(NSError *error) { }]; } } - (void)sendCodeAction:(WLCaptcheButton *)sender { UITextField *nameField = (UITextField *)[self.scrollView viewWithTag:1000+0]; UITextField *accountField = (UITextField *)[self.scrollView viewWithTag:1000+1]; if (nameField.text.length == 0 ) { [MBProgressHUD showMessage:@"请输入姓名"]; return; } if (accountField.text.length == 0) { [MBProgressHUD showMessage:@"请输入支付宝账号"]; return; } NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/bindAlipaySendCode",BaseURL]; NSString *ttl = [PublicFunction getNowTimeTimestamp]; NSString *sign = [NSString stringWithFormat:@"phone=%@&ttl=%@%@",_phone,ttl,SignCode]; NSString *md5Str = [PublicFunction md5:sign]; NSDictionary *para = @{@"phone":_phone, @"ttl":ttl, @"sign":md5Str }; [LDHttp post:url params:para success:^(id json) { UITextField *codeField = (UITextField *)[self.scrollView viewWithTag:1000+3]; [codeField becomeFirstResponder]; [sender fire]; [MBProgressHUD showMessage:@"发送成功"]; } failure:^(NSError *error) { }]; } - (void)linkAction { UITextField *nameField = (UITextField *)[self.scrollView viewWithTag:1000+0]; UITextField *accountField = (UITextField *)[self.scrollView viewWithTag:1000+1]; UITextField *codeField = (UITextField *)[self.scrollView viewWithTag:1000+3]; if (nameField.text.length == 0 ) { [MBProgressHUD showMessage:@"请输入姓名"]; return; } if (accountField.text.length == 0) { [MBProgressHUD showMessage:@"请输入支付宝账号"]; return; } if (codeField.text.length == 0) { [MBProgressHUD showMessage:@"请输入验证码"]; return; } if (self.isUpdate) { NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/modifyAlipayAccountCode",BaseURL]; NSDictionary *para = @{@"phone":_phone, @"code":codeField.text, @"alipay_account":accountField.text, @"real_name":nameField.text }; [LDHttp post:url params:para success:^(id json) { [MBProgressHUD showMessage:json[@"msg"]]; if ([json[@"flag"] isEqual:@1]) { [self.navigationController popViewControllerAnimated:YES]; } } failure:^(NSError *error) { }]; }else { NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/bindAlipayCheckCode",BaseURL]; NSDictionary *para = @{@"phone":_phone, @"code":codeField.text, @"alipay_account":accountField.text, @"real_name":nameField.text }; [LDHttp post:url params:para success:^(id json) { NSString *msg = json[@"msg"]; [MBProgressHUD showMessage:msg]; [self.navigationController popViewControllerAnimated:YES]; } failure:^(NSError *error) { }]; } } - (UIScrollView *)scrollView { if (!_scrollView) { _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)]; _scrollView.backgroundColor = [UIColor whiteColor]; _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight+1); _scrollView.showsVerticalScrollIndicator = NO; _scrollView.bounces = YES; } return _scrollView; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end