1.啟動(dòng)IDE(如Xcode),把iOS包中的壓縮文件中以下文件拷貝到項(xiàng)目文件夾下,并導(dǎo)入到項(xiàng)目工程中
????? AlipaySDK.bundle; AlipaySDK.framework
在Build Phases選項(xiàng)卡的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"]) {
?????????????? //跳轉(zhuǎn)支付寶錢(qián)包進(jìn)行支付,處理支付結(jié)果
????????????? [[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"]) {
????? ?? ? // 支付跳轉(zhuǎn)支付寶錢(qián)包進(jìn)行支付,處理支付結(jié)果
???????? ? ? ? ? ?? [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
????????????? ? ? ? ? ? ? ? ?? NSLog(@"result = %@",resultDic);
??????? ? ? ? ? ? ? }];
?? ? ? ? ?? }
????????? return YES;
}
3.在發(fā)起支付的頁(yè)面
?????? 3.1 先請(qǐng)求后臺(tái)獲取支付信息和簽名信息;
?????? 3.2 調(diào)用:
???? ? ? ? ?? [[AlipaySDK defaultService] payOrder:returnData[@"payeeOrder"][@"payInfo"] fromScheme:@"com.vivebest.paymd"callback:^(NSDictionary *resultDic) {
????????????????????????? QLLog(@"reslut = %@",resultDic);
????????????? }];
??????? 3.3 在info中配置scheme,與參數(shù)中傳遞的要一致
4.有可能遇到的坑
坑1: 我遇到的問(wèn)題是做聚合支付的sdk的時(shí)候需要集成支付寶支付功能
??????? 導(dǎo)入了AlipaySDK.framework和bundle 文件,但添加第三方依賴庫(kù)libz.tbd和libc++.tbd的時(shí)候就會(huì)包編譯報(bào)錯(cuò)Xcode 版本是8.2 ,iOS 項(xiàng)目是動(dòng)態(tài)庫(kù)(打包給別人使用),導(dǎo)入了AlipaySDK.framework和bundle 文件,但添加第三方依賴庫(kù)libz.tbd和libc++.tbd的時(shí)候就會(huì)包編譯報(bào)錯(cuò)
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
這個(gè)是網(wǎng)絡(luò)上面的一些方法,試過(guò)也沒(méi)法實(shí)現(xiàn),項(xiàng)目使用Aggregate來(lái)打包,導(dǎo)進(jìn)一個(gè)app里面使用的會(huì)報(bào)這種異常
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)
這個(gè)錯(cuò)誤是不是跟這兩個(gè) libz.tbd和libc++.tbd 有關(guān) ?
解決辦法:第三方支付寶庫(kù)不參加打包即可,在app中引用。
坑2: 引入支付寶 缺少 #include<openssl/asn1.h>報(bào)錯(cuò)
問(wèn)題描述:報(bào)錯(cuò)openssl/asn1.h file not found
解決方法:在 Building Settings -> Search Paths -> Header Search Paths 里添加 openssl/asn1.h(因?yàn)閛penssl/asn1.h就在這個(gè)文件夾里) 的路徑進(jìn)去就可以了