支付宝sdk iOS 集成

1添加支付宝源文件和库文件AlipayOrder.h    AlipayOrder.m    AlipayResult.h    AlipayResult.m  AlixLibService.h   PartnerConfig.h    AlipayRsaLib.a    Alixpay.bundle   AlixPaylib_arc.a    libcrypto.a   libssl.a    

2添加json类库和demo中的rsa签名    json文件夹和RSA文件夹

3添加相关类库  CoreGraphics.framework  Foundation.framework UIKit.framework  CFNetwork.framework  SystemConfiguration.framework 

 

4在delegate文件中加入支付回调函数

//独立客户端回调函数

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    

    [self parse:url application:application];

    return YES;

}

 

- (void)parse:(NSURL *)url application:(UIApplication *)application {

    

    //结果处理

    AlixPayResult* result = [selfhandleOpenURL:url];

    

    if (result)

    {

        

        if (result.statusCode == 9000)

        {

            /*

             *用公钥验证签名 严格验证请使用result.resultString与result.signString验签

             */

            

            //交易成功

            NSString* key = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";

            id<DataVerifier> verifier;

            verifier = CreateRSADataVerifier(key);

            

            if ([verifier verifyString:result.resultStringwithSign:result.signString])

            {

                //验证签名成功,交易结果无篡改

                UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示"

                                                                     message:result.statusMessage

                                                                    delegate:nil

                                                           cancelButtonTitle:@"确定"

                                                           otherButtonTitles:nil];

                [alertView show];

                alertView.delegate = self;

                

                

            //验签错误

            else {

                UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示"

                                                                     message:@"签名错误"

                                                                    delegate:nil

                                                           cancelButtonTitle:@"确定"

                                                           otherButtonTitles:nil];

                [alertView show];

                

            }

        }

        //如果支付失败,可以通过result.statusCode查询错误码

        else {

            UIAlertView * alertView = [[UIAlertViewalloc] initWithTitle:@"提示"

                                                                 message:result.statusMessage

                                                                delegate:nil

                                                       cancelButtonTitle:@"确定"

                                                       otherButtonTitles:nil];

            [alertView show];

            

        }

        

        

    }

    else

    {

        //交易失败

    }

    

    NSLog(@"1111%i",result.statusCode);

    NSLog(@"222%@",result.description);

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

    NSLog(@"444%@",result.resultString);

    

    

}

 

- (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;

}

5设置url 在target中的info中,添加URL Types

posted @   itlover2013  阅读(316)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示