iOS 集成支付宝支付步骤及注意事项

1.启动IDE(如Xcode),把iOS包中的压缩文件中以下文件拷贝到项目文件夹下,并导入到项目工程中

      AlipaySDK.bundle; AlipaySDK.framework

在Build Phases选项卡的Link Binary With Libraries中,增加以下依赖:

其中,需要注意的是:

如果是Xcode 7.0之后的版本,需要添加libc++.tbd、libz.tbd;

如果是Xcode 7.0之前的版本,需要添加libc++.dylib、libz.dylib



2.AppDelegate.m中引入头文件 < #import <AlipaySDK/AlipaySDK.h>>

//9.0前的方法,为了适配低版本 保留

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

         if ([url.host isEqualToString:@"safepay"]) {

               //跳转支付宝钱包进行支付,处理支付结果

              [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary    *resultDic) {

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

              }];

           }

            return YES;

}

//9.0后的方法

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{

(://pay 之前的那串字符串就是你的APPID,)

            if ([url.host isEqualToString:@"safepay"]) {

           // 支付跳转支付宝钱包进行支付,处理支付结果

                    [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {

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

                    }];

            }

          return YES;

}



3.在发起支付的页面

       3.1 先请求后台获取支付信息和签名信息;

       3.2 调用:

              [[AlipaySDK defaultService] payOrder:returnData[@"payeeOrder"][@"payInfo"] fromScheme:@"com.vivebest.paymd"callback:^(NSDictionary *resultDic) {

                          QLLog(@"reslut = %@",resultDic);

              }];

        3.3 在info中配置scheme,与参数中传递的要一致



4.有可能遇到的坑

坑1: 我遇到的问题是做聚合支付的sdk的时候需要集成支付宝支付功能

        导入了AlipaySDK.framework和bundle 文件,但添加第三方依赖库libz.tbd和libc++.tbd的时候就会包编译报错Xcode 版本是8.2 ,iOS 项目是动态库(打包给别人使用),导入了AlipaySDK.framework和bundle 文件,但添加第三方依赖库libz.tbd和libc++.tbd的时候就会包编译报错

error: /Users/mac/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Users/mac/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk/usr/lib/libc.tbd is not an object file (not allowed in a library)

然后尝试谷歌上面一些做法:

1.Delete all references to .tbd files from either your linked libraries phase, or from the copied bundle resources phase (where they sometimes will be added).

Go to Build Phases >Link Binary with Librairies > + > Add other -> Add a library to your project, then click 'Add Other...' then press Shift+Command+G and type in the path '/usr/lib' - you'll find libz.dylib there.

add "-lz" to the other linker flags

这个是网络上面的一些方法,试过也没法实现,项目使用Aggregate来打包,导进一个app里面使用的会报这种异常

Undefined symbols for architecture armv7:

"_OBJC_CLASS_$_AlipaySDK", referenced from:

objc-class-ref in LocalSDK(LocalHttpHelper.o)

ld: symbol(s) not found for architecture armv7

clang: error: linker command failed with exit code 1 (use -v to see invocation)

这个错误是不是跟这两个 libz.tbd和libc++.tbd 有关 ?

解决办法:第三方支付宝库不参加打包即可,在app中引用。



坑2: 引入支付宝 缺少 #include<openssl/asn1.h>报错

问题描述:报错openssl/asn1.h file not found

解决方法:在 Building Settings -> Search Paths -> Header Search Paths 里添加 openssl/asn1.h(因为openssl/asn1.h就在这个文件夹里) 的路径进去就可以了


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在我们应用开发中我们经常在自己的项目中使用到支付,下面我们来谈谈iOS这块的支付;iOS支付主要分为两类,第三方支...
    Hither阅读 8,328评论 9 42
  • iOS支付 iOS支付分为两类,第三方支付和应用内支付(内购)。 第三方支付包括:支付宝支付、微信支付、银联支付、...
    请输入账号名阅读 6,317评论 3 22
  • iOS支付 iOS支付分为两类,第三方支付和应用内支付(内购)。 第三方支付包括:支付宝支付、微信支付、银联支付、...
    帅不过oneS阅读 2,922评论 2 8
  • 实现支付宝支付的准备工作: 1.向支付宝签约,成为支付宝的商户 签约完成后,支付宝会提供一些必要的数据给我们 商户...
    Anson杨春安阅读 8,263评论 0 6
  • iOS支付 iOS支付分为两类,第三方支付和应用内支付(内购)。 第三方支付包括:支付宝支付、微信支付、银联支付、...
    羊驼先生丶阅读 665评论 1 3