NHFPay
介绍
NHFPay对常用支付方式(银联、微信、支付宝、Apple Pay)的一个封装
安装
- pod 'NHFPay'
- 手动下载然后将文件夹拖至工程中即可
使用方法
1.先进行初始化操作,位置放于自己经常放项目启动初始化的地方,比如APPDelegate.m中
头文件
#import "AlipayObject.h"
#import "ApplePayObject.h"
#import "UnionPayPaymentObject.h"
#import "WechatObject.h"
//初始化支付
[[AlipayObject getInstancetype] initByAppScheme:kAliAppScheme];
//银联初始化
[[UnionPayPaymentObject getInstancetype] initFromScheme:FromScheme payModel:PayModel];
//Apple Pay初始化
[[ApplePayObject getInstancetype] initByPayModel:PayModel mechantID:MechantID];
//微信初始化
[[WechatObject getInstancetype] initRegisterApp:WXAPPID];
2.回调处理
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{}
在AppDelegate.m中添加以上三个回调,将一下代码放于其中:
[[UnionPayPaymentObject getInstancetype] handlePaymentResult:url];
[[AlipayObject getInstancetype] testUrlHostBy:url];
[[WechatObject getInstancetype] handleOpenURL:url];
3.使用方法举一个例子
//Apple Pay message为后台返给端上的
- (void)applePayBy:(NSString *)message {
[[ApplePayObject getInstancetype] startPay:[message stringTrim] vc:strongSelf];
UIViewController *viewController = GetCurrentVC;
//成功
[ApplePayObject getInstancetype].applePayObjectResultSuccess = ^(NSString *errorDescription, NSString *otherInfo) {
};
//失败
[ApplePayObject getInstancetype].applePayObjectResultFail = ^(NSString *errorDescription, NSString *otherInfo) {
};
//取消
[ApplePayObject getInstancetype].applePayObjectResultCancel = ^(NSString *errorDescription, NSString *otherInfo) {
};
}
其他方式类似,请查看源码
3.说明
有的朋友有时候会用到友盟分享,友盟分享里边同样引用了微信支付宝等一些功能,所以如果使用友盟的时候大家可以采用友盟里边的微信精简版本