微信和支付宝

2015-09-26  本文已影响168人  iOS小菜鸟

- (void)aLiPay:(id)result{

// 调起支付宝支付

NSString *partner = @"2088811678361814";

NSString *seller = @"lehuo@kubang.com";

Order *order = [[Order alloc] init];

order.partner = partner;

order.seller = seller;

order.tradeNO = [result objectForKey:@"orderid"]; //订单ID(由商家自行制定)

order.productName = [result objectForKey:@"subject"]; //商品标题

order.productDescription = [result objectForKey:@"body"]; //商品描述

order.amount = [result objectForKey:@"price"]; //商品价格

order.notifyURL =  @"http://user.kubang.com/order/paynotify"; //回调URL

order.service = @"mobile.securitypay.pay";

order.paymentType = @"1";

order.inputCharset = @"utf-8";

order.itBPay = @"30m";

NSString *appScheme = @"alisdkdemo";

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

NSString *orderSpec = [order description];

NSString * signedString = (__bridge_transfer  NSString*) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)[result objectForKey:@"sign"], NULL, (__bridge CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 );

NSString *orderString = nil;

if (signedString != nil) {

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

orderSpec, signedString, @"RSA"];

[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {

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

//            [self.navigationController popViewControllerAnimated:NO];

MyDingDanViewController*vc=[[MyDingDanViewController alloc]init];

[self.navigationController pushViewController:vc animated:YES];

}];

}

}

-(void)wxPay:(id)result{

//调起微信支付

PayReq* req = [[PayReq alloc] init];

req.openID      = [result objectForKey:@"appid"];

req.partnerId   = [result objectForKey:@"partnerid"];

req.prepayId    = [result objectForKey:@"prepayid"];

req.nonceStr    = [result objectForKey:@"noncestr"];

req.timeStamp   = [[result objectForKey:@"timestamp"] unsignedIntValue];

req.package     = [result objectForKey:@"package"];

req.sign        = [result objectForKey:@"sign"];

[WXApi sendReq:req];

// [self.navigationController popViewControllerAnimated:NO];

MyDingDanViewController*vc=[[MyDingDanViewController alloc]init];

[self.navigationController pushViewController:vc animated:YES];

}

-(void)zhiFuBtnClick{

NSString*url;

NSString*paytype;

// 获取当前时间

NSDate *  senddate=[NSDate date];

NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];

[dateformatter setDateFormat:@"YYYY-MM-dd HH:mm"];

NSString *  locationString=[dateformatter stringFromDate:senddate];

NSDictionary*dic=@{@"orderstate":@"1",@"rentstate":@"8",@"state":@"8",@"patternid":self.patternid,@"content":@"预定公寓送搬家",@"price":self.YiyuanPrice,@"starttime":locationString,@"type":@"update",@"rentid":self.rentid,@"houseid":self.houseid,@"orderid":@"0"};

if([self.sureButton.titleLabel.text isEqualToString:@"马上预订"]){

[AFHTTPHeadManager POST:@"http://info.kubang.com/apartment/order/?haspaid=1" parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {

[self alert:@"提示" msg:@"订单预订成功"];

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

return;

}else  if(_selectCellRow==0){

paytype=@"1";

url = @"http://user.kubang.com/order/addorder/?ordertype=1";

}else if(_selectCellRow==1){

url = @"http://user.kubang.com/order/addorder/?paytype=2&ordertype=1";

paytype=@"2";

}

NSDictionary*dicc=@{@"price":self.YiyuanPrice};

NSString*uurl=@"http://user.kubang.com/order/addorder/?ordertype=1";

[AFHTTPHeadManager POST:url parameters:dicc success:^(AFHTTPRequestOperation *operation, id responseObject) {

self.sign=[responseObject objectForKey:@"sign"];

paymentid=[responseObject objectForKey:@"orderid"];

NSDictionary*dico;

if(self.orderid==0){

dico=@{@"orderstate":@"1",@"rentstate":@"8",@"state":@"8",@"patternid":self.patternid,@"paymentid":paymentid,@"content":@"预定公寓送搬家",@"price":self.YiyuanPrice,@"starttime":locationString,@"type":@"update",@"rentid":self.rentid,@"houseid":self.houseid,@"orderid":@"0",@"paytype":paytype};

}else{

dico=@{@"orderstate":@"1",@"rentstate":@"8",@"state":@"8",@"patternid":self.patternid,@"paymentid":paymentid,@"content":@"预定公寓送搬家",@"price":self.YiyuanPrice,@"starttime":locationString,@"type":@"update",@"rentid":self.rentid,@"houseid":self.houseid,@"paytype":paytype,@"orderid":self.orderid};

}

//保存表单数据

[AFHTTPHeadManager POST:@"http://info.kubang.com/apartment/order/?haspaid=0" parameters:dico success:^(AFHTTPRequestOperation *operation, id responseObject1) {

if([self.sureButton.titleLabel.text isEqualToString:@"马上预订"]){

UIAlertView*al=[[UIAlertView alloc]initWithTitle:@"提示" message:@"订单预订成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];

[al show];

return ;

}

if([responseObject1[0] isEqualToString:@"ok"]){

//NSString*str=[responseObject objectForKey:@""];

NSDictionary*dict=@{@"sign":self.sign};

if([url isEqualToString:uurl]){

if ([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi] ) {

[self wxPay:responseObject];

}

else{

[self alert:@"提示" msg:@"请安装微信客户端。"];

}

}

else if(![url isEqualToString:uurl]){

[self aLiPay:responseObject];

}

}

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

NSLog(@"请求失败");

}];

}/**结束

*/

上一篇下一篇

猜你喜欢

热点阅读