APICloud模拟微信支付调用(非集成微信支付SDK)

最近因为公司业务发展,需要研究APICloud的使用,主要是针对iOS模块化开发这块。我在APICloud官网搜索半天也没得到解决方案,而下载的APICloud Demo过于简单,故经过几天的钻研,找到了解决办法,现总结出来,给有类似需求的朋友提供一个解决方案。老规矩,先发一个效果图(内附iOS模块及项目Demo)。

APICloud模拟微信支付调用(非集成微信支付SDK)_第1张图片

一、两个核心文件内容
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模块
APICloud模拟微信支付调用(非集成微信支付SDK)_第2张图片

三、其它注意事项
在APICloud新手指南里写了,如果调用微信支付等SDK时在config.xml里做相应配置:比如

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

最新版的APICloud已经支持info.plist写入相应配置信息,如果有相应的需求可以在res文件夹下创建info.plist文件:比如我们打开微信App的时候需要做如下配置:
APICloud模拟微信支付调用(非集成微信支付SDK)_第3张图片

你可能感兴趣的:(iOS开发笔记,前端,APICloud开发,模拟微信支付流程,不是集成微信SDK)