iOS 银联支付

1:导入

#import "UPPayPlugin.h"

#import "UPPayPluginDelegate.h"

#import "DMCAlertCenter.h"


pragma mark-------------------------------------------点击选择会员发起购买请求-----------------------------

//日会元

- (IBAction)putong:(id)sender {

    _RMBstr =10;

    _huiyuanNumber=4;

    UIActionSheet * tryActionSheet = [[UIActionSheet alloc] initWithTitle:@"选择支付方式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"支付宝" otherButtonTitles:@"银联支付", @"微信支付", nil];

    tryActionSheet.tag = 101;

    [tryActionSheet showInView:self.view];

}

//黄金员

- (IBAction)huangjin:(id)sender {

    _RMBstr =100;

    _huiyuanNumber=1;

    UIActionSheet * tryActionSheet = [[UIActionSheet alloc] initWithTitle:@"选择支付方式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"支付宝" otherButtonTitles:@"银联支付", @"微信支付", nil];

    tryActionSheet.tag = 102;

    [tryActionSheet showInView:self.view];

}

//白金会员

- (IBAction)baijin:(id)sender {

    _RMBstr =500;

    _huiyuanNumber=2;

    UIActionSheet * tryActionSheet = [[UIActionSheet alloc] initWithTitle:@"选择支付方式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"支付宝" otherButtonTitles:@"银联支付", @"微信支付", nil];

    tryActionSheet.tag = 103;

    [tryActionSheet showInView:self.view];

}

  //砖石会员

- (IBAction)zhuanshi:(id)sender {

  

    _RMBstr =100;

    _huiyuanNumber=3;

    UIActionSheet * tryActionSheet = [[UIActionSheet alloc] initWithTitle:@"选择支付方式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"支付宝" otherButtonTitles:@"银联支付", @"微信支付", nil];

    tryActionSheet.tag = 104;

    [tryActionSheet showInView:self.view];

}


#pragma mark----------------------------请求参数加载-------------------------------------------

//银联数据加载

- (void)loadData

{

    self.userDefault = [NSUserDefaults standardUserDefaults];

    NSDictionary * dic = @{@"loginId":[_userDefault objectForKey:@"phoneNum"],@"RMB":[NSNumber numberWithInt:_RMBstr ],@"vip":[NSNumber numberWithInt:_huiyuanNumber]};

    [_manager methodPostWithURL:vipMethod parameters:dic];

}

//微信支付加载

-(void)LoadWeiXinData

{

    self.userDefault = [NSUserDefaults standardUserDefaults];

    NSDictionary * dic = @{@"loginId":[_userDefault objectForKey:@"phoneNum"],@"RMB":[NSNumber numberWithInt:_RMBstr ],@"vip":[NSNumber numberWithInt:_huiyuanNumber]};

    [_manager methodPostWithURL:vipMethod parameters:dic];


}


#pragma mark - DataRequestManagerDelegate-----------后台返回结果-----------------------------------------

- (void)passValue:(id)value

{

    NSDictionary * dic = [NSDictionary dictionaryWithDictionary:value];

    NSLog(@"vip dic = %@", dic);

    if ([[dic objectForKey:@"errCode"]isEqualToString:@"0"]&&[[dic objectForKey:@"method"] isEqualToString:@"appPay"]) {//银联

        NSString * tn = [dic objectForKey:@"tn"];

        

        [self payUPWithTN:tn];

    }

  

    

}

#pragma mark--------------------------------------------支付方式的选择----------------------------------------------------------------------

//==================选择支付方式==============================

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

    switch (actionSheet.tag) {

        case 101:

            //一天

        {

            if (buttonIndex == 0) {

                //

                NSLog(@"支付宝");

                

            }else if (buttonIndex == 1) {

                //

                NSLog(@"银联");

                [self loadData];



            }else if(buttonIndex ==2)

            {

              NSLog(@"微信");

            

            }

        }

            break;

            

        case 102:

            //一个月

        {

            if (buttonIndex == 0) {

                //

                NSLog(@"支付宝");

                

            }else if (buttonIndex == 1) {

                //

                NSLog(@"黄金银联");

                [self loadData];



            }

            else if(buttonIndex ==2)

            {

                NSLog(@"微信");

                

                

            }

        }

            

            break;

            

        case 103:

            //三个月

        {

            if (buttonIndex == 0) {

                //

                NSLog(@"支付宝");


            }else if (buttonIndex == 1) {


                NSLog(@"白金银联");

                [self loadData];


            }

            else if(buttonIndex ==2)

            {

                NSLog(@"微信");

                

            }

        }

            

            break;

            

        case 104:

            //一年

        {

            if (buttonIndex == 0) {

                //

                NSLog(@"支付宝");

                

            }else if (buttonIndex == 1) {

                //

                NSLog(@"砖石银联");

                [self loadData];


            }

            else if(buttonIndex ==2)

            {

                NSLog(@"微信");

                

            }

        }

            

            break;

            

        default:

            break;

    }

}


#pragma mark-----------------------------------微信支付判断----------------------------------------------




#pragma mark--------银联支付判断----------------------------------------------------------------

- (void)payUPWithTN:(NSString*)tn

{

    if (tn != nil && tn.length > 0)

    {

        NSLog(@"tn=%@",tn);

        [UPPayPlugin startPay:tn mode:@"01" viewController:self delegate:self];

    }

}

- (void)UPPayPluginResult:(NSString *)result

{

    NSLog(@"result=%@",result);

    if ([result isEqualToString:@"success"]) {

        NSLog(@"支付成功");

        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"支付成功"];

    }else if ([result isEqualToString:@"cancel"]) {

        NSLog(@"取消支付");

        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"取消支付"];

    }else if ([result isEqualToString:@"fail"]) {

        NSLog(@"支付失败");

        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"支付失败"];

    }

    

    [self dismissViewControllerAnimated:YES completion:^{

        

    }];

}



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。