From 97c42125ab362ee45802624d6de5db5d170ba7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=81=A5=E8=BE=89?= <27-hujianhui@users.noreply.gitlab.gitlab.finogeeks.club> Date: Tue, 24 May 2022 15:42:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= 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.h | 3 +- demo/Common/FINExtensionHelper.m | 72 +++++++++++++++++++++----------- demo/demo.entitlements | 10 +++++ demo/finosprite.plist | 2 +- 6 files changed, 67 insertions(+), 33 deletions(-) create mode 100644 demo/demo.entitlements diff --git a/demo.xcodeproj/project.pbxproj b/demo.xcodeproj/project.pbxproj index 02fadeb..4f84d3e 100644 --- a/demo.xcodeproj/project.pbxproj +++ b/demo.xcodeproj/project.pbxproj @@ -48,6 +48,7 @@ A8CE73522810F8C800965B7E /* FCQRCodeScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FCQRCodeScanViewController.h; sourceTree = ""; }; A8CE73542810F8C800965B7E /* FCQRScanView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FCQRScanView.m; sourceTree = ""; }; A8CE73552810F8C800965B7E /* FCQRScanView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FCQRScanView.h; sourceTree = ""; }; + D6278645283CC38F001270F1 /* demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = demo.entitlements; sourceTree = ""; }; FBEBA7E73B95B66C846E76FF /* Pods-demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo.debug.xcconfig"; path = "Target Support Files/Pods-demo/Pods-demo.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -84,6 +85,7 @@ 9DD565BB23EC45080011FC4A /* demo */ = { isa = PBXGroup; children = ( + D6278645283CC38F001270F1 /* demo.entitlements */, A8CE734B2810F3B400965B7E /* Common */, 9DD565BC23EC45080011FC4A /* AppDelegate.h */, 9DD565BD23EC45080011FC4A /* AppDelegate.m */, @@ -432,6 +434,7 @@ baseConfigurationReference = FBEBA7E73B95B66C846E76FF /* Pods-demo.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = demo/demo.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 9QCKYFU5M4; @@ -454,6 +457,7 @@ baseConfigurationReference = 3F2BFD149B6F799A303A07B3 /* Pods-demo.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = demo/demo.entitlements; CODE_SIGN_IDENTITY = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = 9QCKYFU5M4; diff --git a/demo/AppDelegate.m b/demo/AppDelegate.m index 7ec1fc7..4727484 100644 --- a/demo/AppDelegate.m +++ b/demo/AppDelegate.m @@ -10,9 +10,7 @@ #import "MainViewController.h" #import "FINExtensionHelper.h" #import "FINDemoClientHelper.h" - #import -#import @interface AppDelegate () @@ -53,7 +51,7 @@ if ([bundleId isEqualToString:@"com.finogeeks.mop.finosprite"]) { // 该appID【wx85663af68a0cbbc8】绑定的应用为凡泰助手,若要生效,请修改BundleID为com.finogeeks.mop.finosprite - [WXApi registerApp:@"wx85663af68a0cbbc8" universalLink:@"https://www.finclip.com"]; + [WXApi registerApp:@"wx85663af68a0cbbc8" universalLink:@"https://www.finclip.com/finosprite/"]; } self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; @@ -67,10 +65,7 @@ } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { - if ([url.scheme isEqualToString:@"wx85663af68a0cbbc8"]) { - return [WXApi handleOpenURL:url delegate:(id _Nullable)[FINExtensionHelper sharedHelper]]; - } - return YES; + return [WXApi handleOpenURL:url delegate:[FINExtensionHelper sharedHelper]]; } @end diff --git a/demo/Common/FINExtensionHelper.h b/demo/Common/FINExtensionHelper.h index 3782569..d94c2c2 100644 --- a/demo/Common/FINExtensionHelper.h +++ b/demo/Common/FINExtensionHelper.h @@ -6,8 +6,9 @@ // #import +#import -@interface FINExtensionHelper : NSObject +@interface FINExtensionHelper : NSObject + (instancetype)sharedHelper; diff --git a/demo/Common/FINExtensionHelper.m b/demo/Common/FINExtensionHelper.m index 38d03e6..d839fe7 100644 --- a/demo/Common/FINExtensionHelper.m +++ b/demo/Common/FINExtensionHelper.m @@ -44,31 +44,46 @@ static FINExtensionHelper *instance = nil; // 注入自定义api - (void)registerCustomApis { - [[FATClient sharedClient] registerExtensionApi:@"onNative" handle:^(id param, FATExtensionApiCallback callback) { + [[FATClient sharedClient] registerExtensionApi:@"onNative" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) { NSString *inputText = @"床前明月光,疑是地上霜。举头望明月,低头思故乡。"; callback(FATExtensionCodeSuccess, @{@"text":inputText}); }]; - [[FATClient sharedClient] fat_registerWebApi:@"user_define_native" handle:^(id param, FATExtensionApiCallback callback) { + [[FATClient sharedClient] fat_registerWebApi:@"user_define_native" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) { NSString *inputText = @"鹅鹅鹅,曲项向天歌,白毛浮绿水,红掌拨清波。"; callback(FATExtensionCodeSuccess, @{@"text":inputText}); }]; // 注入获取用户信息 - [[FATClient sharedClient] registerExtensionApi:@"getUserProfile" handle:^(id param, FATExtensionApiCallback callback) { + [[FATClient sharedClient] registerExtensionApi:@"getUserProfile" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) { NSDictionary *userInfo = @{@"nickName":@"张三",@"avatarUrl":@"",@"gender":@1,@"country":@"中国",@"province":@"广东省",@"city":@"深圳",@"language":@"zh_CN"}; NSDictionary *resDic = @{@"userInfo":userInfo}; callback(FATExtensionCodeSuccess,resDic); }]; // 注入登录方法 - [[FATClient sharedClient] registerExtensionApi:@"login" handle:^(id param, FATExtensionApiCallback callback) { + [[FATClient sharedClient] registerExtensionApi:@"login" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) { // 处理小程序登录逻辑后,调用小程序回调 // 登录成功回调示例 - callback(FATExtensionCodeSuccess,@{@"desc":@"登录成功"}); + NSString *wxid = appletInfo.wechatLoginInfo[@"wechatOriginId"]; + NSString *path = appletInfo.wechatLoginInfo[@"profileUrl"]; + BOOL canWXLogin = [WXApi isWXAppInstalled] && [wxid length] > 0 && [path length] > 0; + if (canWXLogin) { + self.callback = callback; + WXLaunchMiniProgramReq *req = [WXLaunchMiniProgramReq object]; + req.userName = wxid; + req.path = path; + req.miniProgramType = WXMiniProgramTypeRelease; + [WXApi sendReq:req completion:^(BOOL success) { + NSLog(@"打开微信:%d", success); + }]; + } + else { + callback(FATExtensionCodeSuccess,@{@"desc":@"登录成功"}); + } }]; // 注入微信支付方法 __weak typeof(self) weakSelf = self; - [[FATClient sharedClient] registerExtensionApi:@"requestPayment" handle:^(id param, FATExtensionApiCallback callback) { + [[FATClient sharedClient] registerExtensionApi:@"requestPayment" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) { // 支付调用,调用结果通过回调通告小程序 [weakSelf getTestPayment:callback]; }]; @@ -133,28 +148,37 @@ static FINExtensionHelper *instance = nil; } -//支付结果回调 +//微信结果回调 - (void)onResp:(BaseResp *)resp { - if ([resp isKindOfClass:[PayResp class]]) { - PayResp *response = (PayResp*)resp; - //response.errCode -// WXSuccess = 0, /**< 成功 */ -// WXErrCodeCommon = -1, /**< 普通错误类型 */ -// WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */ -// WXErrCodeSentFail = -3, /**< 发送失败 */ -// WXErrCodeAuthDeny = -4, /**< 授权失败 */ -// WXErrCodeUnsupport = -5, /**< 微信不支持 */ - switch (response.errCode) { - case WXSuccess: - self.callback(FATExtensionCodeSuccess, nil); - break; - - default: - self.callback(FATExtensionCodeFailure, nil); - break; + FATExtensionCode code = FATExtensionCodeSuccess; + if (resp.errCode != WXSuccess) { + code = FATExtensionCodeFailure; + } + if ([resp isKindOfClass:[PayResp class]]) {//支付 + self.callback(code, nil); + } + else if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) {//打开小程序 + NSString *extMsg = ((WXLaunchMiniProgramResp *)resp).extMsg; + if (extMsg.length <= 0) { + self.callback(FATExtensionCodeFailure, nil); + } + else { + self.callback(code, [self dictionaryWithJsonString:extMsg]); + } } } +- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { + if (jsonString == nil) return nil; + NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; + NSError *err; + NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]; + if(err) { + NSLog(@"json解析失败:%@",err); + return nil; + } + return dic; +} @end diff --git a/demo/demo.entitlements b/demo/demo.entitlements new file mode 100644 index 0000000..1c0a022 --- /dev/null +++ b/demo/demo.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.developer.associated-domains + + applinks:www.finclip.com + + + diff --git a/demo/finosprite.plist b/demo/finosprite.plist index 1f9da87..2940202 100644 --- a/demo/finosprite.plist +++ b/demo/finosprite.plist @@ -4,7 +4,7 @@ appId - 611cf17739245f000182fa40 + 60d58080a2b11b0001c439a4 title 小程序微信登录&支付示例 startParams