zhifu

//

//FYPayTicketController.m

//飞影APP

//

//Created by xalo on 16/7/22.

//Copyright © 2016年liutuo. All rights reserved.

//

#import"FYPayTicketController.h"

@interfaceFYPayTicketController()

@property(weak,nonatomic)IBOutletUILabel*showTime;

@property(weak,nonatomic)IBOutletUILabel*totelprice;

@property(weak,nonatomic)IBOutletUILabel*updateTime;

@property(weak,nonatomic)IBOutletUIImageView*filmImage;

@property(weak,nonatomic)IBOutletUILabel*oldPrice;

@property(weak,nonatomic)IBOutletUILabel*lowPrice;

@property(weak,nonatomic)IBOutletUILabel*message;

@property(weak,nonatomic)IBOutletUIView*firstBackView;

@property(weak,nonatomic)IBOutletUIView*secondBackView;

@property(weak,nonatomic)IBOutletUIImageView*headerBackView;

@property(weak,nonatomic)IBOutletUILabel*day;

@property(weak,nonatomic)IBOutletUILabel*weekSeat;

@property(weak,nonatomic)IBOutletUILabel*filmName;

@property(weak,nonatomic)IBOutletUILabel*cinemaName;

@property(weak,nonatomic)IBOutletUILabel*homeNum;

@property(weak,nonatomic)IBOutletUILabel*firstSeat;

@property(weak,nonatomic)IBOutletUILabel*secondSeat;

@property(weak,nonatomic)IBOutletUILabel*thirdSeat;

@property(weak,nonatomic)IBOutletUILabel*fouthSeat;

@property(weak,nonatomic)IBOutletUILabel*fiveSeat;

@property(weak,nonatomic)IBOutletUILabel*lastPrice;

@property(nonatomic,assign)NSIntegerseconds;

@property(nonatomic,strong)NSTimer*timer;

@property(nonatomic,strong)NSString*dingdanID;

@end

@implementationFYPayTicketController

- (NSTimer*)timer {

if(!_timer) {

_timer= [NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(timerAction)userInfo:nilrepeats:YES];

}

return_timer;

}

- (void)viewDidLoad {

[superviewDidLoad];

//设置子控件属性

[selfsetChildView];

self.seconds=1200;

self.navigationItem.leftBarButtonItem= [[FYBarButtonItemalloc]initWithTitle:@"返回选座"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(popAction)];

NSTimer*timer = [NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(timerAction)userInfo:nilrepeats:YES];

[timerfire];

self.navigationItem.leftBarButtonItem= [[FYBarButtonItemalloc]initWithTitle:@"返回"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(backVC)];

self.dingdanID= [NSStringstringWithFormat:@"FYDY%d%d%d",arc4random_uniform(10000),arc4random_uniform(10000),arc4random_uniform(10000)];

self.message.text=self.dingdanID;

}

- (void)backVC {

[selfdismissViewControllerAnimated:YEScompletion:nil];

}

//支付方法

- (IBAction)confirmPay:(id)sender {

NSString*partner = [[NSBundlemainBundle]objectForInfoDictionaryKey:@"Partner"];

NSString*seller = [[NSBundlemainBundle]objectForInfoDictionaryKey:@"Seller"];

NSString*privateKey = [[NSBundlemainBundle]objectForInfoDictionaryKey:@"RSA private

key"];

/*============================================================================*/

/*============================================================================*/

/*============================================================================*/

//partner和seller获取失败,提示

if([partnerlength] ==0||

[sellerlength] ==0||

[privateKeylength] ==0){

//NSLog(@"缺少partner或者seller或者私钥。");

return;

}

/*

*生成订单信息及签名

*/

//将商品信息赋予AlixPayOrder的成员变量

Order*order = [[Orderalloc]init];

order.partner= partner;

order.seller= seller;

order.tradeNO=self.dingdanID;//订单ID(由商家自行制定)

//商品标题

order.productName=@"票价";

//商品描述

order.productDescription=@"飞影影票";

//商品价格

order.amount= [NSStringstringWithFormat:@"%.2f",0.01];

//NSLog(@"[email protected]");

#pragma mark疑问1.

order.notifyURL=@"www.lanou3g.com";//回调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 =@"AliPayTest";

//将商品信息拼接成字符串

NSString*orderSpec = [orderdescription];

//NSLog(@"orderSpec =%@",orderSpec);

//获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode

id signer =CreateRSADataSigner(privateKey);

NSString*signedString =

[signersignString:orderSpec];

//将签名成功字符串格式化为订单字符串,请严格按照该格式

NSString*orderString =nil;

if(signedString !=nil) {

orderString = [NSStringstringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",

orderSpec, signedString,@"RSA"];

[[AlipaySDKdefaultService]payOrder:orderStringfromScheme:appSchemecallback:^(NSDictionary*resultDic) {

//NSLog(@"reslut =%@",resultDic);

}];

}

}

//返回上一级

- (void)popAction {

[self.timerinvalidate];

self.timer=nil;

[selfdismissViewControllerAnimated:YEScompletion:nil];

}

- (void)viewWillAppear:(BOOL)animated {

[superviewWillAppear:animated];

[self.navigationController.navigationBarsetBackgroundImage:[UIImagenew]forBarMetrics:UIBarMetricsDefault];

self.navigationController.navigationBar.shadowImage= [UIImagenew];

}

//定时器方法

- (void)timerAction {

self.seconds--;

if(self.seconds==0) {

UIAlertAction*alertAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction*_Nonnullaction) {

[self.timerinvalidate];

self.timer=nil;

[selfdismissViewControllerAnimated:YEScompletion:nil];

}];

UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"订单超时"preferredStyle:UIAlertControllerStyleAlert];

