FinClip为企业提供小程序生态圈技术产品,开发者可在FinClip小程序开发帮助中心找到相关FinClip小程序指引

# Flutter API

# 1. 初始化小程序

在使用sdk提供的api之前必须要初始化sdk,初始化sdk的接口为

  ///
  ///
  /// initialize mop miniprogram engine.
  /// 初始化小程序
  /// [sdkkey] 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
  /// [cryptType] is optional. cryptType, should be MD5/SM
  /// [disablePermission] is optional.
  /// [encryptServerData] 是否对服务器数据进行加密,需要服务器支持
  /// [userId] 用户id
  /// [finStoreConfigs] 多服务配置
  /// [uiConfig] UI配置
  /// [debug] 设置debug模式,影响调试和日志
  /// [customWebViewUserAgent] 设置自定义webview ua
  /// [appletIntervalUpdateLimit] 设置小程序批量更新周期
  /// [maxRunningApplet] 设置最大同时运行小程序个数
  ///
  Future<Map> initialize(
    String sdkkey,
    String secret, {
    String? apiServer,
    String? apiPrefix,
    String? cryptType,
    bool encryptServerData = false,
    bool disablePermission = false,
    String? userId,
    bool debug = false,
    bool bindAppletWithMainProcess = false,
    List<FinStoreConfig>? finStoreConfigs,
    UIConfig? uiConfig,
    String? customWebViewUserAgent,
    int? appletIntervalUpdateLimit,
    int? maxRunningApplet,
  }) 

使用示例:

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
  /// [sequence] is miniprogram sequence. example 0,1.2.3,4,5...
  /// [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
  /// [fingerprint] is optional. the mop sdk fingerprint. is nullable
  /// [cryptType] is optional. cryptType, should be MD5/SM
  Future<Map> openApplet(
    final String appId, {
    final String? path,
    final String? query,
    final int? sequence,
    final String? apiServer,
    final String? scene,
  }) 

# 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需要在小程序根目录创建 FinClipConf.js 文件,配置实例如下

module.exports = {
  extApi:[
    { //普通交互API
      name: 'onCustomEvent', //扩展api名 该api必须Native方实现了
      params: { //扩展api 的参数格式,必填项
        url: ''
      }
    }
  ]
}

小程序端更多自定义 API 配置信息可参考 ft.loadExtApi

# 8. 注册webview扩展api

自定义的api同样可以在小程序内的webview中使用,只需要通过

  ///
  /// register webview extension api
  /// 注册webview拓展api
  ///
  void addWebExtentionApi(String name, ExtensionApiHandler handler) 

# 9. 原生调用webview中的js方法

  ///
  /// 原生调用webview中的js方法
  /// [appId] 小程序id
  /// [eventName] 方法名
  /// [nativeViewId] webviewId
  /// [eventData] 参数
  ///
  Future<void> callJS(String appId, String eventName, String nativeViewId,
      Map<String, dynamic> eventData)

# 10. 原生发送事件给小程序

  ///
  /// 原生发送事件给小程序
  /// [appId] 小程序id
  /// [eventData] 事件对象
  Future<void> sendCustomEvent(
      String appId, Map<String, dynamic> eventData)

# 11. 关闭小程序

  /// 
  /// 关闭小程序 小程序会在内存中存在
  /// 
  Future<void> closeApplet(String appletId, bool animated)

# 12. 结束小程序

  ///
  /// 结束小程序 小程序会从内存中清除
  ///
  Future<void> finishRunningApplet(String appletId, bool animated)

# 13. 设置小程序切换动画

  ///
  /// 设置小程序切换动画 安卓
  ///
  Future setActivityTransitionAnim(Anim anim)

# 14. 二维码打开小程序

  ///
  /// 通过二维码打开小程序
  /// [qrcode] 二维码内容
  /// 
  Future qrcodeOpenApplet(String qrcode)
© 2022 FinClip with ❤