diff --git a/android/build.gradle b/android/build.gradle index aa883af..321b774 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -91,6 +91,6 @@ kapt { } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.finogeeks.lib:finapplet:2.34.9' - implementation 'com.finogeeks.mop:plugins:2.34.9' + implementation 'com.finogeeks.lib:finapplet:2.35.0-alpha20211229v09' + implementation 'com.finogeeks.mop:plugins:2.35.0-alpha20211229v01' } \ No newline at end of file diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java index 15a7494..8345e46 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java @@ -5,6 +5,7 @@ import android.text.TextUtils; import android.util.Log; import com.finogeeks.lib.applet.client.FinAppClient; +import com.finogeeks.lib.applet.interfaces.FinCallback; import com.finogeeks.lib.applet.sdk.model.StartAppletDecryptRequest; import com.finogeeks.mop.api.BaseApi; import com.finogeeks.mop.interfaces.ICallback; @@ -28,7 +29,7 @@ public class AppletModule extends BaseApi { @Override public String[] apis() { - return new String[]{"openApplet", "scanOpenApplet"}; + return new String[]{"openApplet", "scanOpenApplet","qrcodeOpenApplet"}; } @Override @@ -37,6 +38,8 @@ public class AppletModule extends BaseApi { openApplet(param, callback); } else if ("scanOpenApplet".equals(event)) { scanOpenApplet(param, callback); + } else if ("qrcodeOpenApplet".equals(event)){ + qrcodeOpenApplet(param,callback); } } @@ -109,4 +112,28 @@ public class AppletModule extends BaseApi { FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, new StartAppletDecryptRequest(info)); callback.onSuccess(new HashMap()); } + + private void qrcodeOpenApplet(Map param, ICallback callback){ + String qrcode = String.valueOf(param.get("qrcode")); + FinAppClient.INSTANCE.getAppletApiManager().startAppletByQrcode(mContext, qrcode, new FinCallback() { + @Override + public void onSuccess(String s) { + callback.onSuccess(new HashMap()); + } + + @Override + public void onError(int i, String s) { + callback.onFail(new HashMap(){ + { + put("info",s); + } + }); + } + + @Override + public void onProgress(int i, String s) { + + } + }); + } } diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 438deb6..ec9321b 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mop","path":"/Users/beetle/Desktop/finogeeks/gitlab/finosprite/finclip-flutter-sdk/","dependencies":[]}],"android":[{"name":"mop","path":"/Users/beetle/Desktop/finogeeks/gitlab/finosprite/finclip-flutter-sdk/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"mop","dependencies":[]}],"date_created":"2021-11-15 23:44:20.482386","version":"2.2.2"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mop","path":"/Users/haley/Documents/Finogeeks/Gitlab/finclip-flutter-sdk/","dependencies":[]}],"android":[{"name":"mop","path":"/Users/haley/Documents/Finogeeks/Gitlab/finclip-flutter-sdk/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"mop","dependencies":[]}],"date_created":"2021-12-29 10:07:33.662750","version":"2.3.0-1.0.pre.169"} \ No newline at end of file diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a1..919434a 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/ios/Classes/Api/MOPAppletDelegate.m b/ios/Classes/Api/MOPAppletDelegate.m index d01d99a..4a210d9 100644 --- a/ios/Classes/Api/MOPAppletDelegate.m +++ b/ios/Classes/Api/MOPAppletDelegate.m @@ -9,6 +9,12 @@ #import "MopPlugin.h" #import "MopCustomMenuModel.h" +@interface NSString (FATEncode) +- (NSString *)fat_encodeString; + +@end + + @implementation MOPAppletDelegate + (instancetype)instance @@ -70,6 +76,9 @@ FATAppletMenuStyle style = [typeString isEqualToString:@"onMiniProgram"] ? FATAppletMenuStyleOnMiniProgram : FATAppletMenuStyleCommon; model.menuType = style; } + if ([@"Desktop" isEqualToString:model.menuId] && FATAppletVersionTypeRelease != appletInfo.appletVersionType) { + continue; + } [models addObject:model]; } @@ -87,6 +96,11 @@ [channel invokeMethod:@"extensionApi:onCustomMenuClick" arguments:arguments result:^(id _Nullable result) { }]; + + if ([@"Desktop" isEqualToString:customMenu.menuId]) { + [self addToDesktopItemClick:appletInfo path:path]; + } + } - (void)clickCustomItemMenuWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion { @@ -102,6 +116,12 @@ }]; } +- (void)clickCustomItemMenuWithInfo:(NSDictionary *)contentInfo inApplet:(FATAppletInfo *)appletInfo completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion { + if ([@"Desktop" isEqualToString:contentInfo[@"menuId"]]) { + [self addToDesktopItemClick:appletInfo path:contentInfo[@"path"]]; + } +} + - (void)applet:(NSString *)appletId didOpenCompletion:(NSError *)error { if (!appletId) { return; @@ -113,4 +133,34 @@ }]; } +static NSString *scheme = @"fatae55433be2f62915";//App对应的scheme + +- (void)addToDesktopItemClick:(FATAppletInfo *)appInfo path:(NSString *)path { + NSMutableString *herf = [NSString stringWithFormat:@"%@://applet/appid/%@?", scheme, appInfo.appId].mutableCopy; + NSString *query = [NSString stringWithFormat:@"apiServer=%@&path=%@",appInfo.apiServer, path]; + + if ([appInfo.startParams[@"query"] length]) { + query = [NSString stringWithFormat:@"%@&query=%@",query, appInfo.startParams[@"query"]]; + } + [herf appendString:query.fat_encodeString]; + + NSMutableString *url = [NSMutableString stringWithFormat:@"%@/mop/scattered-page/#/desktopicon", appInfo.apiServer]; + [url appendFormat:@"?iconpath=%@", appInfo.appAvatar]; + [url appendFormat:@"&apptitle=%@", appInfo.appTitle.fat_encodeString]; + [url appendFormat:@"&linkhref=%@", herf]; + + NSLog(@"跳转到中间页面:%@", url); + + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; +} + + +@end + +@implementation NSString (FATEncode) + +- (NSString *)fat_encodeString { + return (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)self, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); +} + @end diff --git a/ios/Classes/Api/MOP_qrcodeOpenApplet.h b/ios/Classes/Api/MOP_qrcodeOpenApplet.h new file mode 100644 index 0000000..f9fdbf0 --- /dev/null +++ b/ios/Classes/Api/MOP_qrcodeOpenApplet.h @@ -0,0 +1,18 @@ +// +// MOP_scanOpenApplet.h +// mop +// +// Created by beetle_92 on 2021/6/7. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_qrcodeOpenApplet : MOPBaseApi + +@property (nonatomic,copy) NSString *qrcode; + +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_qrcodeOpenApplet.m b/ios/Classes/Api/MOP_qrcodeOpenApplet.m new file mode 100644 index 0000000..527e5ea --- /dev/null +++ b/ios/Classes/Api/MOP_qrcodeOpenApplet.m @@ -0,0 +1,37 @@ +// +// MOP_scanOpenApplet.m +// mop +// +// Created by beetle_92 on 2021/6/7. +// + +#import "MOP_qrcodeOpenApplet.h" +#import "MOPTools.h" +#import + +@implementation MOP_qrcodeOpenApplet + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel { + NSLog(@"MOP_qrcodeOpenApplet:%@", self.qrcode); + FATAppletQrCodeRequest *qrcodeRequest = [[FATAppletQrCodeRequest alloc] init]; + qrcodeRequest.qrCode = self.qrcode; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + UIViewController *currentVC = [MOPTools topViewController]; + [[FATClient sharedClient] startAppletWithQrCodeRequest:qrcodeRequest inParentViewController:currentVC requestBlock:^(BOOL result, FATError *error) { + NSLog(@"请求完成:%@", error); + } completion:^(BOOL result, FATError *error) { + NSLog(@"打开完成:%@", error); + if (result){ + success(@{}); + } else { + failure(error.description); + } + } closeCompletion:^{ + NSLog(@"关闭"); + }]; + }); + +} + +@end diff --git a/ios/Classes/MopPlugin.m b/ios/Classes/MopPlugin.m index 3f51f4e..efa087b 100644 --- a/ios/Classes/MopPlugin.m +++ b/ios/Classes/MopPlugin.m @@ -88,6 +88,11 @@ static MopPlugin *_instance; - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { + if (![FATClient sharedClient].inited) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[FATClient sharedClient] handleOpenURL:url]; + }); + } return [[FATClient sharedClient] handleOpenURL:url]; } diff --git a/lib/mop.dart b/lib/mop.dart index 8c08066..2dd8e92 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -178,6 +178,11 @@ class Mop { return await _channel.invokeMapMethod("scanOpenApplet", params); } + Future qrcodeOpenApplet(String qrcode) async { + Map params = {'qrcode': qrcode}; + return await _channel.invokeMapMethod("qrcodeOpenApplet", params); + } + /// /// 根据微信QrCode信息解析小程序信息 /// diff --git a/pubspec.yaml b/pubspec.yaml index b4614b0..5b1e732 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mop description: A Finogeeks MiniProgram Flutter SDK. -version: '2.34.9' +version: '2.34.12' homepage: https://github.com/finogeeks/mop-flutter-sdk environment: