-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathREADME.md
436 lines (375 loc) · 15.1 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<p align="center">
<a href="https://www.finclip.com?from=github">
<img width="auto" src="https://www.finclip.com/mop/document/images/logo.png">
</a>
</p>
<p align="center">
<strong>FinClip Flutter DEMO</strong></br>
<p>
<p align="center">
本项目提供在 Flutter 环境中运行小程序的示例 DEMO
<p>
<p align="center">
👉 <a href="https://www.finclip.com?from=github">https://www.finclip.com/</a> 👈
</p>
<div align="center">
<a href="#"><img src="https://img.shields.io/badge/%E4%B8%93%E5%B1%9E%E5%BC%80%E5%8F%91%E8%80%85-20000%2B-brightgreen"></a>
<a href="#"><img src="https://img.shields.io/badge/%E5%B7%B2%E4%B8%8A%E6%9E%B6%E5%B0%8F%E7%A8%8B%E5%BA%8F-6000%2B-blue"></a>
<a href="#"><img src="https://img.shields.io/badge/%E5%B7%B2%E9%9B%86%E6%88%90%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BA%94%E7%94%A8-75%2B-yellow"></a>
<a href="#"><img src="https://img.shields.io/badge/%E5%AE%9E%E9%99%85%E8%A6%86%E7%9B%96%E7%94%A8%E6%88%B7-2500%20%E4%B8%87%2B-orange"></a>
<a href="https://www.zhihu.com/org/finchat"><img src="https://img.shields.io/badge/FinClip--lightgrey?logo=zhihu&style=social"></a>
<a href="https://www.finclip.com/blog/"><img src="https://img.shields.io/badge/FinClip%20Blog--lightgrey?logo=ghost&style=social"></a>
</div>
<p align="center">
<div align="center">
[官方网站](https://www.finclip.com/) | [示例小程序](https://www.finclip.com/#/market) | [开发文档](https://www.finclip.com/mop/document/) | [部署指南](https://www.finclip.com/mop/document/introduce/quickStart/cloud-server-deployment-guide.html) | [SDK 集成指南](https://www.finclip.com/mop/document/introduce/quickStart/intergration-guide.html) | [API 列表](https://www.finclip.com/mop/document/develop/api/overview.html) | [组件列表](https://www.finclip.com/mop/document/develop/component/overview.html) | [隐私承诺](https://www.finclip.com/mop/document/operate/safety.html)
</div>
-----
## 🤔 FinClip 是什么?
有没有**想过**,开发好的微信小程序能放在自己的 APP 里直接运行,只需要开发一次小程序,就能在不同的应用中打开它,是不是很不可思议?
有没有**试过**,在自己的 APP 中引入一个 SDK ,应用中不仅可以打开小程序,还能自定义小程序接口,修改小程序样式,是不是觉得更不可思议?
这就是 FinClip ,就是有这么多不可思议!
## ⚙️ Flutter 集成
在项目 `pubspec.yaml` 文件中添加依赖
```yaml
mop: latest.version
```
## 🖥 示例
```flutter
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://api.finclip.com', apiPrefix: '/api/v1/mop');
print(res);
} else if (Platform.isAndroid) {
//com.finogeeks.mopexample
final res = await Mop.instance.initialize(
'22LyZEib0gLTQdU3MUauARjmmp6QmYgjGb3uHueys1oA', '98c49f97a031b555',
apiServer: 'https://api.finclip.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),
),
),
),
],
),
),
),
),
);
}
}
```
## 📘 目录结构
```
.
├── LICENSE
├── README.md
├── android 安卓工程目录
│ ├── app
│ │ ├── build.gradle 应用构建配置
│ │ └── src
│ │ ├── debug
│ │ │ └── AndroidManifest.xml 应用清单文件
│ │ ├── main 应用源码主目录
│ │ │ ├── AndroidManifest.xml 应用清单文件
│ │ │ ├── java 应用源码目录
│ │ │ │ ├── com
│ │ │ │ │ └── finogeeks
│ │ │ │ │ └── mop_demo
│ │ │ │ │ └── MainActivity.java
│ │ │ │ └── io
│ │ │ │ └── flutter
│ │ │ │ └── plugins
│ │ │ │ └── GeneratedPluginRegistrant.java
│ │ │ └── res 资源文件目录
│ │ │ ├── drawable darwable资源目录
│ │ │ │ └── launch_background.xml
│ │ │ ├── mipmap-hdpi 图片资源目录
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi 图片资源目录
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi 图片资源目录
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi 图片资源目录
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi 图片资源目录
│ │ │ │ └── ic_launcher.png
│ │ │ └── values
│ │ │ └── styles.xml
│ │ └── profile
│ │ └── AndroidManifest.xml
│ ├── build.gradle
│ ├── gradle gradle版本配置目录,一般情况下无需关注
│ │ └── wrapper
│ │ └── gradle-wrapper.properties
│ ├── gradle.properties
│ ├── local.properties
│ └── settings.gradle
├── build
├── doc
│ └── mop_flutter_demo.gif
├── ios iOS工程目录
│ ├── Flutter Flutter-SDK目录,一般无需关注
│ │ ├── AppFrameworkInfo.plist
│ │ ├── Debug.xcconfig
│ │ ├── Flutter.framework
│ │ ├── Flutter.podspec
│ │ ├── Generated.xcconfig
│ │ ├── Release.xcconfig
│ │ └── flutter_export_environment.sh
│ ├── Podfile pod依赖配置文件
│ ├── Runner iOS源码主目录
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Assets.xcassets 图片资源
│ │ │ ├── AppIcon.appiconset 图标
│ │ │ └── LaunchImage.imageset 启动图
│ │ ├── Base.lproj
│ │ │ ├── LaunchScreen.storyboard
│ │ │ └── Main.storyboard
│ │ ├── FATFlutterViewController.h Flutter页面控制器子类
│ │ ├── FATFlutterViewController.m Flutter页面控制器子类
│ │ ├── GeneratedPluginRegistrant.h
│ │ ├── GeneratedPluginRegistrant.m
│ │ ├── Info.plist iOS工程配置文件
│ │ └── main.m
│ └── Runner.xcodeproj
├── lib Flutter源码主目录
│ ├── main.dart 首页
│ └── wx_pay.dart 微信支付源码
├── pubspec.lock
├── pubspec.yaml Flutter配置文件
└── test
└── widget_test.dart
```
## 📋 接口文档
### 1. 初始化小程序
在使用 SDK 提供的 API 之前必须要初始化 SDK ,初始化 SDK 的接口如下
```
///
/// initialize mop miniprogram engine.
/// 初始化小程序
/// [appkey] is required. it can be getted from api.finclip.com
/// [secret] is required. it can be getted from api.finclip.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://api.finclip.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 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: ''
}
}
]
}
```
## 📘 目录结构
```
.
├─.github
│
├─.vscode
│
├─android 工程Android源码
│
├─ios 工程iOS源码
│
├─lib 工程Flutter源码
│ │
│ ├─ main.dart 程序入口,以及各初始化、调用示例
│ │
│ └─ wx_pay.dart 微信支付类示例
│
├─test 测试目录,无需关注
│
└─pubspec.yaml Flutter工程配置项
```
## 🔗 常用链接
以下内容是您在 FinClip 进行开发与体验时,常见的问题与指引信息
- [FinClip 官网](https://www.finclip.com/#/home)
- [示例小程序](https://www.finclip.com/#/market)
- [文档中心](https://www.finclip.com/mop/document/)
- [SDK 部署指南](https://www.finclip.com/mop/document/introduce/quickStart/intergration-guide.html)
- [小程序代码结构](https://www.finclip.com/mop/document/develop/guide/structure.html)
- [iOS 集成指引](https://www.finclip.com/mop/document/runtime-sdk/ios/ios-integrate.html)
- [Android 集成指引](https://www.finclip.com/mop/document/runtime-sdk/android/android-integrate.html)
- [Flutter 集成指引](https://www.finclip.com/mop/document/runtime-sdk/flutter/flutter-integrate.html)
## ☎️ 联系我们
微信扫描下面二维码,关注官方公众号 **「凡泰极客」**,获取更多精彩内容。<br>
<img width="150px" src="https://www.finclip.com/mop/document/images/ic_qr.svg">
微信扫描下面二维码,加入官方微信交流群,获取更多精彩内容。<br>
<img width="150px" src="https://www-cdn.finclip.com/images/qrcode/qrcode_shequn_text.png">
## Stargazers
[![Stargazers repo roster for @finogeeks/finclip-flutter-demo](https://reporoster.com/stars/finogeeks/finclip-flutter-demo)](https://github.com/finogeeks/finclip-flutter-demo/stargazers)
## Forkers
[![Forkers repo roster for @finogeeks/finclip-flutter-demo](https://reporoster.com/forks/finogeeks/finclip-flutter-demo)](https://github.com/finogeeks/finclip-flutter-demo/network/members)