网银支付

   导入第三方库:

  UPPayPlugin文件

  导入framework:

 


.h 文件

//  Created by cjw on 16-05-12.

//  Copyright (c) 2016 cjw. All rights reserved.

//


#import <UIKit/UIKit.h>

#import "UPPayPluginDelegate.h"



@interface ViewController : UIViewController<UPPayPluginDelegate, UIAlertViewDelegate,UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>



@property(nonatomic, retain)UITableView *tableView;


@end


.m 文件


//  Created by cjw on 16-05-12.

//  Copyright (c) 2016 cjw. All rights reserved.

//

#include <sys/socket.h> // Per msqr

#include <sys/sysctl.h>

#include <net/if.h>

#include <net/if_dl.h>

#import "ViewController.h"

#import "UPPayPlugin.h"


#define KBtn_width        200

#define KBtn_height       80

#define KXOffSet          (self.view.frame.size.width - KBtn_width) / 2

#define KYOffSet          80

#define kCellHeight_Normal  50

#define kCellHeight_Manual  145


#define kBtnFirstTitle    @"获取订单,开始测试"

#define kWaiting          @"正在获取TN,请稍后..."

#define kNote             @"提示"         

#define kConfirm          @"确定"

#define kErrorNet         @"网络错误"

#define kResult           @"支付结果:%@"



#define kMode_Development             @"01"

#define kURL_TN_Normal                @"http://202.101.25.178:8080/sim/gettn"

#define kURL_TN_Configure             @"http://202.101.25.178:8080/sim/app.jsp?user=123456789"


#define UPRelease(X) if (X !=nil) {[X release];X = nil;}


@interface ViewController ()

{

    UIAlertView* _alertView;

    NSMutableData* _responseData;

    CGFloat _maxWidth;

    CGFloat _maxHeight;

    

    UITextField *_urlField;

    UITextField *_modeField;

    UITextField *_curField;

}


@property(nonatomic, copy)NSString *tnMode;


- (void)extendedLayout;


- (void)showAlertWait;

- (void)showAlertMessage:(NSString*)msg;

- (void)hideAlert;


- (void)startNetWithURL:(NSURL *)url;


- (UITextField *)textFieldWithFrame:(CGRect)frame placeHolder:(NSString *)placeHolder;


- (void)buttonAction;


@end


@implementation ViewController

@synthesize contentTableView;

@synthesize tnMode;




- (void)viewDidLoad

{

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    self.title = @"商户测试";

    

    //判断手机系统

    [self extendedLayout];

    

    //初始化tableview

    self.tableView = ({

        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, _maxWidth, _maxHeight) style:UITableViewStyleGrouped];

        tableView.delegate = self;

        tableView.dataSource = self;

        tableView;

    });

    

    [self.view addSubview:self.contentTableView];

}


//判断手机系统

- (void)extendedLayout

{

    BOOL iOS7 = [UIDevice currentDevice].systemVersion.floatValue >= 7.0;

    if (iOS7) {

        self.edgesForExtendedLayout = UIRectEdgeNone;

        self.automaticallyAdjustsScrollViewInsets = NO;

    }

    

    CGFloat offset = iOS7 ? 64 : 44;

    _maxWidth = CGRectGetWidth([UIScreen mainScreen].bounds);

    _maxHeight = CGRectGetHeight([UIScreen mainScreen].bounds)-offset;

    

    self.navigationController.navigationBar.translucent = NO;

}



//点击cell的时候就去网络请求数据

- (void)startNetWithURL:(NSURL *)url

{

    [_curField resignFirstResponder];

    _curField = nil;

    [self showAlertWait];

    

    NSURLRequest * urlRequest=[NSURLRequest requestWithURL:url];

    NSURLConnection* urlConn = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

    [urlConn start];

}

//用到的时候创建UITextField

- (UITextField *)textFieldWithFrame:(CGRect)frame placeHolder:(NSString *)placeHolder

{

    UITextField *textField = [[UITextField alloc] initWithFrame:frame] ;

    textField.placeholder = placeHolder;

    textField.borderStyle = UITextBorderStyleRoundedRect;

    textField.backgroundColor = [UIColor clearColor];

    textField.delegate = self;

    return textField;

}


#pragma mark - Alert初始化


- (void)showAlertWait

