| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- //
- // BindPhoneController.m
- // model
- //
- // Created by JuYi on 2018/7/16.
- // Copyright © 2018年 Mine. All rights reserved.
- // 绑定手机
- #import "BindPhoneController.h"
- #import "TableDefaultCell.h"
- #import "TableWithVerificationCodeCell.h"
- @interface BindPhoneController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate> {
- NSString *zhifubaoAccount;
- NSString *zhifubaoName;
- NSString *phoneNum;
- NSString *verifyCode;
- NSString *randomCode;
- }
- @property(nonatomic, strong) UITableView *tableView;
- @property(nonatomic, strong) TableDefaultCell *accountCell;
- @property(nonatomic, strong) TableDefaultCell *nameCell;
- @property(nonatomic, strong) TableDefaultCell *phoneCell;
- @property(nonatomic, strong) TableWithVerificationCodeCell *verificationCodeCell;
- @end
- @implementation BindPhoneController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
- //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。
- tapGestureRecognizer.cancelsTouchesInView = NO;
- //将触摸事件添加到当前view
- [self.view addGestureRecognizer:tapGestureRecognizer];
- //设置导航条
- [self creatNavBar];
- //设置子试图
- [self creatSubViews];
- }
- #pragma mark -- 收起键盘
- - (void)keyboardHide:(UITapGestureRecognizer *)tap {
- [self.view endEditing:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)creatNavBar {
- self.title = @"绑定手机";
- //
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(0, 0, 40, 40);
- [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
- [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
- UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
- self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
- }
- - (void)backClick {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)creatSubViews {
- //
- UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 16)];
- headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- //
- UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 220)];
- footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- UIButton *bindingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- bindingBtn.frame = CGRectMake(20, 39, ScreenWidth - 40, 45);
- [bindingBtn setBackgroundImage:[UIImage imageNamed:@"tixian-1"] forState:UIControlStateNormal];
- [bindingBtn setTitle:@"绑定" forState:UIControlStateNormal];
- [bindingBtn setTitleColor:RGBValueColor(0xffffff, 1.0) forState:UIControlStateNormal];
- [bindingBtn addTarget:self action:@selector(bindingBtnAction) forControlEvents:UIControlEventTouchUpInside];
- [footerView addSubview:bindingBtn];
- //
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
- self.tableView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableView.tableHeaderView = headerView;
- self.tableView.tableFooterView = footerView;
- [self.view addSubview:self.tableView];
- [self.tableView registerClass:[TableDefaultCell class] forCellReuseIdentifier:@"DefaultCell"];
- [self.tableView registerClass:[TableWithVerificationCodeCell class] forCellReuseIdentifier:@"VerificationCodeCell"];
- }
- #pragma mark -- UITableViewDelegate, UITableViewDataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 4;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == 0) {
- TableDefaultCell *accountCell = [tableView dequeueReusableCellWithIdentifier:@"DefaultCell" forIndexPath:indexPath];
- accountCell.titleLabel.text = @"提现账户";
- accountCell.contentTF.placeholder = @"请输入支付宝账户";
- accountCell.contentTF.keyboardType = UIKeyboardTypeDefault;
- accountCell.contentTF.delegate = self;
- accountCell.contentTF.tag = 1000;
- self.accountCell = accountCell;
- return accountCell;
- } else if (indexPath.row == 1) {
- TableDefaultCell *nameCell = [tableView dequeueReusableCellWithIdentifier:@"DefaultCell" forIndexPath:indexPath];
- nameCell.titleLabel.text = @"账户姓名";
- nameCell.contentTF.placeholder = @"请输入账户姓名";
- nameCell.contentTF.keyboardType = UIKeyboardTypeDefault;
- nameCell.contentTF.delegate = self;
- nameCell.contentTF.tag = 1001;
- self.nameCell = nameCell;
- return nameCell;
- } else if (indexPath.row == 2) {
- TableDefaultCell *phoneCell = [tableView dequeueReusableCellWithIdentifier:@"DefaultCell" forIndexPath:indexPath];
- phoneCell.titleLabel.text = @"手机号";
- phoneCell.contentTF.placeholder = @"请输入手机号";
- phoneCell.contentTF.keyboardType = UIKeyboardTypePhonePad;
- phoneCell.contentTF.delegate = self;
- phoneCell.contentTF.tag = 1002;
- self.phoneCell = phoneCell;
- return phoneCell;
- } else {
- TableWithVerificationCodeCell *verificationCodeCell = [tableView dequeueReusableCellWithIdentifier:@"VerificationCodeCell" forIndexPath:indexPath];
- verificationCodeCell.titleLabel.text = @"验证码";
- verificationCodeCell.contentTF.placeholder = @"请输入手机验证码";
- verificationCodeCell.contentTF.keyboardType = UIKeyboardTypeNumberPad;
- verificationCodeCell.contentTF.delegate = self;
- verificationCodeCell.contentTF.tag = 1003;
- [verificationCodeCell.codeBtn addTarget:self action:@selector(codeBtnAction) forControlEvents:UIControlEventTouchUpInside];
- self.verificationCodeCell = verificationCodeCell;
- return verificationCodeCell;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 50;
- }
- #pragma mark -- 绑定按钮
- - (void)bindingBtnAction {
- if (zhifubaoAccount.length == 0) {
- [MBProgressHUD showInfo:@"请输入支付宝账户"];
- return;
- }
- if (zhifubaoName.length == 0) {
- [MBProgressHUD showInfo:@"请输入账户姓名"];
- return;
- }
- if (phoneNum.length == 0) {
- [MBProgressHUD showInfo:@"请填写正确的手机号"];
- return;
- }
- if (verifyCode.length == 0 || ![verifyCode isEqualToString:randomCode]) {
- [MBProgressHUD showInfo:@"请填写正确的验证码"];
- return;
- }
- [self postBindingRequestToNetworking];
- }
- #pragma mark -- 网络请求
- - (void)postBindingRequestToNetworking {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- ModelUser *modelUser = [ModelUser user];
- NSDictionary *dic = @{@"modelpk": modelUser.modelpk, @"alipayid": zhifubaoAccount, @"name": zhifubaoName};
- [YanCNetWorkManager requestPostWithURLStr:Url_alipayoutcashmodify(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
- [MBProgressHUD showSuccess:@"绑定成功"];
- [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(backClick) userInfo:nil repeats:NO];
- } else {
- [MBProgressHUD showInfo:@"请求失败!"];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- #pragma mark -- 倒计时
- - (void)codeBtnAction {
- if ([Helper valiMobile:phoneNum]) {
- [self getVerifyCode];
- [self startCountdownAction];
- } else {
- [MBProgressHUD showInfo:@"请填写正确的手机号"];
- }
- }
- - (void)getVerifyCode {
- NSString *sn = @"SDK-FHD-010-00328";
- //NSString *md5Pwd = [MD5String md5String:[NSString stringWithFormat:@"%@%@",sn,password]];
- NSString *Md5Pwd = @"54774CB6E781A142206F756B3E18142C";
- int a = arc4random() % 100000;
- randomCode = [NSString stringWithFormat:@"%06d", a];
- NSString *content = [NSString stringWithFormat:@"【千模科技】您正在进行提现账号绑定,验证码%@,5分钟内有效。请勿泄露。来千模多挣钱,有钱日子天天过年。非本人操作,请勿理会。", randomCode];
- NSString *str = [NSString stringWithFormat:@"http://sdk.entinfo.cn:8061/mdsmssend.ashx?sn=%@&pwd=%@&mobile=%@&content=%@&ext=&stime=&rrid=&msgfmt=", sn, Md5Pwd, phoneNum, content];
- AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
- manager.responseSerializer = [AFHTTPResponseSerializer serializer];
- [manager GET:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- NSLog(@"%@", result);
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- NSLog(@"%@", error);
- }];
- }
- //获取验证码按钮开始倒计时响应事件
- - (void)startCountdownAction {
- __block int timeout = 60;//倒计时时间
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
- dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1.0 * NSEC_PER_SEC, 0); //每秒执行
- dispatch_source_set_event_handler(_timer, ^{
- if (timeout <= 1) {//倒计时结束,关闭
- dispatch_source_cancel(_timer);
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示根据自己需求设置
- [self.verificationCodeCell.codeBtn setTitle:@"重新获取" forState:UIControlStateNormal];
- self.verificationCodeCell.codeBtn.userInteractionEnabled = YES;
- });
- } else {
- int seconds = timeout;
- NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
- dispatch_async(dispatch_get_main_queue(), ^{
- //让按钮变为不可点击的灰色
- //并且关掉按钮的交互
- self.verificationCodeCell.codeBtn.userInteractionEnabled = NO;
- //设置界面的按钮显示根据自己需求设置
- [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:1];
- [self.verificationCodeCell.codeBtn setTitle:[NSString stringWithFormat:@"%@s", strTime] forState:UIControlStateNormal];
- [UIView commitAnimations];
- });
- timeout--;
- }
- });
- dispatch_resume(_timer);
- }
- #pragma mark -- UITextFieldDelegate
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- if ([textField viewWithTag:1002]) {
- if (string.length > 0 && (![NSString amtchString:string checkString:@"[0-9]"] || [textField.text length] == 11)) {
- return NO;
- }
- } else if ([textField viewWithTag:1003]) {
- if (string.length > 0 && [textField.text length] == 6) {
- return NO;
- }
- }
- return YES;
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField {
- if ([textField viewWithTag:1000]) {
- zhifubaoAccount = textField.text;
- } else if ([textField viewWithTag:1001]) {
- zhifubaoName = textField.text;
- } else if ([textField viewWithTag:1002]) {
- phoneNum = textField.text;
- } else if ([textField viewWithTag:1003]) {
- verifyCode = textField.text;
- }
- }
- @end
|