[alertControlleraddAction:alertAction];

[selfpresentViewController:alertControlleranimated:YEScompletion:nil];

}

if(self.seconds>=0) {

self.updateTime.text= [selfupdateWithSeconds:self.seconds];

}

}

//设置剩余时间格式

- (NSString*)updateWithSeconds:(NSInteger)seconds {

if(seconds /60<10&& seconds %60>9) {

return[NSStringstringWithFormat:@"0%ld:%ld", seconds /60, seconds %60];

}elseif(seconds /60<10&& seconds %60<9) {

return[NSStringstringWithFormat:@"0%ld:0%ld", seconds /60, seconds %60];

}elseif(seconds /60>9&& seconds %60<9) {

return[NSStringstringWithFormat:@"%ld:0%ld", seconds /60, seconds %60];

}

return[NSStringstringWithFormat:@"%ld:%ld", seconds /60, seconds %60];

}

//设置子空间属性

- (void)setChildView{

[selfsetShadowWith:self.headerBackView];

[selfsetShadowWith:self.firstBackView];

[selfsetShadowWith:self.secondBackView];

[selfsetShadowWith:self.filmImage];

NSString*appendStr = [NSStringstringWithFormat:@"%@(%@)",self.seatModel.filmName,self.seatModel.dimensional];

self.filmName.text= appendStr;

self.homeNum.text=self.seatModel.hallName;

[self.filmImagesd_setImageWithURL:[NSURLURLWithString:self.filmBigImage]];

self.oldPrice.text=self.totolPrice;

self.totelprice.text=self.totolPrice;

self.lastPrice.text=self.totolPrice;

self.cinemaName.text=self.cinemaNameAddress;

self.showTime.text= [NSStringstringWithFormat:@"%ld:%ld",self.seatModel.showTime.integerValue/100,self.seatModel.showTime.integerValue%100];

self.day.text= [self.seatModel.showDatesubstringFromIndex:5];

switch(self.seatArray.count) {

case1:

self.firstSeat.text=self.seatArray[0];

break;

case2:

self.firstSeat.text=self.seatArray[0];

self.secondSeat.text=self.seatArray[1];

break;

case3:

self.firstSeat.text=self.seatArray[0];

self.secondSeat.text=self.seatArray[1];

self.thirdSeat.text=self.seatArray[2];

break;

case4:

self.firstSeat.text=self.seatArray[0];

self.secondSeat.text=self.seatArray[1];

self.thirdSeat.text=self.seatArray[2];

self.fouthSeat.text=self.seatArray[3];

break;

case5:

self.firstSeat.text=self.seatArray[0];

self.secondSeat.text=self.seatArray[1];

self.thirdSeat.text=self.seatArray[2];

self.fouthSeat.text=self.seatArray[3];

self.fiveSeat.text=self.seatArray[4];

break;

default:

break;

}

}

//设置阴影

- (void)setShadowWith:(UIView*)view {

view.layer.shadowOffset=CGSizeMake(5,5);

view.layer.shadowColor= [[UIColorgrayColor]CGColor];

view.layer.shadowOpacity=0.9;

view.layer.shadowRadius=4;

}

- (void)didReceiveMemoryWarning{

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be

recreated.

}

/*

#pragma mark -Navigation

// In astoryboard-based application, you will often want to do a little preparationbefore navigation

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [seguedestinationViewController].

// Pass the selected object to the new viewcontroller.

}

*/

@end

你可能感兴趣的:(zhifu)