RN对接京东支付sdk(IOS)
生活随笔
收集整理的這篇文章主要介紹了
RN对接京东支付sdk(IOS)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
京東支付IOS接入說明文檔
1、根據 京東支付IOS接入說明文檔 集成sdk依賴的framework,配置相關的內容(xcode 需要配置簽名)
2、在ios 下封裝調用sdk的方法
JDPayManager.h
// // JDPayManager.h // b2bapp // // Created by edz on 2021/3/9. // Copyright ? 2021 Facebook. All rights reserved. //#import <React/RCTBridgeModule.h>@interface JDPayManager : NSObject <RCTBridgeModule> @end?JDPayManager.m
.m文件是對.h文件中方法是實現,對外部是不可見的
// // JDPayManager.m // b2bapp // // Created by edz on 2021/3/9. // Copyright ? 2021 Facebook. All rights reserved. //#import <Foundation/Foundation.h> #import "JDPayManager.h" #import "ViewController.h" #import <JDPay/JDPay.h> #import <JDPay/JDPayJSONUtils.h>@implementation JDPayManagerRCT_EXPORT_MODULE();RCT_EXPORT_METHOD(addEvent:(NSDictionary *)payReqcallback:(RCTResponseSenderBlock) callback) {dispatch_async(dispatch_get_main_queue(), ^{UIViewController *weakSelfView = [self getCurrentVC];NSString *appId = [payReq objectForKey:@"appId"];NSString *merchant = [payReq objectForKey:@"merchant"];NSString *orderId = [payReq objectForKey:@"orderId"];NSString *signData = [payReq objectForKey:@"signData"];NSLog(@"京東支付");[JDPayAuth_mainModule() payWithViewController:weakSelfViewappID:appIdmerchant:merchantorderId:orderIdsignData:signDataextraInfo:nilcompletion:^(NSDictionary *resultDict) {NSLog(@"支付結果");NSLog(@"京東 result = %@",resultDict);callback(@[resultDict]);}];}); } - (UIViewController *)getCurrentVC {UIViewController * curVC = 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]]){curVC = nextResponder;}else{UIViewController * appRootVC = window.rootViewController;UIViewController * topVC = appRootVC;curVC = topVC;if (topVC.presentedViewController){curVC = topVC.presentedViewController;}}return curVC; }@end?AppDelegate.m
#pragma mark - Handle url - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation {NSMutableDictionary *options = [NSMutableDictionary dictionaryWithCapacity:2];if (sourceApplication != nil) {options[UIApplicationOpenURLOptionsSourceApplicationKey] = sourceApplication;}if (annotation != nil) {options[UIApplicationOpenURLOptionsAnnotationKey] = annotation;}return [self application:application openURL:url options:options]; }- (BOOL)application:(UIApplication *)appopenURL:(NSURL *)urloptions:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {if ([JDPayModule canHandleURL:url options:options]) {[JDPayModule handleURL:urloptions:optionscompletionHandler:^(NSDictionary * __nullable results, BOOL handled) {NSLog(@"handleURL:%@ options:%@ completionHandler:(%@, %@)",url, options, results, handled ? @"YES" : @"NO");}];return YES;}return NO; }3、喚起京東支付(jdpay接口需要生成一個京東訂單,返回商戶id、訂單id和京東支付MD5的密鑰)
MD5的密鑰需要通過MD5進行加密生產簽名
const { code, context, message } = await webapi.jdpay(tid);if (code == config.SUCCESS_CODE) {const text ='merchant=' +context.merchant +'&orderId=' +context.orderId +'&key=' +Const.MD5_KET;const signData = MD5.hex_md5(text).toLowerCase();const payRequest = {orderId: context.orderId,merchant: context.merchant,appId: Const.APP_ID,signData: signData};let JDPayModule;if (Platform.OS === 'ios') {JDPayModule = NativeModules.JDPayManager;JDPayModule.addEvent(payRequest, (result) => {console.log('result====>', result);if (result.payStatus == 'JDP_PAY_SUCCESS') {msg.emit('router: goToNext', {routeName: 'PaySuccess',tid: tid,payType: 'online'});}});}總結
以上是生活随笔為你收集整理的RN对接京东支付sdk(IOS)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对GCD的一些理解和实践
- 下一篇: [密码学基础][每个信息安全博士生应该知