123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722 |
- //
- // APViewController.m
- // AliSDKDemo
- //
- // Created by 方彬 on 11/29/13.
- // Copyright (c) 2013 Alipay.com. All rights reserved.
- //
- #import "APViewController.h"
- #import "EvaluationAndPayVC.h"
- #import "InputPasswordVC.h"
- #import "Order.h"
- #import "DataSigner.h"
- #import <AlipaySDK/AlipaySDK.h>
- #import "WXApi.h"
- //----
- #import "payRequsestHandler.h"
- @implementation Product
- @end
- @interface APViewController ()<UIAlertViewDelegate>
- {
- UIView *skipView;
- UIImageView *aliImg;
- UIImageView *webImg;
- UIImageView *balanceImg;
- UIScrollView *mainScrollView;
- UILabel *balanceLabel;
-
-
- NSInteger whichPay;
- CGFloat useMoney;
- }
- @end
- @implementation APViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- [self myInit];
-
- [self getMyAccount];
- }
- #pragma mark -
- -(void)myInit
- {
- self.view.backgroundColor = backGroundColor;
- self.title = @"支付";
- [self configNavigationBar];
-
- whichPay = 0;
- NSString *timeLength = _orderDic[@"MINUTE"];
- int hour = [timeLength intValue]/60;
- int min = [timeLength intValue]%60;
- timeLength = [NSString stringWithFormat:@"%d时%d分",hour,min];
-
- NSString *moneyString = _orderDic[@"RO_MONEY"];
- if (moneyString.length < 1) {
- moneyString = @"0";
- }
-
-
- mainScrollView = [[UIScrollView alloc] initWithFrame:kFrame];
- mainScrollView.height -= kNavOffSet;
- mainScrollView.backgroundColor = backGroundColor;
- [self.view addSubview:mainScrollView];
-
-
- NSArray *titleString = @[@"开始时间",@"结束时间",@"练车时长",@"教练姓名",@"练车单价",@"应付金额"];
- NSArray *contentString = @[_orderDic[@"RO_START_TIME"],_orderDic[@"RO_END_TIME"],timeLength,_orderDic[@"RO_COACH_NAME"],[NSString stringWithFormat:@"%@元/小时",_orderDic[@"PRICE"]],[NSString stringWithFormat:@"%@元",moneyString]];
-
- CGFloat x,y,w,h;
- x = 20;
- y = 10;
- w = 100;
- h = 41;
- UIView *labelBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h*6)];
- labelBar.backgroundColor = [UIColor whiteColor];
- [mainScrollView addSubview:labelBar];
-
- y = 0;
- for (int i = 0; i < 6; i ++) {
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + i*h, w, h)];
- [label setText:titleString[i] Font:Font17 TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
- [labelBar addSubview:label];
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(x + w, y + i*h, kSize.width - x - w - 20, h)];
- [label setText:contentString[i] Font:Font17 TextColor:kTitleColor Alignment:NSTextAlignmentRight];
- [labelBar addSubview:label];
-
-
- if (i != 5) {
- //i == 5的时候 不用画线了
- [label addViewWithRect:CGRectMake(10, y + 40*(i+1) - 1, kSize.width - 20, 1)];
- }
- }
-
-
- //支付
- y += 6*h + 40;
- UIView *btnBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 60)];
- btnBar.backgroundColor = [UIColor whiteColor];
- [mainScrollView addSubview:btnBar];
-
- //scroll的长度
- [mainScrollView setContentSize:CGSizeMake(kSize.width, btnBar.y + btnBar.height)];
-
- //余额支付
- y = 5;
- w = h = 50;
-
- UIImageView *balancePayImage = [[UIImageView alloc] setxywh];
- balancePayImage.image = [UIImage imageNamed:@"BalancePay.png"];
- [btnBar addSubview:balancePayImage];
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + 60, y, kSize.width - x - 80, h)];
- [label setText:@"余额" Font:Font17 TextColor:contentTextColor];
- [btnBar addSubview:label];
- balanceLabel = label;
-
-
- //支付按钮
- UIButton *payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- payBtn.frame = CGRectMake(0, kSize.height - 60 - kNavOffSet, kSize.width, 60);
- payBtn.backgroundColor = defGreen;
- [payBtn setTitle:@"支付" textColor:[UIColor whiteColor] font:FontLarger fotState:UIControlStateNormal];
- [payBtn target:self tag:7];
- [self.view addSubview:payBtn];
-
-
- /*
-
- //支付方式
- y += 6*h + 20;
-
- UIView *btnBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 300)];
- btnBar.backgroundColor = [UIColor whiteColor];
- [mainScrollView addSubview:btnBar];
-
- y = 5;
- h = 36;
- w = kSize.width - 60;
-
- UILabel *label = [[UILabel alloc] setxywh];
- [label setText:@"请选择支付方式" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
- [btnBar addSubview:label];
- [label addViewWithRect:CGRectMake(10, y + h - 1, kSize.width - 20, 1)];
-
- //余额支付
- y += h + 5;
- w = h = 50;
-
- UIImageView *balancePayImage = [[UIImageView alloc] setxywh];
- balancePayImage.image = [UIImage imageNamed:@"BalancePay.png"];
- [btnBar addSubview:balancePayImage];
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(x + 60, y, 200, h)];
- [label setText:@"余额" Font:Font17 TextColor:contentTextColor];
- [btnBar addSubview:label];
- balanceLabel = label;
-
- balanceImg = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 50, y + 10, 30, 30)];
- balanceImg.image = [UIImage imageNamed:@"paySelect.png"];
- [btnBar addSubview:balanceImg];
-
- UIButton *payBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, y - 5, kSize.width, 60)];
- [payBtn setBackgroundColor:[UIColor clearColor]];
- [payBtn target:self tag:6];
- [btnBar addSubview:payBtn];
-
-
- //支付宝
- y += 61;
- [label addViewWithRect:CGRectMake(10, y - 6, kSize.width - 20, 1)];
-
- UIImageView *aliImage = [[UIImageView alloc] setxywh];
- aliImage.image = [UIImage imageNamed:@"AliPay.png"];
- [btnBar addSubview:aliImage];
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(x + 60, y, 100, h)];
- [label setText:@"支付宝" Font:Font17 TextColor:contentTextColor];
- [btnBar addSubview:label];
-
- aliImg = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 50, y + 10, 30, 30)];
- aliImg.image = [UIImage imageNamed:@"paySelect.png"];
- [btnBar addSubview:aliImg];
-
- payBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, y - 5, kSize.width, 60)];
- [payBtn setBackgroundColor:[UIColor clearColor]];
- [payBtn target:self tag:4];
- [btnBar addSubview:payBtn];
-
-
- //微信
- y += 61;
- [label addViewWithRect:CGRectMake(10, y - 6, kSize.width - 20, 1)];
-
- UIImageView *webImage = [[UIImageView alloc] setxywh];
- webImage.image = [UIImage imageNamed:@"WebPay.png"];
- [btnBar addSubview:webImage];
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(x + 60, y, 100, h)];
- [label setText:@"微信" Font:Font17 TextColor:contentTextColor];
- [btnBar addSubview:label];
-
- webImg = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 50, y + 10, 30, 30)];
- webImg.image = [UIImage imageNamed:@"paySelect.png"];
- [btnBar addSubview:webImg];
-
- payBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, y - 5, kSize.width, 60)];
- [payBtn setBackgroundColor:[UIColor clearColor]];
- [payBtn target:self tag:5];
- [btnBar addSubview:payBtn];
-
- y += 55;
- [label addViewWithRect:CGRectMake(0, y, kSize.width, 17) Color:backGroundColor];
-
-
-
- y += 17;
- //支付按钮
- payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- payBtn.frame = CGRectMake(0, y, kSize.width, 60);
- payBtn.backgroundColor = defGreen;
- [payBtn setTitle:@"支付" textColor:[UIColor whiteColor] font:FontLarger fotState:UIControlStateNormal];
- [payBtn target:self tag:7];
- [btnBar addSubview:payBtn];
-
- */
-
- //搞不懂 这15的距离哪里来的
- // [mainScrollView setContentSize:CGSizeMake(kSize.width, btnBar.y + btnBar.height + 15)];
- }
- -(void)clickToWebPay
- {
- // NSString *res = [self jumpToBizPay];
- // //如果返回有文字 支付失败
- // if( ![@"" isEqual:res] ){
- // ShowMsg(res);
- // }
-
- //这里调用我自己写的catagoary中的方法,方法里集成了微信支付的步骤,并会发送一个通知,用来传递是否支付成功的信息
- //这里填写的两个参数是后台会返回给你的
- [self payTheMoneyUseWeChatPayWithPrepay_id:@"这里填写后台返回的Prepay_id" nonce_str:@"这里填写后台给你返回的nonce_str"];
- //所以这里添加一个监听,用来接收是否成功的消息
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weChatPayResultNoti:) name:WX_PAY_RESULT object:nil];
- }
- //微信支付付款成功失败
- -(void)weChatPayResultNoti:(NSNotification *)noti{
- if ([[noti object] isEqualToString:IS_SUCCESSED]) {
- //NSLog(@"支付成功");
- //在这里填写支付成功之后你要做的事情
-
- }else{
- //NSLog(@"支付失败");
- }
- //上边添加了监听,这里记得移除
- [[NSNotificationCenter defaultCenter] removeObserver:self name:WX_PAY_RESULT object:nil];
- }
- - (void)payTheMoneyUseWeChatPayWithPrepay_id:(NSString *)prepay_id nonce_str:(NSString *)nonce_str
- {
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
- // 设置时间格式
- formatter.dateFormat = @"yyyyMMddHHmmss";
- NSString *str = [formatter stringFromDate:[NSDate date]];
- //NSLog(@"%@",str);
- //调起微信支付···
- PayReq* req = [[PayReq alloc] init];
- req.partnerId = MCH_ID;
- req.prepayId = [NSString stringWithFormat:@"%@",prepay_id];
- req.nonceStr = [NSString stringWithFormat:@"%@",nonce_str];
- req.timeStamp = [str intValue];
- req.package = @"Sign=WXpay";
- //创建支付签名对象
- payRequsestHandler *req1 =[[payRequsestHandler alloc] init];
- //初始化支付签名对象
- [req1 init:APP_ID mch_id:MCH_ID];
- //设置密钥
- [req1 setKey:PARTNER_ID];
- //第二次签名参数列表
- NSMutableDictionary *signParams = [NSMutableDictionary dictionary];
- [signParams setObject: APP_ID forKey:@"appid"];
- [signParams setObject: [NSString stringWithFormat:@"%@",nonce_str] forKey:@"noncestr"];
- [signParams setObject: @"Sign=WXpay" forKey:@"package"];
- [signParams setObject: MCH_ID forKey:@"partnerid"];
- [signParams setObject: [NSString stringWithFormat:@"%d",str.intValue] forKey:@"timestamp"];
- [signParams setObject: [NSString stringWithFormat:@"%@",prepay_id] forKey:@"prepayid"];
- //生成签名
- NSString *signStr = [req1 createMd5Sign:signParams];
- //NSLog(@"%@",signStr);
- req.sign =signStr;
- //NSLog(@"%@",req);
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noti:) name:@"weixin_pay_result" object:nil];
- [WXApi sendReq:req completion:nil];
- }
- //微信付款成功失败
- -(void)noti:(NSNotification *)noti{
- //NSLog(@"%@",noti);
- if ([[noti object] isEqualToString:@"成功"]) {
- [[NSNotificationCenter defaultCenter] postNotificationName:WX_PAY_RESULT object:IS_SUCCESSED];
-
- }else{
- [[NSNotificationCenter defaultCenter] postNotificationName:WX_PAY_RESULT object:IS_FAILED];
- }
-
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"weixin_pay_result" object:nil];
- }
- - (NSString *)jumpToBizPay {
-
- //判断用户是否安装微信 是否支持微信支付
- if (![WXApi isWXAppInstalled]) {
- return @"您还未安装微信,无法发起微信支付";
- }
- if (![WXApi isWXAppSupportApi]){
- return @"您的微信暂不支持支付";
- }
-
-
-
- //============================================================
- // V3&V4支付流程实现
- // 注意:参数配置请查看服务器端Demo
- // 更新时间:2015年11月20日
- //============================================================
- //http://218.6.66.181:9999/jxglpt/admin/weixinPay/appNotify
- NSString *urlString = @"http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php?plat=ios";
- //解析服务端返回json数据
- NSError *error;
- //加载一个NSURL对象
- NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
- //将请求的url数据放到NSData对象中
- NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
- if ( response != nil) {
- NSMutableDictionary *dict = NULL;
- //IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中
- dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
-
- //NSLog(@"url:%@",urlString);
- if(dict != nil){
- NSMutableString *retcode = [dict objectForKey:@"retcode"];
- if (retcode.intValue == 0){
- NSMutableString *stamp = [dict objectForKey:@"timestamp"];
-
- //调起微信支付
- PayReq* req = [[PayReq alloc] init];
- req.partnerId = [dict objectForKey:@"partnerid"];
- req.prepayId = [dict objectForKey:@"prepayid"];
- req.nonceStr = [dict objectForKey:@"noncestr"];
- req.timeStamp = stamp.intValue;
- req.package = [dict objectForKey:@"package"];
- req.sign = [dict objectForKey:@"sign"];
- [WXApi sendReq:req completion:nil];
- //日志输出
- //NSLog(@"appid=%@\npartid=%@\nprepayid=%@\nnoncestr=%@\ntimestamp=%ld\npackage=%@\nsign=%@",[dict objectForKey:@"appid"],req.partnerId,req.prepayId,req.nonceStr,(long)req.timeStamp,req.package,req.sign );
- return @"";
- }else{
- return [dict objectForKey:@"retmsg"];
- }
- }else{
- return @"服务器返回错误,未获取到json对象";
- }
- }else{
- return @"服务器返回错误";
- }
- }
- -(void)clickToAliPay
- {
- /*
- *商户的唯一的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[@"RO_ORDER_NO"]; //订单ID(由商家自行制定)
- // order.subject = [NSString stringWithCString:[sub UTF8String] encoding:NSUnicodeStringEncoding]; //商品标题
- // order.body = [bod stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];; //商品描述
- order.subject = @"优易学车,先学后付交易"; //商品标题
- order.body = @"详细描述"; //商品描述
- //dansonmark 上架前一定要改正 商品价格 和通知地址 都是钱啊
- //_orderDic[@"RO_MONEY"]
- order.totalFee = _orderDic[@"RO_MONEY"]; //商品价格
- order.notifyURL = aliPayNotify; //回调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
- {
- //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)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == alertView.cancelButtonIndex) {
- [self.navigationController popViewControllerAnimated:YES];
- }else{
-
- EvaluationAndPayVC *vc = [[EvaluationAndPayVC alloc] init];
- vc.isFinishEva = NO;
- //vc.isFromPayVC = YES;
- vc.dataDic = _orderDic;
- [self navPushHideTabbarToVC:vc];
- }
- }
- -(void)btnClick:(UIButton *)sender
- {
- if (sender.tag < 4) {
- [skipView removeFromSuperview];
- }
-
- if (sender.tag == 1) {
- //支付成功的返回按钮1
- UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"支付成功,是否评价?" delegate:self cancelButtonTitle:@"暂不评价" otherButtonTitles:@"确认", nil];
- [alertView show];
- }
-
- if (sender.tag == 2) {
- //支付失败查看订单的页面3
- [self.navigationController popViewControllerAnimated:YES];
- }
-
- if (sender.tag == 3) {
- //支付失败重新支付
- switch (whichPay) {
- case 4:
- [self clickToAliPay];
- break;
- case 5:
- [self clickToWebPay];
- break;
-
- default:
- //这里返回到订单页面 并且提示
- break;
- }
- }
-
- if (sender.tag == 4) {
- //支付宝
- whichPay = 4;
- aliImg.image = [UIImage imageNamed:@"paySelected.png"];
- webImg.image = [UIImage imageNamed:@"paySelect.png"];
- balanceImg.image = [UIImage imageNamed:@"paySelect.png"];
- }
- if (sender.tag == 5) {
- //微信
- whichPay = 5;
- aliImg.image = [UIImage imageNamed:@"paySelect.png"];
- webImg.image = [UIImage imageNamed:@"paySelected.png"];
- balanceImg.image = [UIImage imageNamed:@"paySelect.png"];
- }
- if (sender.tag == 6) {
- //余额
- whichPay = 6;
- aliImg.image = [UIImage imageNamed:@"paySelect.png"];
- webImg.image = [UIImage imageNamed:@"paySelect.png"];
- balanceImg.image = [UIImage imageNamed:@"paySelected.png"];
- }
- if (sender.tag == 7){
-
- if ([_orderDic[@"RO_MONEY"] floatValue] > useMoney) {
- ShowMsg(@"余额不足,请充值");
- }else{
-
- InputPasswordVC *inputVC = [[InputPasswordVC alloc] init];
- [inputVC finishInput:^(NSString *yesorno) {
- if ([yesorno isEqualToString:@"TRUE"]) {
- [self saveAccountRecharge];
- }
- }];
- [self navPushHideTabbarToVC:inputVC];
- }
-
-
- // switch (whichPay){
- // case 4:
- // [self clickToAliPay];
- // break;
- // case 5:
- // ShowMsg(@"暂不支持微信支付,敬请期待");
- // //[self clickToWebPay];
- // break;
- // case 6://余额支付
- // {
- // if ([_orderDic[@"RO_MONEY"] floatValue] > useMoney) {
- // ShowMsg(@"余额不足,请充值或使用其他方式付款");
- // }else{
- // [self saveAccountRechargeAsync];
- // }
- // }
- // break;
- //
- // default:
- // ShowMsg(@"请选择支付方式!");
- // break;
- // }
- }
- }
- #pragma mark 数据请求
- //获取我的账户
- -(void)getMyAccount
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
-
- NSString* method = @"getMyAccount";
-
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- [MBProgressHUD hideHUDForView:self.view];
- if (!root) {
- ShowMsgFailed();
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- return;
- }
- /**
- LOCKMONEY = 20,
- OVERMONEY = 22,
- */
-
- if (![root[@"body"] isKindOfClass:[NSDictionary class]])
- {
- return;
- }
-
- CGFloat allF = [[root[@"body"] objectForKey:@"moneyIn"] floatValue];
- CGFloat consumeF = [[root[@"body"] objectForKey:@"moneyOut"] floatValue];
- useMoney = allF - consumeF;//可用余额
-
- balanceLabel.text = [NSString stringWithFormat:@"我的账户(账户金额%.2f元)",useMoney];
- }];
- }
- //余额支付
- -(void)saveAccountRecharge
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"orderNo" Value:_orderDic[@"RO_ORDER_NO"]];//订单编号
- [arr addPro:@"user" Value:defUser.sfzmhm];
- [arr addPro:@"money" Value:_orderDic[@"RO_MONEY"]];
-
- NSString* method = @"saveAccountRecharge";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- [MBProgressHUD hideHUDForView:self.view];
- if (!root) {
- ShowMsg(@"交易异常,请查看账户余额");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- return;
- }
-
- ShowMsg(root[@"body"]);
- [self.navigationController popViewControllerAnimated:YES];
- }];
- }
- @end;
|