123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- //
- // TopUpMoneyVC.m
- // jiaPei
- //
- // Created by apple on 16/8/23.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "TopUpMoneyVC.h"
- #import "BankCardView.h"
- #import "Order.h"
- #import "DataSigner.h"
- #import <AlipaySDK/AlipaySDK.h>
- #import <WechatOpenSDK/WXApi.h>
- #import <WechatOpenSDK/WXApiObject.h>
- @interface TopUpMoneyVC ()<UITextFieldDelegate>
- {
- UIView *payTypeView;
- UIButton *payTypeBtn;
- UITextField *payMoneyTF;
- UIButton *continueBtn;
- UILabel *balanceLabel;
- UIView *backView;
- UIView *btnBar;
- UIImageView *selectedPayStyleImg;
- UIView *skipView;
-
- NSTimer *timer;
-
- NSArray *bankCardArray;
- NSInteger payType;
- NSDictionary *orderDic;
-
- NSString *rsaOrderString;
- }
- @end
- @implementation TopUpMoneyVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self myInit];
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
-
- if (backView) {
- [backView removeFromSuperview];
- }
-
- if (timer) {
- [timer invalidate];
- timer = nil;
- }
- }
- -(void)myInit
- {
- [self configNavigationBar];
- [self.view setBackgroundColor:backGroundColor];
-
-
- payType = 0;
- bankCardArray = [NSArray array];
-
- CGFloat x,y,w,h;
- x = 0;
- y = 15;
- w = kSize.width;
- h = 60;
-
- payTypeView = [[UIView alloc] setxywh];
- payTypeView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:payTypeView];
-
- UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 30, 20, 10, 20)];
- imgView.image = [UIImage imageNamed:@"more_right_arrow.png"];
- [payTypeView addSubview:imgView];
-
- UILabel *payTypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, w, h)];
- [payTypeLabel setText:@"请选择支付方式" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
- [payTypeView addSubview:payTypeLabel];
-
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = setDIYFrame;
- btn.backgroundColor = [UIColor clearColor];
- [btn target:self tag:1];
- [self.view addSubview:btn];
- payTypeBtn = btn;
- [payTypeBtn addViewWithRect:CGRectMake(x, 0, w, 15)];
-
- y += h;
- if (self.type == 1) {
- [self setTitle:@"我要充值"];
-
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"限额说明" style:UIBarButtonItemStyleDone target:self action:@selector(clickToLimit)];
- [item setTintColor:defGreen];
- [self.navigationItem setRightBarButtonItem:item];
-
- x = 20;
- w -= 40;
- h = 40;
- UILabel *label = [[UILabel alloc] setxywh];
- label.backgroundColor = backGroundColor;
- [label setText:@"该账户本次最多可充值10,000.00元" Font:Font17 TextColor:contentTextColor];
- [self.view addSubview:label];
-
- x = 0;
- y += h;
- w += 40;
- h = 50;
- UIView *payMoneyView = [[UIView alloc] setxywh];
- payMoneyView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:payMoneyView];
-
- x = 20;
- w = 50;
- label = [[UILabel alloc] setxywh];
- [label setText:@"金额" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
-
- x += w;
- w = kSize.width - x - 20;
- payMoneyTF = [[UITextField alloc] setxywh];
- payMoneyTF.placeholder = @"请输入充值金额";
- payMoneyTF.keyboardType = UIKeyboardTypeNumberPad;
- payMoneyTF.delegate = self;
- [self.view addSubview:payMoneyTF];
-
- if (_neededMoney.length > 0) {
- payMoneyTF.text = _neededMoney;
- [continueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [continueBtn setBackgroundColor:[UIColor colorWithRed:55/255.0 green:147/255.0 blue:239/255.0 alpha:1]];
- [continueBtn setUserInteractionEnabled:YES];
- }
-
- x = 20;
- y += h + 30;
- w = kSize.width - 40;
- h = 50;
- continueBtn = [[UIButton alloc] setxywh];
- [continueBtn setTitle:@"下一步" textColor:contentTextColor font:FontTitle fotState:UIControlStateNormal];
- continueBtn.backgroundColor = KlineColor;
- continueBtn.layer.masksToBounds = YES;
- continueBtn.layer.cornerRadius = 4;
- [continueBtn target:self tag:2];
- [continueBtn setUserInteractionEnabled:NO];
- [self.view addSubview:continueBtn];
-
- }else{
- [self setTitle:@"提现"];
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"转出说明" style:UIBarButtonItemStyleDone target:self action:@selector(clickToCash)];
- [item setTintColor:defGreen];
- [self.navigationItem setRightBarButtonItem:item];
-
- [payTypeBtn addViewWithRect:CGRectMake(x, y, w, 20)];
- y += 20;
- h = 140;
- UIView *payMoneyView = [[UIView alloc] setxywh];
- payMoneyView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:payMoneyView];
-
- x = 20;
- w -= 40;
- h = 39;
- UILabel *label = [[UILabel alloc] setxywh];
- [label setText:@"提现金额" Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
-
- y += h;
- w = 30;
- h = 60;
- label = [[UILabel alloc] setxywh];
- [label setText:@"¥" Font:30 TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
-
- x += w;
- w = kSize.width - x - 20;
- payMoneyTF = [[UITextField alloc] setxywh];
- //payMoneyTF.placeholder = @"请输入充值金额";
- payMoneyTF.keyboardType = UIKeyboardTypeNumberPad;
- payMoneyTF.delegate = self;
- [self.view addSubview:payMoneyTF];
- [payMoneyTF addViewWithRect:CGRectMake(20, y + h, kSize.width - 40, 1)];
-
- y += h + 1;
- x = 20;
- w = kSize.width - 100 - x;
- h = 40;
- label = [[UILabel alloc] setxywh];
- [label setText:@"可用余额2.00元" Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
- balanceLabel = label;
-
- x += w;
- w = 80;
- UIButton *btn = [[UIButton alloc] setxywh];
- [btn setTitle:@"全部提现" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
- [btn target:self tag:3];
- [self.view addSubview:btn];
-
- y += h + 15;
- x = 20;
- w = h = 20;
- UIImageView *imageView = [[UIImageView alloc] setxywh];
- imageView.image = [UIImage imageNamed:@"payFault.png"];
- [self.view addSubview:imageView];
- x += w + 5;
- w = kSize.width - x - 20;
- label = [[UILabel alloc] setxywh];
- [label setText:@"两小时内到账,确认提现" Font:Font17 TextColor:[UIColor colorWithRed:252/255.0 green:85/255.0 blue:117/255.0 alpha:1] Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
-
- y += 30 + h;
- x = 20;
- w = kSize.width - 40;
- h = 50;
- continueBtn = [[UIButton alloc] setxywh];
- [continueBtn setTitle:@"确认转出" textColor:contentTextColor font:FontTitle fotState:UIControlStateNormal];
- continueBtn.backgroundColor = KlineColor;
- continueBtn.layer.masksToBounds = YES;
- continueBtn.layer.cornerRadius = 4;
- [continueBtn target:self tag:3];
- [continueBtn setUserInteractionEnabled:NO];
- [self.view addSubview:continueBtn];
- }
- }
- -(void)btnClick:(UIButton *)sender
- {
- [self.view endEditing:YES];
-
- if (sender.tag < 0) {
- [skipView removeFromSuperview];
- if (sender.tag == -1) {
- //支付成功的返回按钮
- [self.navigationController popViewControllerAnimated:YES];
- }
- if (sender.tag == -2) {
- //支付失败查看订单的页面3
- //[self.navigationController popViewControllerAnimated:YES];
- }
- if (sender.tag == -3) {
- //支付失败重新支付
- [self clickToAliPay];
- }
- }
-
- if (sender.tag == 1) {
- //选择支付 或提现账号
- [self getMyBanks];
- }
- if (sender.tag == 2) {
- if (payType == 0) {
- ShowMsg(@"请选择支付方式");
- return;
- }
- //下一步 充值按钮
- [self uploadRechargeInfo];
- }
- if (sender.tag == 3) {
- //下一步 提现按钮
-
- }
-
- if (sender.tag == 6) {
- //使用新卡支付
- ShowMsg(@"暂未开通,敬请期待");
- return;
- }
-
- if (sender.tag > 6) {
- selectedPayStyleImg.y = sender.y + 15;
- selectedPayStyleImg.x = kSize.width - 50;
- [self selectdePayTypeWithTag:sender.tag];
- }
- }
- -(void)selectdePayTypeWithTag:(NSInteger)btnTag
- {
- if (btnTag == 7 || btnTag == 8 || btnTag == 9) {
- //使用支付宝、微信、QQ钱包来支付
- // if (btnTag == 8 || btnTag == 9) {
- // ShowMsg(@"暂未开通,敬请期待");
- // return;
- // }
- payType = btnTag;//设置支付类型
-
- for (UIView *payTypeSubview in payTypeView.subviews) {
- [payTypeSubview removeFromSuperview];
- }
-
- NSArray *imgArray = @[@"AliPay.png",@"WebPay.png",@"WebPay.png"];
- NSArray *titleArray = @[@"支付宝",@"微信",@"QQ钱包"];
-
- UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 40, 40)];
- img.image = [UIImage imageNamed:imgArray[btnTag - 7]];
- [payTypeView addSubview:img];
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, 100, 60)];
- [label setText:titleArray[btnTag - 7] Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
- [payTypeView addSubview:label];
- }
-
- if (btnTag > 9) {
- //使用银行卡来支付
- ShowMsg(@"暂未开通,敬请期待");
-
- payType = btnTag;//设置支付类型
-
- for (UIView *payTypeSubview in payTypeView.subviews) {
- [payTypeSubview removeFromSuperview];
- }
-
- NSDictionary *dic = bankCardArray[btnTag - 10];
- BankCardView *bankV = [[BankCardView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 60)];
- [bankV setDataDic:dic];
- [payTypeView addSubview:bankV];
- }
-
- UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 30, 20, 10, 20)];
- imgView.image = [UIImage imageNamed:@"more_right_arrow.png"];
- [payTypeView addSubview:imgView];
-
- [self removeSearchView];//关闭选择框
- }
- //额度和转出说明
- -(void)clickToLimit
- {
- TopUpMoneyVC *vc = [[TopUpMoneyVC alloc] init];
- vc.type = 2;
- [self navPushHideTabbarToVC:vc];
- }
- -(void)clickToCash
- {
-
- }
- #pragma mark 创建银行卡选择项
- -(void)creatSheetView
- {
- backView = [[UIView alloc] initWithFrame:kFrame];
- backView.backgroundColor = [UIColor colorWithWhite:.7 alpha:.1];
- UITapGestureRecognizer *tapGR=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
- [backView addGestureRecognizer:tapGR];
- [[UIApplication sharedApplication].keyWindow addSubview:backView];
-
-
- btnBar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height, kSize.width, kSize.height - 200 - kNavOffSet)];
- [btnBar setBackgroundColor:[UIColor whiteColor]];
- [backView addSubview:btnBar];
-
- CGFloat x,y,w,h;
- x = y = 0;
- w = kSize.width;
- h = 40;
- UILabel *label = [[UILabel alloc] setxywh];
- [label setText:@"" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
- [btnBar addSubview:label];
- [label addViewWithRect:CGRectMake(0, h, w, 1)];
-
- w = 100;
- UIButton *backBtn = [[UIButton alloc] setxywh];
- [backBtn addTarget:self action:@selector(removeSearchView) forControlEvents:UIControlEventTouchUpInside];
- [backBtn setImage:[[UIImage imageNamed:@"drawer_img08"] tint:[UIColor lightGrayColor]] forState:UIControlStateNormal];
- [backBtn setImageEdgeInsets:UIEdgeInsetsMake(5, 20, 5, 50)];
- [btnBar addSubview:backBtn];
-
- w = kSize.width;
- y += h + 1;
- h = btnBar.height - y;
- UIScrollView *scrollView = [[UIScrollView alloc] setxywh];
- [btnBar addSubview:scrollView];
-
- //选中的标示
- selectedPayStyleImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paySelected.png"]];
- selectedPayStyleImg.frame = CGRectMake(kSize.width, 0, 30, 30);
- [scrollView addSubview:selectedPayStyleImg];
-
- //支付宝 微信 QQ钱包 7、8、9 要的写 不要的不写 然后新卡的话 tag为6 银行卡的tag从10开始
-
- if (self.type == 1) {
- [label setText:@"选择付款方式"];
- }else{
- [label setText:@"选择提现账号"];
- }
-
- x = y = 0;
- h = 60;
-
- NSArray *imgArray = @[@"AliPay.png",@"WebPay.png",@"QQPay.png"];
- NSArray *titleArray = @[@"支付宝",@"微信",@"QQ钱包"];
- for (int i = 0; i < 3; i ++) {
-
- UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10+i*h, 40, 40)];
- img.image = [UIImage imageNamed:imgArray[i]];
- [scrollView addSubview:img];
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70, i*h, 100, 60)];
- [label setText:titleArray[i] Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
- [scrollView addSubview:label];
-
- [label addViewWithRect:CGRectMake(20, (i + 1)*h - 1.5, kSize.width - 40, 1.5)];
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x, i*h, w, h)];
- [btn setBackgroundColor:[UIColor clearColor]];
- [btn target:self tag:i + 7];//7 8 9
- [btn setBackgroundImage:[UIImage imageWithColor:KlineColor] forState:UIControlStateHighlighted];
- [scrollView addSubview:btn];
- }
-
- y += 60*titleArray.count;
- //银行卡
- for (int i = 0; i < bankCardArray.count; i ++) {
-
- NSDictionary *dic = bankCardArray[i];
-
- BankCardView *bankV = [[BankCardView alloc] initWithFrame:CGRectMake(0, y+i*h, kSize.width, h)];
- [bankV setDataDic:dic];
- [scrollView addSubview:bankV];
- [bankV addViewWithRect:CGRectMake(20, y + (i + 1)*h - 1.5, kSize.width - 40, 1.5)];
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y + i*h, w, h)];
- [btn setBackgroundColor:[UIColor clearColor]];
- [btn target:self tag:i + 10];//从10开始
- [btn setBackgroundImage:[UIImage imageWithColor:KlineColor] forState:UIControlStateHighlighted];
- [scrollView addSubview:btn];
- }
-
- y += 60*bankCardArray.count;
- //暂设置提现只能提到充值过得卡中 如果以后提现可以提到任意卡中(除信用卡)那么就把 使用新卡付款 改为 使用新卡提现
- if (self.type == 1) {
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- //[btn setBackgroundColor:[UIColor clearColor]];
- [btn setTitle:@"使用新卡付款" textColor:kTitleColor font:FontTitle fotState:UIControlStateNormal];
- [btn target:self tag:6];//6
- [scrollView addSubview:btn];
- [btn addViewWithRect:CGRectMake(20, y + h - 1.5, kSize.width - 40, 1.5)];
-
- UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 30, y + 20, 10, 20)];
- imgView.image = [UIImage imageNamed:@"more_right_arrow.png"];
- [scrollView addSubview:imgView];
-
- y += h;
- }
-
- [scrollView setContentSize:CGSizeMake(kSize.width, y + 20)];
-
- //做弹出浅入动画
- [UIView animateWithDuration:.4 animations:^{
-
- backView.backgroundColor = [UIColor colorWithWhite:.3 alpha:.5];
- btnBar.y = 200 + kNavOffSet;
- }];
-
- }
- -(void)tapAction:(UITapGestureRecognizer *)gesture
- {
- //做关闭的操作
- [self removeSearchView];
- }
- -(void)removeSearchView
- {
- [UIView animateWithDuration:.4 animations:^{
- backView.backgroundColor = [UIColor colorWithWhite:.7 alpha:.1];
- btnBar.y = kSize.height;
- } completion:^(BOOL finished) {
- [backView removeFromSuperview];
- //[btnBar removeFromSuperview];
- }];
- }
- #pragma mark textField delegate
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
- {
- if (textField.text.length > 0 && [textField.text floatValue] == 0.0 && [string isEqualToString:@"0"]) {
- return NO;
- }
-
- NSString *currentString = [textField.text stringByReplacingCharactersInRange:range withString:string];
- if ([currentString floatValue] > 0.0) {
-
- [continueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [continueBtn setBackgroundColor:[UIColor colorWithRed:55/255.0 green:147/255.0 blue:239/255.0 alpha:1]];
- [continueBtn setUserInteractionEnabled:YES];
- }else{
- [continueBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [continueBtn setBackgroundColor:KlineColor];
- [continueBtn setUserInteractionEnabled:NO];
- }
-
- return YES;
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- [self.view endEditing:YES];
- }
- #pragma mark 数据请求
- //获取我的银行卡列表信息
- -(void)getMyBanks
- {
- //NSLog(@"-----><><><>%d",payTypeBtn.isUserInteractionEnabled);
- [payTypeBtn setUserInteractionEnabled:NO];
- if (![Util connectedToNetWork]) {
- [self creatSheetView];
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
-
- NSString* method = @"getMyBanks";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- [MBProgressHUD hideHUDForView:self.view];
- [payTypeBtn setUserInteractionEnabled:YES];
-
- //NSLog(@"我的银行卡列表-->%@-->%@",arr,root);
- if (!root) {
- ShowMsg(@"未获取到您的银行卡信息,请重试");
- [self creatSheetView];
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- [self creatSheetView];
- return;
- }
-
- bankCardArray = root[@"body"];
-
- [self creatSheetView];
- }];
- }
- //获取我的订单状态 暂未用到
- //-(void)getTradeStatusIsOkAsyc
- //{
- // [MBProgressHUD showLoadToView:self.view];
- // [self performSelectorInBackground:@selector(getTradeStatusIsOk) withObject:nil];
- //}
- //-(void)getTradeStatusIsOk
- //{
- // if (![Util connectedToNetWork]) {
- // [self creatSheetView];
- // showMsgUnconnect();
- // return;
- // }
- //
- // ServiceHelper *helper = [[ServiceHelper alloc] init];
- // NSMutableArray *arr=[NSMutableArray array];
- //
- // [arr addPro:@"serviceName" Value:defaultServiceName];
- // [arr addPro:@"key" Value:[defaultKey md5Encrypt]];
- // [arr addPro:@"id" Value:orderDic[@"tradeId"]];//订单状态
- //
- // NSString* method = @"getTradeStatusIsOk";
- // NSString* soapMsg = [SoapHelper arrayToDefaultSoapMessage:arr methodName:method];
- // NSString *xml=[helper syncServiceMethod:method soapMessage:soapMsg];
- // [MBProgressHUD hideHUDForView:self.view];
- // NSDictionary* root = [xml jsonObject];
- //
- // //NSLog(@"我的订单状态-->%@-->%@",arr,root);
- // if (!root) {
- // ShowMsg(@"交易异常,请查看账户余额");
- // return;
- // }
- // if ([root[@"code"] isEqualToString:@"1"]) {
- // ShowMsg(root[@"body"]);
- // return;
- // }
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //
- //
- //
- // });
- //}
- //充值接口
- -(void)uploadRechargeInfo
- {
- [self clickToWechatPay];
- /*
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString *payTypeString = @"";
- if (payType < 10) {
- payTypeString = [NSString stringWithFormat:@"%d",(int)(payType - 6)];
- }else{
- payTypeString = @"4";
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"money" Value:payMoneyTF.text];
- [arr addPro:@"payType" Value:payTypeString];//1 支付宝 2 微信 3 QQ钱包 4 银行卡
- [arr addPro:@"title" Value:@"优易学车充值"];
- [arr addPro:@"demo" Value:@"余额充值"];
-
- NSString* method = @"sd_imageWithGIFData";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- [MBProgressHUD hideHUDForView:self.view];
- NSLog(@"充值-->%@-->%@",arr,root);
- if (!root) {
- ShowMsg(@"充值失败,请重试");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- return;
- }
-
- //orderDic = root[@"body"];
-
- rsaOrderString = root[@"body"];
-
- rsaOrderString = [rsaOrderString stringByReplacingOccurrencesOfString:@"amp;" withString:@""];
-
- //充值成功 调支付接口
- //充值成功 调支付接口
- if ([payTypeString isEqualToString:@"1"]) {
- [self clickToAliPay];
- }else if ([payTypeString isEqualToString:@"2"]) {
- [self clickToWechatPay];
- }
- }];
- */
- }
- - (void)clickToWechatPay {
- // 发起微信支付,设置参数
- //需要创建这个支付对象
- PayReq *req = [[PayReq alloc] init];
- //由用户微信号和AppID组成的唯一标识,用于校验微信用户
- req.openID = WEIXIN_APPID;
- // 商家id,在注册的时候给的
- req.partnerId = @"1539360921";
- // 预支付订单这个是后台跟微信服务器交互后,微信服务器传给你们服务器的,你们服务器再传给你
- req.prepayId = @"wx04172515935255d860df5b9a0892674222";
- // 根据财付通文档填写的数据和签名
- req.package = @"Sign=WXPay";
- // 随机编码,为了防止重复的,在后台生成
- req.nonceStr = @"aJIXjLdXQLpEHB8R";
- // 这个是时间戳,也是在后台生成的,为了验证支付的
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
- formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
- [formatter setDateStyle:NSDateFormatterMediumStyle];
- [formatter setTimeStyle:NSDateFormatterShortStyle];
- [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
- NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
- [formatter setTimeZone:timeZone];
- NSDate *datenow = [NSDate date];
- NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
- NSString * stamp = timeSp;
- req.timeStamp = (UInt32)stamp.intValue;
- // 这个签名也是后台做的
- req.sign = @"B86B1200B6CC0649519590A65BA7C14C";
- //发送请求到微信,等待微信返回onResp
- [WXApi sendReq:req completion:nil];
- }
- -(void)clickToAliPay
- {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AliPayResultNoti:) name:ALI_PAY_RESULT object:nil];
-
- [[AlipaySDK defaultService] payOrder:rsaOrderString fromScheme:aliPayScheme callback:^(NSDictionary *resultDic) {
- //NSLog(@"reslutAP页面 = %@",resultDic);
-
- //是9000代表支付成功
- if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
- //支付成功
- [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
- }else{
- [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
- }
- }];
- }
- -(void)clickToAliPayOld
- {
- /*
- *商户的唯一的parnter和seller。
- *签约后,支付宝会为每个商户分配一个唯一的 parnter 和 seller。
- */
-
- /*============================================================================*/
- /*=======================需要填写商户app申请的===================================*/
- /*============================================================================*/
-
- //这个要写在一个按钮的方法中
- NSString *partner = aliPartner;
- NSString *seller = aliSeller;
- NSString *privateKey = aliPrivateKey;
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
-
- //partner和seller获取失败,提示
- if ([partner length] == 0 ||
- [seller length] == 0 ||
- [privateKey length] == 0)
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
- message:@"支付发生错误 错误码1000"
- delegate:nil
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- [alert show];
- return;
- }
-
- /*
- *生成订单信息及签名
- */
- //将商品信息赋予AlixPayOrder的成员变量
-
- Order *order = [[Order alloc] init];
- order.partner = partner;
- order.sellerID = seller;
- order.outTradeNO = orderDic[@"orderNo"]; //订单ID(由商家自行制定)
- // order.subject = [NSString stringWithCString:[sub UTF8String] encoding:NSUnicodeStringEncoding]; //商品标题
- // order.body = [bod stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];; //商品描述
- order.subject = @"优易学车,先学后付交易"; //商品标题
- order.body = @"详细描述"; //商品描述
-
- //dansonmark 上架前一定要改正 商品价格 和通知地址 都是钱啊
- //orderDic[@"money"]
- order.totalFee = orderDic[@"money"]; //商品价格topUpNotify
- order.notifyURL = topUpNotify; //回调URL
-
- order.service = @"mobile.securitypay.pay";
- order.paymentType = @"1";
- order.inputCharset = @"utf-8";
- order.itBPay = @"30m";
- order.showURL = @"m.alipay.com";
-
- //应用注册scheme,在AlixPayDemo-Info.plist定义URL types 原来支付宝这个是自己定义的、、
- NSString *appScheme = aliPayScheme;
-
- //将商品信息拼接成字符串
- NSString *orderSpec = [order description];
- //NSLog(@"orderSpec = %@",orderSpec);
-
- //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
- id<DataSigner> signer = CreateRSADataSigner(privateKey);
- NSString *signedString = [signer signString:orderSpec];
-
- //将签名成功字符串格式化为订单字符串,请严格按照该格式
- NSString *orderString = nil;
- if (signedString != nil) {
- orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
- orderSpec, signedString, @"RSA"];
- //NSLog(@"---->%@",orderString);
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AliPayResultNoti:) name:ALI_PAY_RESULT object:nil];
-
- [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
- //NSLog(@"reslutAP页面 = %@",resultDic);
-
- //是9000代表支付成功
- if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
- //支付成功
- [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
- }else{
- [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
- }
- }];
- }
- }
- //支付宝支付成功失败
- -(void)AliPayResultNoti:(NSNotification *)noti
- {
- //[self getTradeStatusIsOkAsyc];
- //NSLog(@"充值----><>%@",noti);
-
- skipView = [[UIView alloc] initWithFrame:kFrame];
- skipView.backgroundColor = backGroundColor;
- [self.view addSubview:skipView];
- if ([[noti object] isEqualToString:ALIPAY_SUCCESSED]) {
- //在这里填写支付成功之后你要做的事情
- UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paySuccess.png"]];
- img.frame = CGRectMake(kSize.width *0.375, 100, kSize.width *0.25, kSize.width *0.25);
- [skipView addSubview:img];
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100+kSize.width *0.25, kSize.width, 40)];
- [label setText:@"支付成功" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
- [skipView addSubview:label];
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200+kSize.width *0.25, kSize.width - 40, 50)];
- [btn setTitle:@"确定" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal];
- btn.backgroundColor=[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1];
- [btn target:self tag:-1];
- [skipView addSubview:btn];
-
- }else{
- //支付失败
-
- UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"payFault.png"]];
- img.frame = CGRectMake(kSize.width *0.375, 100, kSize.width *0.25, kSize.width *0.25);
- [skipView addSubview:img];
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100+kSize.width *0.25, kSize.width, 40)];
- [label setText:@"支付失败,请重新支付" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
- [skipView addSubview:label];
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200+kSize.width *0.25, kSize.width/2.0 - 35, 50)];
- [btn setTitle:@"取消" textColor:[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1] font:Font17 fotState:UIControlStateNormal];
- [btn borderColor:[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1] width:1 cornorRadios:5];
- [btn target:self tag:-2];
- [skipView addSubview:btn];
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 + 15, 200+kSize.width *0.25, kSize.width/2.0 - 35, 50)];
- [btn setTitle:@"重新支付" textColor:contentTextColor font:Font17 fotState:UIControlStateNormal];
- [btn borderColor:contentTextColor width:1 cornorRadios:5];
- [btn target:self tag:-3];
- [skipView addSubview:btn];
- }
- //上边添加了监听,这里记得移除
- [[NSNotificationCenter defaultCenter] removeObserver:self name:ALI_PAY_RESULT object:nil];
- }
- //提现接口
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|