Skip to content

iOS---支付

概述

借助宝船SDK平台接入各个平台的支付,你可以在你的应用中快速轻松地实现支付功能。

SDK平台配置和依赖导入

应用接入

1.在AppDelegate类中初始化SDK。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
       // Override point for customization after application launch.
       [BrickManager initBrickWith:@"cdshf8dfbshdf8sdfc" appSecret:@"sdjncvs889347r983274cvhsd" bindId:@"com.xxx.name"];//宝船出海SDK应用创建后,平台生成的key
       //宝船出海SDK应用创建后,平台生成的秘钥
       [BrickManager wechatRegisterAppWith:@"wxd326eceb36c332323" universalLink:@"https://weixin.com/"];
       //微信开发者ID
       //微信开发者Universal Link
       return YES;
    }

2.配置添加CoreTelephony.framework,libc++.tbd,libsqlite3.0.tbd,libz.tbd,SystemConfiguration.framework,WebKit.framework。

bricksdkcreate10

3.配置URL Type。

bricksdkcreate11

4.配置Other Linker Flags。

bricksdkcreate12

用户支付相关方法和说明

用户支付

1.在您需要支付的UIViewController页面中,需要做支付操作的时候调用支付。以微信支付为例:

    - (IBAction)wechatPayBtnClick:(UIButton *)sender {
        [BrickManager wechatPayFromOrderInfo:@"订单信息" productId:@"产品号" money:@"金额" extraData:@"透传数据(需要SDK返回的数据)" userAgent:@"User-Agent" success:^(BrickCompleteResult * _Nonnull completeResult) {
           BrickCompleteResult *result = completeResult;
           NSInteger code = result.code;
           NSString *message = result.message;
           NSDictionary *data = result.data;
           NSLog(@"wechatPaySuccess:%ld-----%@------%@",(long)code,message,data);
        } failure:^(BrickCompleteResult * _Nonnull completeResult) {
           BrickCompleteResult *result = completeResult;
           NSInteger code = result.code;
           NSString *message = result.message;
           NSDictionary *data = result.data;
           NSLog(@"wechatPayFailure:%ld-----%@----%@",(long)code,message,data);
        }];
    }

2.支付宝支付示例:

    - (IBAction)alipayBtnClick:(UIButton *)sender {
        [BrickManager alipayFromOrder:@"支付订单信息字串" productId:@"产品号" money:@"金额" extraData:@"透传数据(需要SDK返回的数据)" userAgent:@"User-Agent" withScheme:@"调用支付的app注册在info.plist中的scheme" andCallBackSuccess:^(BrickCompleteResult * _Nonnull completeResult) {
           BrickCompleteResult *result = completeResult;
           NSInteger code = result.code;
           NSString *message = result.message;
           NSLog(@"alipaySuccess:%ld-----%@",(long)code,message);
        } failure:^(BrickCompleteResult * _Nonnull completeResult) {
           BrickCompleteResult *result = completeResult;
           NSInteger code = result.code;
           NSString *message = result.message;
           NSLog(@"alipayFailure:%ld-----%@",(long)code,message);
        }];
    }

3.苹果内购支付示例:

    - (IBAction)applePayBtnClick:(UIButton *)sender {
        [BrickManager appleInPurchaseFromProductsId:@"产品id" orderId:@"订单号" money:@"金额" extraData:@"透传数据(需要SDK返回的数据" userAgent:@"User-Agent" success:^(BrickCompleteResult * _Nonnull completeResult) {
           BrickCompleteResult *result = completeResult;
           NSInteger code = result.code;
           NSString *message = result.message;
           NSDictionary *data = result.data;
           NSLog(@"appleSuccess:%ld-----%@----%@",(long)code,message,data);
        } failure:^(BrickCompleteResult * _Nonnull completeResult) {
          BrickCompleteResult *result = completeResult;
          NSInteger code = result.code;
          NSString *message = result.message;
          NSLog(@"appleFailure:%ld-----%@",(long)code,message);
        }];
    }

4.苹果内购支付恢复购买:

    - (IBAction)restoreBtnClick:(UIButton *)sender {
        [BrickManager restoreSuccess:^(BrickCompleteResult * _Nonnull completeResult) {
            NSLog(@"恢复购买成功");
        } failure:^(BrickCompleteResult * _Nonnull completeResult) {
           NSLog(@"恢复购买失败");
        }];
    }

5.重写AppDelegate或SceneDelegate的continueUserActivity方法: 注意:适配了SceneDelegate的App,系统将会回调SceneDelegate的continueUserActivity方法,所以需要重写SceneDelegate的该方法。

    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url  {
        return [BrickManager brickPayHandleOpenURL:url];
    }
    

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {    
        return [BrickManager brickPayHandleOpenURL:url];
    }


    - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
        NSArray *contextArray = [URLContexts allObjects];
        UIOpenURLContext *urlContent = [contextArray firstObject];
        [BrickManager brickPayHandleOpenURL:urlContent.URL];
    }

    - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
        [BrickManager brickPayHandleOpenUniversalLink:userActivity];
    }