Merge branch 'master' into github-master

master
kangxuyao 2020-04-30 17:45:27 +08:00
commit a3a91c69bd
6 changed files with 279 additions and 5 deletions

263
README.md
View File

@ -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<MyApp> {
@override
void initState() {
super.initState();
init();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> 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: <Widget>[
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.
使sdkapisdksdk
```
///
///
/// 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<Map> 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<Map> 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<Map<String, dynamic>> 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<String, dynamic> appletInfo);
///
///
/// "userId"
/// "nickName"
/// "avatarUrl"
/// "jwt"
/// "accessToken"
///
Future<Map<String, dynamic>> getUserInfo();
///
Future<List<CustomMenu>> getCustomMenus(String appId);
///
Future onCustomMenuClick(String appId, int menuId);
}
```
7. api
SDK APIAPIAPI
···
///
/// register extension api
/// api
///
void registerExtensionApi(String name, ExtensionApiHandler handler)
···
iosFinChatConf.js
```
module.exports = {
extApi:[
{ //API
name: 'onCustomEvent', //api apiNative
params: { //api
url: ''
}
}
]
}
```

View File

@ -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.30'
}

View File

@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface MOPAppletDelegate : NSObject<FATAppletDelegate>
+ (instancetype)instance;
@end
NS_ASSUME_NONNULL_END

View File

@ -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);

View File

@ -15,8 +15,7 @@
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _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

View File

@ -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