银联:
提供测试使用卡号、手机号信息(此类信息仅供测试,不会发生正式交易)招商银行预付费卡:
卡号:6226 4401 2345 6785
密码:111101
1>(
SDK
分为以下两个版本)选择的是
UPPayPlugin
版 本
UPPayPlugin.h
UPPayPluginDelegate.h
libUPPayPlugin.a
-
添 加 QuartzCore.framework、Security.framework到工程
-
-
在调用支付的界面添加
-
-
然后在.m调用:
[UPPayPluginstartPay:tnmode:@"01"viewController:selfdelegate:self];//解释一下 tn 是后台传过来的流水号,01是测试环境,生产环境是00,调用银联手机支付的当前UIViewController;
-
实现代理方法:
-
- //银联结果回调
- -(void)UPPayPluginResult:(NSString*)result
- {
- // NSString* msg = [NSString stringWithFormat:@"支付结果:%@", result];
- // [MyAlertView showWaitViewWithMessage:msg];
- int x;
- if ([result isEqualToString: @"fail"]) {
- [MyAlertView showWaitViewWithMessage:@"支付结果:失败"];
- x = 0;
- }else if([result isEqualToString: @"cancel"]){
- [MyAlertView showWaitViewWithMessage:@"支付结果:取消"];
- x = 0;
- }else if([result isEqualToString: @"success"]){
- [MyAlertView showWaitViewWithMessage:@"支付结果:成功"];
- x = 1;
- [self changeTheOrderStates:x];
- }else{
- }
- }
- //加密
- -(NSString*)doRsa:(NSString*)orderInfo
- {
- id<DataSigner> signer;
- signer = CreateRSADataSigner(PartnerPrivKey);
- NSString *signedString = [signer signString:orderInfo];
- return signedString;
- }
好了银联完成!!!
支付宝:
支付宝比银联少复杂点
1》导入包
引入系统的
CFNetwork.framework
SystemConfiguration.framework
Security.framework
如果用到了zbar 二维码会报错,需替换里面的.a文件
2》 然
后就是引入
//支付宝
#import "AlixLibService.h"
#import "PartnerConfig.h"
#import "DataSigner.h"
#import "DataVerifier.h"
#import "AlixPayResult.h"
3》就是调用函数去支付 和支付后的回调,但是支付宝要写两套1<是在AppDelegate.m中,是手机上装了支付宝的回调和处理。2<是在你要调用支付的当前控制器里一套,是手机没用装支付宝客户端请求web页的处理。
在AppDelegate.m中引入支付宝的类!(见2)
然后添加如下代码
- #pragma mark 支付宝独立客户端 回掉
- //独立客户端回调函数
- - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
- [self parse:url application:application];
- return YES;
- }
- - (void)parse:(NSURL *)url application:(UIApplication *)application {
- //结果处理
- AlixPayResult* result = [self handleOpenURL:url];
- if (result)
- {
- if (result.statusCode == 9000)
- {
- /*
- *用公钥验证签名 严格验证请使用result.resultString与result.signString验签
- */
- //交易成功
- NSString* key = AlipayPubKey;//签约帐户后获取到的支付宝公钥
- id<DataVerifier> verifier;
- verifier = CreateRSADataVerifier(key);
- if ([verifier verifyString:result.resultString withSign:result.signString])
- {
- //验证签名成功,交易结果无篡
- [[NSNotificationCenter defaultCenter] postNotificationName:@"JYsuccess"object:nil];
- }
- }
- else
- {
- //交易失败
- [[NSNotificationCenter defaultCenter] postNotificationName:@"JYfail"object:nil];
- }
- }
- else
- {
- //交易失败
- [[NSNotificationCenter defaultCenter] postNotificationName:@"JYfail"object:nil];
- }
- }
- - (AlixPayResult *)resultFromURL:(NSURL *)url {
- NSString * query = [[url query] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- #if ! __has_feature(objc_arc)
- return [[[AlixPayResult alloc] initWithString:query] autorelease];
- #else
- return [[AlixPayResult alloc] initWithString:query];
- #endif
- }
- - (AlixPayResult *)handleOpenURL:(NSURL *)url {
- AlixPayResult * result = nil;
- if (url != nil && [[url host] compare:@"safepay"] == 0) {
- result = [self resultFromURL:url];
- }
- return result;
- }
//在调用支付的控制器中添加如下代码
调用支付代码》
- //注册购买请求
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(successToDo:) name:@"JYsuccess" object:nil];
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(failToDo:) name:@"JYfail" object:nil];
- //时间戳
- // NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];
- NSString *timeSp = _currentOrderNo;
- NSString *subject = @"惠人产品购买";
- NSString *body = @"商品购买";
- NSString *notify_url = @"";
- //订单ID
- NSString *IDstring = [[NSString alloc]initWithFormat:@"%@",timeSp];
- // NSString *fee = @"0.01";
- NSString *fee = _currentOrderMoney;
- NSString *TempOrderString = [NSString stringWithFormat:@"partner=\"%@\"&seller_id=\"%@\"&out_trade_no=\"%@\"&subject=\"%@\"&body=\"%@\"&total_fee=\"%@\"¬ify_url=\"%@\"&service=\"mobile.securitypay.pay\"&_input_charset=\"utf-8\"&payment_type=\"1\"",PartnerID,SellerID,IDstring,subject,body,fee,notify_url];
- NSString* signedStr = [self doRsa:TempOrderString];
- NSString *orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",TempOrderString,signedStr,@"RSA"];
- #ifdef DEBUG
- NSLog(@"购买请求%@",orderString);
- #endif
- NSString *appScheme = @"BlueMobiProject";
- [AlixLibService payOrder:orderString AndScheme:appScheme seletor:@selector(paymentResult:) target:self];
处理结果代码》
- #pragma mark web会调函数
- //wap回调函数
- -(void)paymentResult:(NSString *)resultd
- {
- //结果处理
- #ifdef EEBUG
- NSLog(@"返回的结果是%@",resultd);
- #endif
- AlixPayResult* result = [[AlixPayResult alloc] initWithString:resultd];
- if (result)
- {
- if (result.statusCode == 9000)
- {
- /*
- *用公钥验证签名 严格验证请使用result.resultString与result.signString验签
- */
- //交易成功
- NSString* key = AlipayPubKey;//签约帐户后获取到的支付宝公钥
- id<DataVerifier> verifier;
- verifier = CreateRSADataVerifier(key);
- if ([verifier verifyString:result.resultString withSign:result.signString])
- {
- //验证签名成功,交易结果无篡
- [[NSNotificationCenter defaultCenter] postNotificationName:@"JYsuccess"object:nil];
- // BMBuySuccess *buysuccess = [[BMBuySuccess alloc]init];
- // NSLog(@"返回数据=%@",_TempDic);
- buysuccess._TempDic = _TempDic;
- // [buysuccess requite:_TempDic and:_liushuiID];
- }
- }
- else
- {
- //交易失败
- [[NSNotificationCenter defaultCenter] postNotificationName:@"JYfail"object:nil];
- }
- }
- else
- {
- //交易失败
- [[NSNotificationCenter defaultCenter] postNotificationName:@"JYfail"object:nil];
- }
- }
好了支付宝完成!!