{

    [self hideAlert];

    _alertView = [[UIAlertView alloc] initWithTitle:kWaiting message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];

    [_alertView show];

    UIActivityIndicatorView* aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

    aiv.center = CGPointMake(_alertView.frame.size.width / 2.0f - 15, _alertView.frame.size.height / 2.0f + 10 );

    [aiv startAnimating];

    [_alertView addSubview:aiv];


}


- (void)showAlertMessage:(NSString*)msg

{

    [self hideAlert];

    _alertView = [[UIAlertView alloc] initWithTitle:kNote message:msg delegate:self cancelButtonTitle:kConfirm otherButtonTitles:nil, nil];

    [_alertView show];

  

}

- (void)hideAlert

{

    if (_alertView != nil)

    {

        [_alertView dismissWithClickedButtonIndex:0 animated:NO];

        _alertView = nil;

    }

}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    _alertView = nil;

}


#pragma mark - 网络请求


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*)response

{

    NSHTTPURLResponse* rsp = (NSHTTPURLResponse*)response;

    //获取网络返回码

    NSInteger code = [rsp statusCode];

    if (code != 200)

    {

        

        [self showAlertMessage:kErrorNet];

        [connection cancel];

    }

    else

    {

        _responseData = [[NSMutableData alloc] init];

    }

}

//有数据的时候就接受数据

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{

    [_responseData appendData:data];

}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection

{

    [self hideAlert];

    NSString* tn = [[NSMutableString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];

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

    {

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

        //请求成功:把TN传给 UPPayplugin 此处设置代理监听支付结果

        [UPPayPlugin startPay:tn mode:self.tnMode viewController:self delegate:self];

    }

}


-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

{

    [self showAlertMessage:kErrorNet];

}



#pragma mark 监听支付结果

- (void)UPPayPluginResult:(NSString *)result

{

    NSString* msg = [NSString stringWithFormat:kResult, result];

    [self showAlertMessage:msg];

}





#pragma mark -

#pragma mark UITableView 代理方法


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    

    switch (indexPath.row) {

        case 0:

            

            self.tnMode = kMode_Development;

            [self startNetWithURL:[NSURL URLWithString:kURL_TN_Normal]];

            [tableView deselectRowAtIndexPath:indexPath animated:YES];

            

            break;

        case 1:

            self.tnMode = kMode_Development;

            [self startNetWithURL:[NSURL URLWithString:kURL_TN_Configure]];

            [tableView deselectRowAtIndexPath:indexPath animated:YES];

            break;

        case 2:

            [tableView deselectRowAtIndexPath:indexPath animated:NO];

            break;

            

        default:

            break;

    }

}


#pragma mark -

#pragma mark UITableView 数据源代理


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return (indexPath.row == 2) ? kCellHeight_Manual : kCellHeight_Normal;

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex

{

    return 3;

}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];

    

    switch (indexPath.row) {

        case 0:

        {

            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

            cell.textLabel.text = @"普通订单";

            cell.detailTextLabel.text = @"mode=01";

        }

            

            break;

        case 1:

        {

            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

            cell.textLabel.text = @"配置用户123456789";

            cell.detailTextLabel.text = @"mode=01";

        }

            break;

        case 2:

        {

             //点击cell的时候去掉选中效果,

            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

            

            CGRect urlFrame = CGRectMake(10, 10, CGRectGetWidth(tableView.frame)-20, 35);

            _urlField = [self textFieldWithFrame:urlFrame placeHolder:@"获取TN地址"];

            [cell.contentView addSubview:_urlField];

            

            CGRect modeFrame = CGRectMake(10, 55, CGRectGetWidth(tableView.frame)-20, 35);

            _modeField = [self textFieldWithFrame:modeFrame placeHolder:@"mode"];

            [cell.contentView addSubview:_modeField];

            

            CGRect btnFrame = CGRectMake(50, 100, CGRectGetWidth(tableView.frame)-100, 35);

            UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

            button.frame = btnFrame;

            [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];

            [button setTitle:@"      " forState:UIControlStateNormal];

            [cell.contentView addSubview:button];

            

        }

            break;

        

            

        default:

            break;

    }

    

    

    

    return cell;

}


- (void)buttonAction

{

    self.tnMode = _modeField.text;

    [self startNetWithURL:[NSURL URLWithString:_urlField.text]];

}



#pragma mark UITextFieldDelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField

{

    _curField = textField;

}


@end



 


【6层】一字型框架办公楼(含建筑结构图、计算书) 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值