猎豆优选

LDLinkAliPayViewController.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //
  2. // LDLinkAliPayViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/31.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDLinkAliPayViewController.h"
  9. #import "WLCaptcheButton.h"
  10. @interface LDLinkAliPayViewController ()
  11. {
  12. NSString *_phone;
  13. }
  14. @property (nonatomic, strong) UIScrollView *scrollView;
  15. @property (nonatomic, strong) WLCaptcheButton *captcheButton;
  16. @end
  17. @implementation LDLinkAliPayViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self configNavigationBar];
  21. [self configUI];
  22. [self request];
  23. }
  24. - (void)configNavigationBar {
  25. NSString *navText = self.isUpdate?@"修改支付宝":@"绑定支付宝";
  26. [self.navigationBar setNavTitle:navText];
  27. self.navigationBar.backgroundColor = [UIColor changeColor];
  28. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  29. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  30. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  31. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  32. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  33. }
  34. - (void)backAction {
  35. [self.navigationController popViewControllerAnimated:YES];
  36. }
  37. - (void)configUI {
  38. [self.view addSubview:self.scrollView];
  39. NSArray *titles = @[@"真实姓名",@"支付宝账号",@"手机号码",@"验证码"];
  40. for (int i = 0; i < titles.count; i++) {
  41. UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(Fitsize(15), Fitsize(50)+Fitsize(41)*i, SCREEN_WIDTH-Fitsize(30), 1)];
  42. line.backgroundColor = [UIColor YHColorWithHex:0xE5E5E5];
  43. [self.scrollView addSubview:line];
  44. UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(Fitsize(15), 0, Fitsize(100), Fitsize(20))];
  45. title.font = [UIFont systemFontOfSize:Fitsize(16)];
  46. title.textColor = [UIColor YHColorWithHex:0x333333];
  47. title.text = titles[i];
  48. title.bottom = line.top-Fitsize(10);
  49. [self.scrollView addSubview:title];
  50. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(Fitsize(114), Fitsize(20)+Fitsize(22+20)*i, Fitsize(200), Fitsize(20))];
  51. textField.centerY = title.centerY;
  52. textField.textColor = [UIColor YHColorWithHex:0x333333];
  53. textField.font = [UIFont systemFontOfSize:Fitsize(16)];
  54. textField.tag = 1000+i;
  55. if (i == 0) {
  56. if (self.isUpdate) {
  57. textField.text = @"加载中...";
  58. }else {
  59. textField.placeholder = @"请输入真实姓名";
  60. }
  61. textField.clearButtonMode = UITextFieldViewModeAlways;
  62. }
  63. if (i == 1) {
  64. if (self.isUpdate) {
  65. textField.text = @"加载中...";
  66. }else {
  67. textField.placeholder = @"请输入支付宝账号";
  68. }
  69. textField.clearButtonMode = UITextFieldViewModeAlways;
  70. }
  71. if (i == 2) {
  72. textField.text = @"加载中...";
  73. textField.enabled = NO;
  74. textField.textColor = [UIColor YHColorWithHex:0x333333];
  75. }
  76. if (i == 3) {
  77. textField.keyboardType = UIKeyboardTypeNumberPad;
  78. textField.width = Fitsize(150);
  79. self.captcheButton = [[WLCaptcheButton alloc] init];
  80. self.captcheButton.layer.borderWidth = 1;
  81. self.captcheButton.layer.cornerRadius = Fitsize(12);
  82. self.captcheButton.layer.borderColor = [UIColor YHColorWithHex:0xFA2C36].CGColor;
  83. [self.captcheButton setTitleColor:[UIColor YHColorWithHex:0xFA2C36] forState:UIControlStateNormal];
  84. [self.captcheButton setTitle:@"获取验证码" forState:UIControlStateNormal];
  85. self.captcheButton.titleLabel.font = [UIFont systemFontOfSize:12];
  86. self.captcheButton.frame = CGRectMake(0, 0, Fitsize(84), Fitsize(22));
  87. self.captcheButton.centerY = textField.centerY;
  88. self.captcheButton.right = SCREEN_WIDTH-16;
  89. self.captcheButton.identifyKey = @"linkAlikey";
  90. [self.captcheButton addTarget:self action:@selector(sendCodeAction:) forControlEvents:UIControlEventTouchUpInside];
  91. [self.scrollView addSubview:self.captcheButton];
  92. textField.placeholder = @"请输入验证码";
  93. textField.clearButtonMode = UITextFieldViewModeAlways;
  94. UIButton *linkBtn = [[UIButton alloc] initWithFrame:CGRectMake(Fitsize(16), line.bottom+Fitsize(87), SCREEN_WIDTH-Fitsize(32), Fitsize(42))];
  95. linkBtn.backgroundColor = [UIColor homeRedColor];
  96. linkBtn.layer.cornerRadius = Fitsize(4);
  97. NSString *btnTitle = @"确定";
  98. [linkBtn setTitle:btnTitle forState:UIControlStateNormal];
  99. [linkBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  100. linkBtn.titleLabel.font = [UIFont systemFontOfSize:Fitsize(16)];
  101. linkBtn.centerX = line.centerX;
  102. [linkBtn addTarget:self action:@selector(linkAction) forControlEvents:UIControlEventTouchUpInside];
  103. [self.scrollView addSubview:linkBtn];
  104. }
  105. [self.scrollView addSubview:textField];
  106. }
  107. }
  108. - (void)request {
  109. if (self.isUpdate) {
  110. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/modifyAlipayAccountPage",BaseURL];
  111. [LDHttp post:url params:nil success:^(id json) {
  112. UITextField *phoneField = (UITextField *)[self.scrollView viewWithTag:1000+2];
  113. NSString *accountStr = json[@"data"][@"phone"];
  114. _phone = accountStr;
  115. NSString *newAccountStr;
  116. newAccountStr = [accountStr stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
  117. phoneField.text = newAccountStr;
  118. UITextField *nameField = (UITextField *)[self.scrollView viewWithTag:1000+0];
  119. nameField.text = json[@"data"][@"real_name"];
  120. UITextField *accountField = (UITextField *)[self.scrollView viewWithTag:1000+1];
  121. accountField.text = json[@"data"][@"alipay_account"];
  122. } failure:^(NSError *error) {
  123. }];
  124. }else {
  125. UITextField *nameField = (UITextField *)[self.scrollView viewWithTag:1000+0];
  126. [nameField becomeFirstResponder];
  127. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/getPhoneBindAlipay",BaseURL];
  128. [LDHttp post:url params:nil success:^(id json) {
  129. UITextField *phoneField = (UITextField *)[self.scrollView viewWithTag:1000+2];
  130. NSString *accountStr = json[@"phone"];
  131. _phone = accountStr;
  132. NSString *newAccountStr;
  133. newAccountStr = [accountStr stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
  134. phoneField.text = newAccountStr;
  135. } failure:^(NSError *error) {
  136. }];
  137. }
  138. }
  139. - (void)sendCodeAction:(WLCaptcheButton *)sender {
  140. UITextField *nameField = (UITextField *)[self.scrollView viewWithTag:1000+0];
  141. UITextField *accountField = (UITextField *)[self.scrollView viewWithTag:1000+1];
  142. if (nameField.text.length == 0 ) {
  143. [MBProgressHUD showMessage:@"请输入姓名"];
  144. return;
  145. }
  146. if (accountField.text.length == 0) {
  147. [MBProgressHUD showMessage:@"请输入支付宝账号"];
  148. return;
  149. }
  150. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/bindAlipaySendCode",BaseURL];
  151. NSString *ttl = [PublicFunction getNowTimeTimestamp];
  152. NSString *sign = [NSString stringWithFormat:@"phone=%@&ttl=%@%@",_phone,ttl,SignCode];
  153. NSString *md5Str = [PublicFunction md5:sign];
  154. NSDictionary *para = @{@"phone":_phone,
  155. @"ttl":ttl,
  156. @"sign":md5Str
  157. };
  158. [LDHttp post:url params:para success:^(id json) {
  159. UITextField *codeField = (UITextField *)[self.scrollView viewWithTag:1000+3];
  160. [codeField becomeFirstResponder];
  161. [sender fire];
  162. [MBProgressHUD showMessage:@"发送成功"];
  163. } failure:^(NSError *error) {
  164. }];
  165. }
  166. - (void)linkAction {
  167. UITextField *nameField = (UITextField *)[self.scrollView viewWithTag:1000+0];
  168. UITextField *accountField = (UITextField *)[self.scrollView viewWithTag:1000+1];
  169. UITextField *codeField = (UITextField *)[self.scrollView viewWithTag:1000+3];
  170. if (nameField.text.length == 0 ) {
  171. [MBProgressHUD showMessage:@"请输入姓名"];
  172. return;
  173. }
  174. if (accountField.text.length == 0) {
  175. [MBProgressHUD showMessage:@"请输入支付宝账号"];
  176. return;
  177. }
  178. if (codeField.text.length == 0) {
  179. [MBProgressHUD showMessage:@"请输入验证码"];
  180. return;
  181. }
  182. if (self.isUpdate) {
  183. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/modifyAlipayAccountCode",BaseURL];
  184. NSDictionary *para = @{@"phone":_phone,
  185. @"code":codeField.text,
  186. @"alipay_account":accountField.text,
  187. @"real_name":nameField.text
  188. };
  189. [LDHttp post:url params:para success:^(id json) {
  190. [MBProgressHUD showMessage:json[@"msg"]];
  191. if ([json[@"flag"] isEqual:@1]) {
  192. [self.navigationController popViewControllerAnimated:YES];
  193. }
  194. } failure:^(NSError *error) {
  195. }];
  196. }else {
  197. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/bindAlipayCheckCode",BaseURL];
  198. NSDictionary *para = @{@"phone":_phone,
  199. @"code":codeField.text,
  200. @"alipay_account":accountField.text,
  201. @"real_name":nameField.text
  202. };
  203. [LDHttp post:url params:para success:^(id json) {
  204. NSString *msg = json[@"msg"];
  205. [MBProgressHUD showMessage:msg];
  206. [self.navigationController popViewControllerAnimated:YES];
  207. } failure:^(NSError *error) {
  208. }];
  209. }
  210. }
  211. - (UIScrollView *)scrollView {
  212. if (!_scrollView) {
  213. _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
  214. _scrollView.backgroundColor = [UIColor whiteColor];
  215. _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight+1);
  216. _scrollView.showsVerticalScrollIndicator = NO;
  217. _scrollView.bounces = YES;
  218. }
  219. return _scrollView;
  220. }
  221. - (void)didReceiveMemoryWarning {
  222. [super didReceiveMemoryWarning];
  223. // Dispose of any resources that can be recreated.
  224. }
  225. /*
  226. #pragma mark - Navigation
  227. // In a storyboard-based application, you will often want to do a little preparation before navigation
  228. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  229. // Get the new view controller using [segue destinationViewController].
  230. // Pass the selected object to the new view controller.
  231. }
  232. */
  233. @end