TopUpMoneyVC.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. //
  2. // TopUpMoneyVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/8/23.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "TopUpMoneyVC.h"
  9. #import "BankCardView.h"
  10. #import "Order.h"
  11. #import "DataSigner.h"
  12. #import <AlipaySDK/AlipaySDK.h>
  13. #import <WechatOpenSDK/WXApi.h>
  14. #import <WechatOpenSDK/WXApiObject.h>
  15. @interface TopUpMoneyVC ()<UITextFieldDelegate>
  16. {
  17. UIView *payTypeView;
  18. UIButton *payTypeBtn;
  19. UITextField *payMoneyTF;
  20. UIButton *continueBtn;
  21. UILabel *balanceLabel;
  22. UIView *backView;
  23. UIView *btnBar;
  24. UIImageView *selectedPayStyleImg;
  25. UIView *skipView;
  26. NSTimer *timer;
  27. NSArray *bankCardArray;
  28. NSInteger payType;
  29. NSDictionary *orderDic;
  30. NSString *rsaOrderString;
  31. }
  32. @end
  33. @implementation TopUpMoneyVC
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. [self myInit];
  37. }
  38. -(void)viewWillDisappear:(BOOL)animated
  39. {
  40. [super viewWillDisappear:animated];
  41. if (backView) {
  42. [backView removeFromSuperview];
  43. }
  44. if (timer) {
  45. [timer invalidate];
  46. timer = nil;
  47. }
  48. }
  49. -(void)myInit
  50. {
  51. [self configNavigationBar];
  52. [self.view setBackgroundColor:backGroundColor];
  53. payType = 0;
  54. bankCardArray = [NSArray array];
  55. CGFloat x,y,w,h;
  56. x = 0;
  57. y = 15;
  58. w = kSize.width;
  59. h = 60;
  60. payTypeView = [[UIView alloc] setxywh];
  61. payTypeView.backgroundColor = [UIColor whiteColor];
  62. [self.view addSubview:payTypeView];
  63. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 30, 20, 10, 20)];
  64. imgView.image = [UIImage imageNamed:@"more_right_arrow.png"];
  65. [payTypeView addSubview:imgView];
  66. UILabel *payTypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, w, h)];
  67. [payTypeLabel setText:@"请选择支付方式" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  68. [payTypeView addSubview:payTypeLabel];
  69. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  70. btn.frame = setDIYFrame;
  71. btn.backgroundColor = [UIColor clearColor];
  72. [btn target:self tag:1];
  73. [self.view addSubview:btn];
  74. payTypeBtn = btn;
  75. [payTypeBtn addViewWithRect:CGRectMake(x, 0, w, 15)];
  76. y += h;
  77. if (self.type == 1) {
  78. [self setTitle:@"我要充值"];
  79. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"限额说明" style:UIBarButtonItemStyleDone target:self action:@selector(clickToLimit)];
  80. [item setTintColor:defGreen];
  81. [self.navigationItem setRightBarButtonItem:item];
  82. x = 20;
  83. w -= 40;
  84. h = 40;
  85. UILabel *label = [[UILabel alloc] setxywh];
  86. label.backgroundColor = backGroundColor;
  87. [label setText:@"该账户本次最多可充值10,000.00元" Font:Font17 TextColor:contentTextColor];
  88. [self.view addSubview:label];
  89. x = 0;
  90. y += h;
  91. w += 40;
  92. h = 50;
  93. UIView *payMoneyView = [[UIView alloc] setxywh];
  94. payMoneyView.backgroundColor = [UIColor whiteColor];
  95. [self.view addSubview:payMoneyView];
  96. x = 20;
  97. w = 50;
  98. label = [[UILabel alloc] setxywh];
  99. [label setText:@"金额" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  100. [self.view addSubview:label];
  101. x += w;
  102. w = kSize.width - x - 20;
  103. payMoneyTF = [[UITextField alloc] setxywh];
  104. payMoneyTF.placeholder = @"请输入充值金额";
  105. payMoneyTF.keyboardType = UIKeyboardTypeNumberPad;
  106. payMoneyTF.delegate = self;
  107. [self.view addSubview:payMoneyTF];
  108. if (_neededMoney.length > 0) {
  109. payMoneyTF.text = _neededMoney;
  110. [continueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  111. [continueBtn setBackgroundColor:[UIColor colorWithRed:55/255.0 green:147/255.0 blue:239/255.0 alpha:1]];
  112. [continueBtn setUserInteractionEnabled:YES];
  113. }
  114. x = 20;
  115. y += h + 30;
  116. w = kSize.width - 40;
  117. h = 50;
  118. continueBtn = [[UIButton alloc] setxywh];
  119. [continueBtn setTitle:@"下一步" textColor:contentTextColor font:FontTitle fotState:UIControlStateNormal];
  120. continueBtn.backgroundColor = KlineColor;
  121. continueBtn.layer.masksToBounds = YES;
  122. continueBtn.layer.cornerRadius = 4;
  123. [continueBtn target:self tag:2];
  124. [continueBtn setUserInteractionEnabled:NO];
  125. [self.view addSubview:continueBtn];
  126. }else{
  127. [self setTitle:@"提现"];
  128. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"转出说明" style:UIBarButtonItemStyleDone target:self action:@selector(clickToCash)];
  129. [item setTintColor:defGreen];
  130. [self.navigationItem setRightBarButtonItem:item];
  131. [payTypeBtn addViewWithRect:CGRectMake(x, y, w, 20)];
  132. y += 20;
  133. h = 140;
  134. UIView *payMoneyView = [[UIView alloc] setxywh];
  135. payMoneyView.backgroundColor = [UIColor whiteColor];
  136. [self.view addSubview:payMoneyView];
  137. x = 20;
  138. w -= 40;
  139. h = 39;
  140. UILabel *label = [[UILabel alloc] setxywh];
  141. [label setText:@"提现金额" Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  142. [self.view addSubview:label];
  143. y += h;
  144. w = 30;
  145. h = 60;
  146. label = [[UILabel alloc] setxywh];
  147. [label setText:@"¥" Font:30 TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  148. [self.view addSubview:label];
  149. x += w;
  150. w = kSize.width - x - 20;
  151. payMoneyTF = [[UITextField alloc] setxywh];
  152. //payMoneyTF.placeholder = @"请输入充值金额";
  153. payMoneyTF.keyboardType = UIKeyboardTypeNumberPad;
  154. payMoneyTF.delegate = self;
  155. [self.view addSubview:payMoneyTF];
  156. [payMoneyTF addViewWithRect:CGRectMake(20, y + h, kSize.width - 40, 1)];
  157. y += h + 1;
  158. x = 20;
  159. w = kSize.width - 100 - x;
  160. h = 40;
  161. label = [[UILabel alloc] setxywh];
  162. [label setText:@"可用余额2.00元" Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  163. [self.view addSubview:label];
  164. balanceLabel = label;
  165. x += w;
  166. w = 80;
  167. UIButton *btn = [[UIButton alloc] setxywh];
  168. [btn setTitle:@"全部提现" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
  169. [btn target:self tag:3];
  170. [self.view addSubview:btn];
  171. y += h + 15;
  172. x = 20;
  173. w = h = 20;
  174. UIImageView *imageView = [[UIImageView alloc] setxywh];
  175. imageView.image = [UIImage imageNamed:@"payFault.png"];
  176. [self.view addSubview:imageView];
  177. x += w + 5;
  178. w = kSize.width - x - 20;
  179. label = [[UILabel alloc] setxywh];
  180. [label setText:@"两小时内到账,确认提现" Font:Font17 TextColor:[UIColor colorWithRed:252/255.0 green:85/255.0 blue:117/255.0 alpha:1] Alignment:NSTextAlignmentLeft];
  181. [self.view addSubview:label];
  182. y += 30 + h;
  183. x = 20;
  184. w = kSize.width - 40;
  185. h = 50;
  186. continueBtn = [[UIButton alloc] setxywh];
  187. [continueBtn setTitle:@"确认转出" textColor:contentTextColor font:FontTitle fotState:UIControlStateNormal];
  188. continueBtn.backgroundColor = KlineColor;
  189. continueBtn.layer.masksToBounds = YES;
  190. continueBtn.layer.cornerRadius = 4;
  191. [continueBtn target:self tag:3];
  192. [continueBtn setUserInteractionEnabled:NO];
  193. [self.view addSubview:continueBtn];
  194. }
  195. }
  196. -(void)btnClick:(UIButton *)sender
  197. {
  198. [self.view endEditing:YES];
  199. if (sender.tag < 0) {
  200. [skipView removeFromSuperview];
  201. if (sender.tag == -1) {
  202. //支付成功的返回按钮
  203. [self.navigationController popViewControllerAnimated:YES];
  204. }
  205. if (sender.tag == -2) {
  206. //支付失败查看订单的页面3
  207. //[self.navigationController popViewControllerAnimated:YES];
  208. }
  209. if (sender.tag == -3) {
  210. //支付失败重新支付
  211. [self clickToAliPay];
  212. }
  213. }
  214. if (sender.tag == 1) {
  215. //选择支付 或提现账号
  216. [self getMyBanks];
  217. }
  218. if (sender.tag == 2) {
  219. if (payType == 0) {
  220. ShowMsg(@"请选择支付方式");
  221. return;
  222. }
  223. //下一步 充值按钮
  224. [self uploadRechargeInfo];
  225. }
  226. if (sender.tag == 3) {
  227. //下一步 提现按钮
  228. }
  229. if (sender.tag == 6) {
  230. //使用新卡支付
  231. ShowMsg(@"暂未开通,敬请期待");
  232. return;
  233. }
  234. if (sender.tag > 6) {
  235. selectedPayStyleImg.y = sender.y + 15;
  236. selectedPayStyleImg.x = kSize.width - 50;
  237. [self selectdePayTypeWithTag:sender.tag];
  238. }
  239. }
  240. -(void)selectdePayTypeWithTag:(NSInteger)btnTag
  241. {
  242. if (btnTag == 7 || btnTag == 8 || btnTag == 9) {
  243. //使用支付宝、微信、QQ钱包来支付
  244. // if (btnTag == 8 || btnTag == 9) {
  245. // ShowMsg(@"暂未开通,敬请期待");
  246. // return;
  247. // }
  248. payType = btnTag;//设置支付类型
  249. for (UIView *payTypeSubview in payTypeView.subviews) {
  250. [payTypeSubview removeFromSuperview];
  251. }
  252. NSArray *imgArray = @[@"AliPay.png",@"WebPay.png",@"WebPay.png"];
  253. NSArray *titleArray = @[@"支付宝",@"微信",@"QQ钱包"];
  254. UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 40, 40)];
  255. img.image = [UIImage imageNamed:imgArray[btnTag - 7]];
  256. [payTypeView addSubview:img];
  257. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, 100, 60)];
  258. [label setText:titleArray[btnTag - 7] Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  259. [payTypeView addSubview:label];
  260. }
  261. if (btnTag > 9) {
  262. //使用银行卡来支付
  263. ShowMsg(@"暂未开通,敬请期待");
  264. payType = btnTag;//设置支付类型
  265. for (UIView *payTypeSubview in payTypeView.subviews) {
  266. [payTypeSubview removeFromSuperview];
  267. }
  268. NSDictionary *dic = bankCardArray[btnTag - 10];
  269. BankCardView *bankV = [[BankCardView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 60)];
  270. [bankV setDataDic:dic];
  271. [payTypeView addSubview:bankV];
  272. }
  273. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 30, 20, 10, 20)];
  274. imgView.image = [UIImage imageNamed:@"more_right_arrow.png"];
  275. [payTypeView addSubview:imgView];
  276. [self removeSearchView];//关闭选择框
  277. }
  278. //额度和转出说明
  279. -(void)clickToLimit
  280. {
  281. TopUpMoneyVC *vc = [[TopUpMoneyVC alloc] init];
  282. vc.type = 2;
  283. [self navPushHideTabbarToVC:vc];
  284. }
  285. -(void)clickToCash
  286. {
  287. }
  288. #pragma mark 创建银行卡选择项
  289. -(void)creatSheetView
  290. {
  291. backView = [[UIView alloc] initWithFrame:kFrame];
  292. backView.backgroundColor = [UIColor colorWithWhite:.7 alpha:.1];
  293. UITapGestureRecognizer *tapGR=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  294. [backView addGestureRecognizer:tapGR];
  295. [[UIApplication sharedApplication].keyWindow addSubview:backView];
  296. btnBar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height, kSize.width, kSize.height - 200 - kNavOffSet)];
  297. [btnBar setBackgroundColor:[UIColor whiteColor]];
  298. [backView addSubview:btnBar];
  299. CGFloat x,y,w,h;
  300. x = y = 0;
  301. w = kSize.width;
  302. h = 40;
  303. UILabel *label = [[UILabel alloc] setxywh];
  304. [label setText:@"" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  305. [btnBar addSubview:label];
  306. [label addViewWithRect:CGRectMake(0, h, w, 1)];
  307. w = 100;
  308. UIButton *backBtn = [[UIButton alloc] setxywh];
  309. [backBtn addTarget:self action:@selector(removeSearchView) forControlEvents:UIControlEventTouchUpInside];
  310. [backBtn setImage:[[UIImage imageNamed:@"drawer_img08"] tint:[UIColor lightGrayColor]] forState:UIControlStateNormal];
  311. [backBtn setImageEdgeInsets:UIEdgeInsetsMake(5, 20, 5, 50)];
  312. [btnBar addSubview:backBtn];
  313. w = kSize.width;
  314. y += h + 1;
  315. h = btnBar.height - y;
  316. UIScrollView *scrollView = [[UIScrollView alloc] setxywh];
  317. [btnBar addSubview:scrollView];
  318. //选中的标示
  319. selectedPayStyleImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paySelected.png"]];
  320. selectedPayStyleImg.frame = CGRectMake(kSize.width, 0, 30, 30);
  321. [scrollView addSubview:selectedPayStyleImg];
  322. //支付宝 微信 QQ钱包 7、8、9 要的写 不要的不写 然后新卡的话 tag为6 银行卡的tag从10开始
  323. if (self.type == 1) {
  324. [label setText:@"选择付款方式"];
  325. }else{
  326. [label setText:@"选择提现账号"];
  327. }
  328. x = y = 0;
  329. h = 60;
  330. NSArray *imgArray = @[@"AliPay.png",@"WebPay.png",@"QQPay.png"];
  331. NSArray *titleArray = @[@"支付宝",@"微信",@"QQ钱包"];
  332. for (int i = 0; i < 3; i ++) {
  333. UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10+i*h, 40, 40)];
  334. img.image = [UIImage imageNamed:imgArray[i]];
  335. [scrollView addSubview:img];
  336. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70, i*h, 100, 60)];
  337. [label setText:titleArray[i] Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  338. [scrollView addSubview:label];
  339. [label addViewWithRect:CGRectMake(20, (i + 1)*h - 1.5, kSize.width - 40, 1.5)];
  340. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x, i*h, w, h)];
  341. [btn setBackgroundColor:[UIColor clearColor]];
  342. [btn target:self tag:i + 7];//7 8 9
  343. [btn setBackgroundImage:[UIImage imageWithColor:KlineColor] forState:UIControlStateHighlighted];
  344. [scrollView addSubview:btn];
  345. }
  346. y += 60*titleArray.count;
  347. //银行卡
  348. for (int i = 0; i < bankCardArray.count; i ++) {
  349. NSDictionary *dic = bankCardArray[i];
  350. BankCardView *bankV = [[BankCardView alloc] initWithFrame:CGRectMake(0, y+i*h, kSize.width, h)];
  351. [bankV setDataDic:dic];
  352. [scrollView addSubview:bankV];
  353. [bankV addViewWithRect:CGRectMake(20, y + (i + 1)*h - 1.5, kSize.width - 40, 1.5)];
  354. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y + i*h, w, h)];
  355. [btn setBackgroundColor:[UIColor clearColor]];
  356. [btn target:self tag:i + 10];//从10开始
  357. [btn setBackgroundImage:[UIImage imageWithColor:KlineColor] forState:UIControlStateHighlighted];
  358. [scrollView addSubview:btn];
  359. }
  360. y += 60*bankCardArray.count;
  361. //暂设置提现只能提到充值过得卡中 如果以后提现可以提到任意卡中(除信用卡)那么就把 使用新卡付款 改为 使用新卡提现
  362. if (self.type == 1) {
  363. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
  364. //[btn setBackgroundColor:[UIColor clearColor]];
  365. [btn setTitle:@"使用新卡付款" textColor:kTitleColor font:FontTitle fotState:UIControlStateNormal];
  366. [btn target:self tag:6];//6
  367. [scrollView addSubview:btn];
  368. [btn addViewWithRect:CGRectMake(20, y + h - 1.5, kSize.width - 40, 1.5)];
  369. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 30, y + 20, 10, 20)];
  370. imgView.image = [UIImage imageNamed:@"more_right_arrow.png"];
  371. [scrollView addSubview:imgView];
  372. y += h;
  373. }
  374. [scrollView setContentSize:CGSizeMake(kSize.width, y + 20)];
  375. //做弹出浅入动画
  376. [UIView animateWithDuration:.4 animations:^{
  377. backView.backgroundColor = [UIColor colorWithWhite:.3 alpha:.5];
  378. btnBar.y = 200 + kNavOffSet;
  379. }];
  380. }
  381. -(void)tapAction:(UITapGestureRecognizer *)gesture
  382. {
  383. //做关闭的操作
  384. [self removeSearchView];
  385. }
  386. -(void)removeSearchView
  387. {
  388. [UIView animateWithDuration:.4 animations:^{
  389. backView.backgroundColor = [UIColor colorWithWhite:.7 alpha:.1];
  390. btnBar.y = kSize.height;
  391. } completion:^(BOOL finished) {
  392. [backView removeFromSuperview];
  393. //[btnBar removeFromSuperview];
  394. }];
  395. }
  396. #pragma mark textField delegate
  397. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  398. {
  399. if (textField.text.length > 0 && [textField.text floatValue] == 0.0 && [string isEqualToString:@"0"]) {
  400. return NO;
  401. }
  402. NSString *currentString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  403. if ([currentString floatValue] > 0.0) {
  404. [continueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  405. [continueBtn setBackgroundColor:[UIColor colorWithRed:55/255.0 green:147/255.0 blue:239/255.0 alpha:1]];
  406. [continueBtn setUserInteractionEnabled:YES];
  407. }else{
  408. [continueBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  409. [continueBtn setBackgroundColor:KlineColor];
  410. [continueBtn setUserInteractionEnabled:NO];
  411. }
  412. return YES;
  413. }
  414. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  415. {
  416. [self.view endEditing:YES];
  417. }
  418. #pragma mark 数据请求
  419. //获取我的银行卡列表信息
  420. -(void)getMyBanks
  421. {
  422. //NSLog(@"-----><><><>%d",payTypeBtn.isUserInteractionEnabled);
  423. [payTypeBtn setUserInteractionEnabled:NO];
  424. if (![Util connectedToNetWork]) {
  425. [self creatSheetView];
  426. showMsgUnconnect();
  427. return;
  428. }
  429. NSMutableArray *arr=[NSMutableArray array];
  430. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  431. NSString* method = @"getMyBanks";
  432. [MBProgressHUD showLoadToView:self.view];
  433. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  434. [MBProgressHUD hideHUDForView:self.view];
  435. [payTypeBtn setUserInteractionEnabled:YES];
  436. //NSLog(@"我的银行卡列表-->%@-->%@",arr,root);
  437. if (!root) {
  438. ShowMsg(@"未获取到您的银行卡信息,请重试");
  439. [self creatSheetView];
  440. return;
  441. }
  442. if ([root[@"code"] isEqualToString:@"1"]) {
  443. ShowMsg(root[@"body"]);
  444. [self creatSheetView];
  445. return;
  446. }
  447. bankCardArray = root[@"body"];
  448. [self creatSheetView];
  449. }];
  450. }
  451. //获取我的订单状态 暂未用到
  452. //-(void)getTradeStatusIsOkAsyc
  453. //{
  454. // [MBProgressHUD showLoadToView:self.view];
  455. // [self performSelectorInBackground:@selector(getTradeStatusIsOk) withObject:nil];
  456. //}
  457. //-(void)getTradeStatusIsOk
  458. //{
  459. // if (![Util connectedToNetWork]) {
  460. // [self creatSheetView];
  461. // showMsgUnconnect();
  462. // return;
  463. // }
  464. //
  465. // ServiceHelper *helper = [[ServiceHelper alloc] init];
  466. // NSMutableArray *arr=[NSMutableArray array];
  467. //
  468. // [arr addPro:@"serviceName" Value:defaultServiceName];
  469. // [arr addPro:@"key" Value:[defaultKey md5Encrypt]];
  470. // [arr addPro:@"id" Value:orderDic[@"tradeId"]];//订单状态
  471. //
  472. // NSString* method = @"getTradeStatusIsOk";
  473. // NSString* soapMsg = [SoapHelper arrayToDefaultSoapMessage:arr methodName:method];
  474. // NSString *xml=[helper syncServiceMethod:method soapMessage:soapMsg];
  475. // [MBProgressHUD hideHUDForView:self.view];
  476. // NSDictionary* root = [xml jsonObject];
  477. //
  478. // //NSLog(@"我的订单状态-->%@-->%@",arr,root);
  479. // if (!root) {
  480. // ShowMsg(@"交易异常,请查看账户余额");
  481. // return;
  482. // }
  483. // if ([root[@"code"] isEqualToString:@"1"]) {
  484. // ShowMsg(root[@"body"]);
  485. // return;
  486. // }
  487. //
  488. // dispatch_async(dispatch_get_main_queue(), ^{
  489. //
  490. //
  491. //
  492. //
  493. // });
  494. //}
  495. //充值接口
  496. -(void)uploadRechargeInfo
  497. {
  498. [self clickToWechatPay];
  499. /*
  500. if (![Util connectedToNetWork]) {
  501. showMsgUnconnect();
  502. return;
  503. }
  504. NSString *payTypeString = @"";
  505. if (payType < 10) {
  506. payTypeString = [NSString stringWithFormat:@"%d",(int)(payType - 6)];
  507. }else{
  508. payTypeString = @"4";
  509. }
  510. NSMutableArray *arr=[NSMutableArray array];
  511. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  512. [arr addPro:@"money" Value:payMoneyTF.text];
  513. [arr addPro:@"payType" Value:payTypeString];//1 支付宝 2 微信 3 QQ钱包 4 银行卡
  514. [arr addPro:@"title" Value:@"优易学车充值"];
  515. [arr addPro:@"demo" Value:@"余额充值"];
  516. NSString* method = @"sd_imageWithGIFData";
  517. [MBProgressHUD showLoadToView:self.view];
  518. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  519. [MBProgressHUD hideHUDForView:self.view];
  520. NSLog(@"充值-->%@-->%@",arr,root);
  521. if (!root) {
  522. ShowMsg(@"充值失败,请重试");
  523. return;
  524. }
  525. if ([root[@"code"] isEqualToString:@"1"]) {
  526. ShowMsg(root[@"body"]);
  527. return;
  528. }
  529. //orderDic = root[@"body"];
  530. rsaOrderString = root[@"body"];
  531. rsaOrderString = [rsaOrderString stringByReplacingOccurrencesOfString:@"amp;" withString:@""];
  532. //充值成功 调支付接口
  533. //充值成功 调支付接口
  534. if ([payTypeString isEqualToString:@"1"]) {
  535. [self clickToAliPay];
  536. }else if ([payTypeString isEqualToString:@"2"]) {
  537. [self clickToWechatPay];
  538. }
  539. }];
  540. */
  541. }
  542. - (void)clickToWechatPay {
  543. // 发起微信支付,设置参数
  544. //需要创建这个支付对象
  545. PayReq *req = [[PayReq alloc] init];
  546. //由用户微信号和AppID组成的唯一标识,用于校验微信用户
  547. req.openID = WEIXIN_APPID;
  548. // 商家id,在注册的时候给的
  549. req.partnerId = @"1539360921";
  550. // 预支付订单这个是后台跟微信服务器交互后,微信服务器传给你们服务器的,你们服务器再传给你
  551. req.prepayId = @"wx04172515935255d860df5b9a0892674222";
  552. // 根据财付通文档填写的数据和签名
  553. req.package = @"Sign=WXPay";
  554. // 随机编码,为了防止重复的,在后台生成
  555. req.nonceStr = @"aJIXjLdXQLpEHB8R";
  556. // 这个是时间戳,也是在后台生成的,为了验证支付的
  557. NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
  558. formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  559. [formatter setDateStyle:NSDateFormatterMediumStyle];
  560. [formatter setTimeStyle:NSDateFormatterShortStyle];
  561. [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
  562. NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
  563. [formatter setTimeZone:timeZone];
  564. NSDate *datenow = [NSDate date];
  565. NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
  566. NSString * stamp = timeSp;
  567. req.timeStamp = (UInt32)stamp.intValue;
  568. // 这个签名也是后台做的
  569. req.sign = @"B86B1200B6CC0649519590A65BA7C14C";
  570. //发送请求到微信,等待微信返回onResp
  571. [WXApi sendReq:req completion:nil];
  572. }
  573. -(void)clickToAliPay
  574. {
  575. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AliPayResultNoti:) name:ALI_PAY_RESULT object:nil];
  576. [[AlipaySDK defaultService] payOrder:rsaOrderString fromScheme:aliPayScheme callback:^(NSDictionary *resultDic) {
  577. //NSLog(@"reslutAP页面 = %@",resultDic);
  578. //是9000代表支付成功
  579. if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
  580. //支付成功
  581. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
  582. }else{
  583. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
  584. }
  585. }];
  586. }
  587. -(void)clickToAliPayOld
  588. {
  589. /*
  590. *商户的唯一的parnter和seller。
  591. *签约后,支付宝会为每个商户分配一个唯一的 parnter 和 seller。
  592. */
  593. /*============================================================================*/
  594. /*=======================需要填写商户app申请的===================================*/
  595. /*============================================================================*/
  596. //这个要写在一个按钮的方法中
  597. NSString *partner = aliPartner;
  598. NSString *seller = aliSeller;
  599. NSString *privateKey = aliPrivateKey;
  600. /*============================================================================*/
  601. /*============================================================================*/
  602. /*============================================================================*/
  603. //partner和seller获取失败,提示
  604. if ([partner length] == 0 ||
  605. [seller length] == 0 ||
  606. [privateKey length] == 0)
  607. {
  608. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
  609. message:@"支付发生错误 错误码1000"
  610. delegate:nil
  611. cancelButtonTitle:@"确定"
  612. otherButtonTitles:nil];
  613. [alert show];
  614. return;
  615. }
  616. /*
  617. *生成订单信息及签名
  618. */
  619. //将商品信息赋予AlixPayOrder的成员变量
  620. Order *order = [[Order alloc] init];
  621. order.partner = partner;
  622. order.sellerID = seller;
  623. order.outTradeNO = orderDic[@"orderNo"]; //订单ID(由商家自行制定)
  624. // order.subject = [NSString stringWithCString:[sub UTF8String] encoding:NSUnicodeStringEncoding]; //商品标题
  625. // order.body = [bod stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];; //商品描述
  626. order.subject = @"优易学车,先学后付交易"; //商品标题
  627. order.body = @"详细描述"; //商品描述
  628. //dansonmark 上架前一定要改正 商品价格 和通知地址 都是钱啊
  629. //orderDic[@"money"]
  630. order.totalFee = orderDic[@"money"]; //商品价格topUpNotify
  631. order.notifyURL = topUpNotify; //回调URL
  632. order.service = @"mobile.securitypay.pay";
  633. order.paymentType = @"1";
  634. order.inputCharset = @"utf-8";
  635. order.itBPay = @"30m";
  636. order.showURL = @"m.alipay.com";
  637. //应用注册scheme,在AlixPayDemo-Info.plist定义URL types 原来支付宝这个是自己定义的、、
  638. NSString *appScheme = aliPayScheme;
  639. //将商品信息拼接成字符串
  640. NSString *orderSpec = [order description];
  641. //NSLog(@"orderSpec = %@",orderSpec);
  642. //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
  643. id<DataSigner> signer = CreateRSADataSigner(privateKey);
  644. NSString *signedString = [signer signString:orderSpec];
  645. //将签名成功字符串格式化为订单字符串,请严格按照该格式
  646. NSString *orderString = nil;
  647. if (signedString != nil) {
  648. orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
  649. orderSpec, signedString, @"RSA"];
  650. //NSLog(@"---->%@",orderString);
  651. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AliPayResultNoti:) name:ALI_PAY_RESULT object:nil];
  652. [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
  653. //NSLog(@"reslutAP页面 = %@",resultDic);
  654. //是9000代表支付成功
  655. if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
  656. //支付成功
  657. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
  658. }else{
  659. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
  660. }
  661. }];
  662. }
  663. }
  664. //支付宝支付成功失败
  665. -(void)AliPayResultNoti:(NSNotification *)noti
  666. {
  667. //[self getTradeStatusIsOkAsyc];
  668. //NSLog(@"充值----><>%@",noti);
  669. skipView = [[UIView alloc] initWithFrame:kFrame];
  670. skipView.backgroundColor = backGroundColor;
  671. [self.view addSubview:skipView];
  672. if ([[noti object] isEqualToString:ALIPAY_SUCCESSED]) {
  673. //在这里填写支付成功之后你要做的事情
  674. UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paySuccess.png"]];
  675. img.frame = CGRectMake(kSize.width *0.375, 100, kSize.width *0.25, kSize.width *0.25);
  676. [skipView addSubview:img];
  677. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100+kSize.width *0.25, kSize.width, 40)];
  678. [label setText:@"支付成功" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  679. [skipView addSubview:label];
  680. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200+kSize.width *0.25, kSize.width - 40, 50)];
  681. [btn setTitle:@"确定" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal];
  682. btn.backgroundColor=[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1];
  683. [btn target:self tag:-1];
  684. [skipView addSubview:btn];
  685. }else{
  686. //支付失败
  687. UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"payFault.png"]];
  688. img.frame = CGRectMake(kSize.width *0.375, 100, kSize.width *0.25, kSize.width *0.25);
  689. [skipView addSubview:img];
  690. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100+kSize.width *0.25, kSize.width, 40)];
  691. [label setText:@"支付失败,请重新支付" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  692. [skipView addSubview:label];
  693. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200+kSize.width *0.25, kSize.width/2.0 - 35, 50)];
  694. [btn setTitle:@"取消" textColor:[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1] font:Font17 fotState:UIControlStateNormal];
  695. [btn borderColor:[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1] width:1 cornorRadios:5];
  696. [btn target:self tag:-2];
  697. [skipView addSubview:btn];
  698. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 + 15, 200+kSize.width *0.25, kSize.width/2.0 - 35, 50)];
  699. [btn setTitle:@"重新支付" textColor:contentTextColor font:Font17 fotState:UIControlStateNormal];
  700. [btn borderColor:contentTextColor width:1 cornorRadios:5];
  701. [btn target:self tag:-3];
  702. [skipView addSubview:btn];
  703. }
  704. //上边添加了监听,这里记得移除
  705. [[NSNotificationCenter defaultCenter] removeObserver:self name:ALI_PAY_RESULT object:nil];
  706. }
  707. //提现接口
  708. - (void)didReceiveMemoryWarning {
  709. [super didReceiveMemoryWarning];
  710. }
  711. @end