From b860cb8a93b24937c48b98a3c238a93cb6ac27fc Mon Sep 17 00:00:00 2001 From: kangxuyao Date: Mon, 27 Apr 2020 18:55:36 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Classes/Api/MOPAppletDelegate.h | 2 ++ ios/Classes/Api/MOPAppletDelegate.m | 12 +++++++++++- ios/Classes/Api/MOP_registerAppletHandler.m | 3 +-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ios/Classes/Api/MOPAppletDelegate.h b/ios/Classes/Api/MOPAppletDelegate.h index c44aa0c..0fab813 100644 --- a/ios/Classes/Api/MOPAppletDelegate.h +++ b/ios/Classes/Api/MOPAppletDelegate.h @@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN @interface MOPAppletDelegate : NSObject ++ (instancetype)instance; + @end NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOPAppletDelegate.m b/ios/Classes/Api/MOPAppletDelegate.m index 9f00dfd..614dbd7 100644 --- a/ios/Classes/Api/MOPAppletDelegate.m +++ b/ios/Classes/Api/MOPAppletDelegate.m @@ -10,11 +10,21 @@ @implementation MOPAppletDelegate ++ (instancetype)instance +{ + static MOPAppletDelegate *_instance; + static dispatch_once_t once; + dispatch_once(&once, ^{ + _instance = [[self alloc] init]; + }); + return _instance; +} + - (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion { NSLog(@"forwardAppletWithInfo:%@",contentInfo); FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel]; - [channel invokeMethod:@"extensionApi:forwardApplet" arguments:contentInfo result:^(id _Nullable result) { + [channel invokeMethod:@"extensionApi:forwardApplet" arguments:@{@"appletInfo":contentInfo} result:^(id _Nullable result) { if([result isKindOfClass:[FlutterError class]]|| [result isKindOfClass:[FlutterMethodNotImplemented class] ]) { completion(FATExtensionCodeFailure,nil); diff --git a/ios/Classes/Api/MOP_registerAppletHandler.m b/ios/Classes/Api/MOP_registerAppletHandler.m index 2fb6f63..a1a0b63 100644 --- a/ios/Classes/Api/MOP_registerAppletHandler.m +++ b/ios/Classes/Api/MOP_registerAppletHandler.m @@ -15,8 +15,7 @@ - (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel { NSLog(@"MOP_registerAppletHandler"); - [[FATClient sharedClient] setDelegate:[[MOPAppletDelegate alloc] init]]; - + [FATClient sharedClient].delegate = [MOPAppletDelegate instance]; } @end From baeada287915faef5c4ea6af79ea17066f04d021 Mon Sep 17 00:00:00 2001 From: kangxuyao Date: Tue, 28 Apr 2020 12:09:53 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 00da670..801c254 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.1.17' + implementation 'com.finogeeks.lib:finapplet:2.1.28' } From 92fd58b6348b2ac14de0782ecb9fe48f25ef16fa Mon Sep 17 00:00:00 2001 From: kangxuyao Date: Tue, 28 Apr 2020 17:30:07 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/mop.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/mop.podspec b/ios/mop.podspec index 005a141..4f91f80 100644 --- a/ios/mop.podspec +++ b/ios/mop.podspec @@ -17,6 +17,6 @@ A new flutter plugin project. s.dependency 'Flutter' s.ios.deployment_target = '8.0' - s.dependency 'FinApplet', '2.1.14' + s.dependency 'FinApplet', '2.1.13' end From 006e95358362d39d1156115c41947d8a03371c93 Mon Sep 17 00:00:00 2001 From: kangxuyao Date: Wed, 29 Apr 2020 17:00:33 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) diff --git a/README.md b/README.md index ce70fd9..af815d2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,266 @@ # 凡泰极客小程序 Flutter 插件 本插件提供在 Flutter 运行环境中运行小程序能力。 + +## 集成 + +在项目pubspec.yaml文件中添加依赖 + +``` +mop: latest.version +``` + +## 示例 + +``` +import 'package:flutter/material.dart'; +import 'dart:async'; +import 'dart:io'; +import 'package:mop/mop.dart'; + +void main() => runApp(MyApp()); + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + @override + void initState() { + super.initState(); + init(); + } + + // Platform messages are asynchronous, so we initialize in an async method. + Future init() async { + if (Platform.isIOS) { + //com.finogeeks.mopExample + final res = await Mop.instance.initialize( + '22LyZEib0gLTQdU3MUauARlLry7JL/2fRpscC9kpGZQA', '1c11d7252c53e0b6', + apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/mop'); + print(res); + } else if (Platform.isAndroid) { + //com.finogeeks.mopexample + final res = await Mop.instance.initialize( + '22LyZEib0gLTQdU3MUauARjmmp6QmYgjGb3uHueys1oA', '98c49f97a031b555', + apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/mop'); + print(res); + } + if (!mounted) return; + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('凡泰极客小程序 Flutter 插件'), + ), + body: Center( + child: Container( + padding: EdgeInsets.only( + top: 20, + ), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(5)), + gradient: LinearGradient( + colors: const [Color(0xFF12767e), Color(0xFF0dabb8)], + stops: const [0.0, 1.0], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + ), + ), + child: FlatButton( + onPressed: () { + Mop.instance.openApplet('5e3c147a188211000141e9b1'); + }, + child: Text( + '打开示例小程序', + style: TextStyle(color: Colors.white), + ), + ), + ), + SizedBox(height: 30), + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(5)), + gradient: LinearGradient( + colors: const [Color(0xFF12767e), Color(0xFF0dabb8)], + stops: const [0.0, 1.0], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + ), + ), + child: FlatButton( + onPressed: () { + Mop.instance.openApplet('5e4d123647edd60001055df1',sequence: 1); + }, + child: Text( + '打开官方小程序', + style: TextStyle(color: Colors.white), + ), + ), + ), + ], + ), + ), + ), + ), + ); + } +} +``` + +## 接口文档 + +1. 初始化小程序 + +在使用sdk提供的api之前必须要初始化sdk,初始化sdk的接口为 + +``` + + /// + /// + /// initialize mop miniprogram engine. + /// 初始化小程序 + /// [appkey] is required. it can be getted from mp.finogeeks.com + /// [secret] is required. it can be getted from mp.finogeeks.com + /// [apiServer] is optional. the mop server address. default is https://mp.finogeek.com + /// [apiPrefix] is optional. the mop server prefix. default is /api/v1/mop + /// + /// + Future initialize(String appkey, String secret, + {String apiServer, String apiPrefix}) +``` + +使用示例: + +``` +final res = await Mop.instance.initialize( + '22LyZEib0gLTQdU3MUauARlLry7JL/2fRpscC9kpGZQA', '1c11d7252c53e0b6', + apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/mop'); +``` + +2. 打开小程序 + +``` + /// + /// + /// open the miniprogram [appId] from the mop server. + /// 打开小程序 + /// [appId] is required. + /// [path] is miniprogram open path. example /pages/index/index + /// [query] is miniprogram query parameters. example key1=value1&key2=value2 + /// + /// + Future openApplet(final String appId, + {final String path, final String query, final int sequence}) +``` + +3. 获取当前正在使用的小程序信息 + +当前小程序信息包括的字段有appId,name,icon,description,version,thumbnail + +``` + /// + /// get current using applet + /// 获取当前正在使用的小程序信息 + /// {appId,name,icon,description,version,thumbnail} + /// + /// + Future> currentApplet() +``` + +4. 关闭当前打开的所有小程序 + +``` + /// + /// close all running applets + /// 关闭当前打开的所有小程序 + /// + Future closeAllApplets() +``` + +5. 清除缓存的小程序 + +清除缓存的小程序,当再次打开时,会重新下载小程序 + +``` + /// + /// clear applets cache + /// 清除缓存的小程序 + /// + Future clearApplets() +``` + +6. 注册小程序事件处理 + +当小程序内触发指定事件时,会通知到使用者,比如小程序被转发,小程序需要获取用户信息,注册处理器来做出对应的响应 + +``` + /// + /// register handler to provide custom info or behaviour + /// 注册小程序事件处理 + /// + void registerAppletHandler(AppletHandler handler) +``` + +处理器的结构 + +``` +abstract class AppletHandler { + /// + /// 转发小程序 + /// + /// + /// + void forwardApplet(Map appletInfo); + + /// + ///获取用户信息 + /// "userId" + /// "nickName" + /// "avatarUrl" + /// "jwt" + /// "accessToken" + /// + Future> getUserInfo(); + + /// 获取自定义菜单 + Future> getCustomMenus(String appId); + + ///自定义菜单点击处理 + Future onCustomMenuClick(String appId, int menuId); +} +``` + +7. 注册拓展api + +如果,我们的小程序SDK API不满足您的需求,您可以注册自定义的小程序API,然后就可以在小程序内调用自已定义的API了。 + +··· + /// + /// register extension api + /// 注册拓展api + /// + void registerExtensionApi(String name, ExtensionApiHandler handler) +··· + +ios需要在小程序根目录创建FinChatConf.js文件,配置实例如下 + +``` +module.exports = { + extApi:[ + { //普通交互API + name: 'onCustomEvent', //扩展api名 该api必须Native方实现了 + params: { //扩展api 的参数格式,可以只列必须的属性 + url: '' + } + } + ] +} +``` \ No newline at end of file From e6633343cdd46cab9bf70f459494278bb097024a Mon Sep 17 00:00:00 2001 From: kangxuyao Date: Thu, 30 Apr 2020 16:58:46 +0800 Subject: [PATCH 5/5] version --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 801c254..bc1a9d2 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.1.28' + implementation 'com.finogeeks.lib:finapplet:2.1.30' }