From b38cb30e948dbb588b6a2008d6094576bf71f6a8 Mon Sep 17 00:00:00 2001 From: wanghualei Date: Tue, 7 Mar 2023 14:04:48 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=92=8C=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo.xcodeproj/project.pbxproj | 4 +-- demo/AppDelegate.m | 9 +++---- demo/Common/FINExtensionHelper.m | 43 +++++++++++++++++++++++++++++++- demo/MainViewController.m | 2 +- demo/finosprite.plist | 14 ----------- 5 files changed, 49 insertions(+), 23 deletions(-) delete mode 100644 demo/finosprite.plist diff --git a/demo.xcodeproj/project.pbxproj b/demo.xcodeproj/project.pbxproj index bf7a572..30f70a4 100644 --- a/demo.xcodeproj/project.pbxproj +++ b/demo.xcodeproj/project.pbxproj @@ -172,7 +172,7 @@ 9DD565B623EC45080011FC4A /* Frameworks */, 9DD565B723EC45080011FC4A /* Resources */, DFB054DF507DE3B18CCCE932 /* [CP] Embed Pods Frameworks */, - 33C306F0B0B6C469FD078FB0 /* [CP] Copy Pods Resources */, + 11B173FBB433EBB6C00BA0E7 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -231,7 +231,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 33C306F0B0B6C469FD078FB0 /* [CP] Copy Pods Resources */ = { + 11B173FBB433EBB6C00BA0E7 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( diff --git a/demo/AppDelegate.m b/demo/AppDelegate.m index 4e38006..d8f11e8 100644 --- a/demo/AppDelegate.m +++ b/demo/AppDelegate.m @@ -46,7 +46,8 @@ FATConfig *config = [FATConfig configWithStoreConfigs:configs]; [[FATClient sharedClient] initWithConfig:config error:nil]; - [[FATClient sharedClient] setEnableLog:YES]; + // 设置Log日志 + [[FATClient sharedClient].logManager initLogWithLogDir:nil logLevel:FATLogLevelVerbose consoleLog:YES]; [FATClient sharedClient].delegate = [FINDemoClientHelper sharedHelper]; // 注入自定义api @@ -57,10 +58,8 @@ // // 注册高德地图 // [FATGDMapComponent setGDMapAppKey:@"申请的key"]; - if ([bundleId isEqualToString:@"com.finogeeks.mop.finosprite"]) { - // 该appID【wx85663af68a0cbbc8】绑定的应用为凡泰助手,若要生效,请修改BundleID为com.finogeeks.mop.finosprite - [WXApi registerApp:@"wx85663af68a0cbbc8" universalLink:@"https://www.finclip.com/finosprite/"]; - } + // 注册微信SDK +// [WXApi registerApp:@"微信开放sdk的key" universalLink:@"微信开放sdk的universalLink"]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor whiteColor]; diff --git a/demo/Common/FINExtensionHelper.m b/demo/Common/FINExtensionHelper.m index eb44105..d3809f8 100644 --- a/demo/Common/FINExtensionHelper.m +++ b/demo/Common/FINExtensionHelper.m @@ -85,14 +85,19 @@ static FINExtensionHelper *instance = nil; // 注入微信支付方法 __weak typeof(self) weakSelf = self; [[FATClient sharedClient] registerExtensionApi:@"requestPayment" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) { - // 支付调用,调用结果通过回调通告小程序 + // 支付有两种方式实现: + // 1.利用app实现支付,结果通过回调通告小程序 [weakSelf getTestPayment:callback]; + + // 2.使用微信小程序实现支付 +// [weakSelf wechatMiniProgramPayment:appletInfo param:param callback:callback]; }]; } #pragma mark - WXPay // 模拟向服务请求支付订单 - (void)getTestPayment:(FATExtensionApiCallback)callback { + // 以下支持示例代码,演示自行实现的过程 NSString *urlString = @"https://finclip-testing.finogeeks.club/mop/wechat-auth/api/order"; NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *requset = [NSMutableURLRequest requestWithURL:url]; @@ -132,6 +137,42 @@ static FINExtensionHelper *instance = nil; [task resume]; } +- (void)wechatMiniProgramPayment:(FATAppletInfo *)appletInfo + param:(NSDictionary *)param + callback:(FATExtensionApiCallback)callback +{ + NSDictionary *info = appletInfo.wechatLoginInfo; + NSString *wxid = appletInfo.wechatLoginInfo[@"wechatOriginId"]; + NSString *path = appletInfo.wechatLoginInfo[@"paymentUrl"]; + if (wxid.length == 0 || path.length == 0) { + callback(FATExtensionCodeFailure, @{@"desc":@"微信小程序关联信息异常"}); + return; + } + + NSDictionary *dataDic = param; + NSString *payString = [NSString stringWithFormat:@"?appId=%@&nonceStr=%@&package=%@&paySign=%@&signType=%@&timeStamp=%@&type=%@", dataDic[@"appId"], dataDic[@"nonceStr"], dataDic[@"package"], dataDic[@"paySign"], dataDic[@"signType"], dataDic[@"timeStamp"], dataDic[@"type"]]; + + // 需要appDelegate 里注册微信开放SDK。 + WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object]; + launchMiniProgramReq.userName = wxid; + launchMiniProgramReq.path = [NSString stringWithFormat:@"%@%@", wxid, payString]; + if (appletInfo.appletVersionType == FATAppletVersionTypeRelease) { + launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //正式版 + } else if (appletInfo.appletVersionType == FATAppletVersionTypeTrial) { + launchMiniProgramReq.miniProgramType = WXMiniProgramTypePreview; //体验版 + } else { + launchMiniProgramReq.miniProgramType = WXMiniProgramTypeTest; //开发版 + } + [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) { + NSLog(@"打开微信:%d", success); + if (success) { + callback(FATExtensionCodeSuccess, @{@"desc":@"支付成功"}); + return; + } + callback(FATExtensionCodeFailure, @{@"desc":@"支付失败"}); + }]; +} + // 签名加密(正常是放在后台处理,由上面的请求接口返回 - (NSString *)sha256:(NSString *)shaStr { NSData *data = [shaStr dataUsingEncoding:NSUTF8StringEncoding]; diff --git a/demo/MainViewController.m b/demo/MainViewController.m index c6d15cc..5481b9d 100644 --- a/demo/MainViewController.m +++ b/demo/MainViewController.m @@ -137,7 +137,7 @@ [[FATClient sharedClient] startAppletWithRequest:request InParentViewController:self completion:^(BOOL result, FATError *error) { } closeCompletion:^{ - + [[FATClient sharedClient] clearMemoryCache]; }]; } diff --git a/demo/finosprite.plist b/demo/finosprite.plist deleted file mode 100644 index 2940202..0000000 --- a/demo/finosprite.plist +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - appId - 60d58080a2b11b0001c439a4 - title - 小程序微信登录&支付示例 - startParams - - - -