1. 程式人生 > >APICloud模擬微信支付呼叫(非整合微信支付SDK)

APICloud模擬微信支付呼叫(非整合微信支付SDK)

最近因為公司業務發展,需要研究APICloud的使用,主要是針對iOS模組化開發這塊。我在APICloud官網搜尋半天也沒得到解決方案,而下載的APICloud Demo過於簡單,故經過幾天的鑽研,找到了解決辦法,現總結出來,給有類似需求的朋友提供一個解決方案。老規矩,先發一個效果圖(內附iOS模組及專案Demo)。

APICloud效果展示

一、兩個核心檔案內容
APICloudSDK.m

#import "APICloudSDK.h"
#import "NSDictionaryUtils.h"
#import "PayModel.h"
#import "ResultModel.h"
#import "ThridViewController.h"
@interface APICloudSDK () { NSUInteger _cbId; } @end @implementation APICloudSDK - (id)initWithUZWebView:(UZWebView *)webView_ { if (self = [super initWithUZWebView:webView_]) { } return self; } - (void)dispose { //do clean } //調起iOS模組方法 - (void)beginPayWithInfo:(NSDictionary
*)params { NSLog(@"params = %@", params); _cbId = [params integerValueForKey:@"cbId" defaultValue:0]; [PayModel sharedPayInfo].orderNo = params[@"orderNo"]; [PayModel sharedPayInfo].transTime = params[@"transtime"]; [PayModel sharedPayInfo].totalFee = params[@"totalFee"]; [PayModel sharedPayInfo].title
= params[@"title"]; [PayModel sharedPayInfo].body = params[@"body"]; UIViewController *currentVC = [self getCurrentVC]; [self startPay:currentVC resultBlock:^(NSDictionary *resultDict) { NSLog(@"resultDict = %@", resultDict); if (_cbId > 0) { [self sendResultEventWithCallbackId:_cbId dataDict:resultDict errDict:nil doDelete:YES]; } }]; } - (void)startPay:(UIViewController *)subCotroller resultBlock:(void (^)(NSDictionary * resultDict))introduceResultBlock { [ResultModel sharedInstance].payResultBlock = introduceResultBlock; ThridViewController *thridVC = [[ThridViewController alloc] init]; UINavigationController *navVc = [[UINavigationController alloc] initWithRootViewController:thridVC]; [subCotroller presentViewController:navVc animated:YES completion:nil]; } //獲取當前控制器 - (UIViewController *)getCurrentVC { UIViewController *result = nil; UIWindow * window = [[UIApplication sharedApplication] keyWindow]; if (window.windowLevel != UIWindowLevelNormal) { NSArray *windows = [[UIApplication sharedApplication] windows]; for(UIWindow * tmpWin in windows) { if (tmpWin.windowLevel == UIWindowLevelNormal) { window = tmpWin; break; } } } UIView *frontView = [[window subviews] objectAtIndex:0]; id nextResponder = [frontView nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) result = nextResponder; else result = window.rootViewController; return result; } @end

module.json檔案

 {
    "name":"aPICloudSDK",
    "class":"APICloudSDK",
    "methods":["beginPayWithInfo"],
    "launchClassMethod":"myLaunch"
 }

二、iOS模組及使用方法簡單說明
1.下載iOS模組及專案Demo
點選下載iOS模組
點選下載相關Demo

2.匯入iOS模組
匯入iOS模組

三、其它注意事項
在APICloud新手指南里寫了,如果呼叫微信支付等SDK時在config.xml裡做相應配置:比如

<feature name="wxPay">  
    <param name="urlScheme" value=""/>  
    <param name="apiKey" value=""/>  
    <param name="apiSecret" value=""/>  
</feature>  

最新版的APICloud已經支援info.plist寫入相應配置資訊,如果有相應的需求可以在res資料夾下建立info.plist檔案:比如我們開啟微信App的時候需要做如下配置:
res資料夾下建立info.plist