Skip to content

API de vibração

1. Inicialize o applet

Antes de poder usar a API fornecida pelo SDK, você deve inicializar o SDK, a interface para inicializar o SDK é

dart
  ///
  ///
  /// initialize mop miniprogram engine.
  /// Initialize applet
  /// [sdkkey] is required. it can be getted from api.PhizClip.com
  /// [secret] is required. it can be getted from api.PhizClip.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] Whether to encrypt the server data, need server support
  /// [userId] user id
  /// [finStoreConfigs] Multiservice configuration
  /// [uiConfig] UI configuration
  /// [debug] Set debug mode to affect debugging and logging
  /// [customWebViewUserAgent] Set custom webview ua
  /// [appletIntervalUpdateLimit] Set applet batch update period
  /// [maxRunningApplet] Set the maximum number of running applets at the same time
  ///
  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,
  })

Exemplos de uso:

dart
final res = await Mop.instance.initialize(
          '22LyZEib0gLTQdU3MUauARlLry7JL/2fRpscC9kpGZQA', '1c11d7252c53e0b6',
          apiServer: 'https://api.PhizClip.com', apiPrefix: '/api/v1/mop');

2. Abra o applet

dart
  /// open the miniprogram [appId] from the  mop server.
  /// Abra o phizclip
  /// [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. Obtenha informações sobre o applet atualmente em uso

As informações atuais do applet incluem os campos appid, nome, ícone, design, versão, miniatura

dart
  ///
  ///  get current using applet
  ///  Get information about the applet currently in use
  ///  {appId,name,icon,description,version,thumbnail}
  ///
  ///
  Future<Map<String, dynamic>> currentApplet()

4. Feche os applets abrem de forma completa

dart
  ///
  /// close all running applets
  /// Close all currently open applets
  ///
  Future closeAllApplets()

5. Appleto de cache limpo

Limpe o cache do applet, quando aberto novamente, ele baixará o applet novamente

dart
  ///
  /// clear applets cache
  /// Clear cache applet
  ///
  Future clearApplets()

6. Registre o manuseio de eventos de applet

Quando um evevent especificado é acionado com o applet, o usuário será notificado, por exemplo, se o applet for encaminhado, o applet precisará fazer com que o usuário incusante e registre o processador para fazer a resposta correspondente

dart
 ///
  /// register handler to provide custom info or behaviour
  /// Register applet event handling
  ///
  void registerAppletHandler(AppletHandler handler)

Estrutura do processador

dart
abstract class AppletHandler {
  ///
  /// Forwarding applet
  ///
  ///
  ///
  void forwardApplet(Map<String, dynamic> appletInfo);

  ///
  ///Obtain user information
  ///   "userId" 
  ///   "nickName" 
  ///   "avatarUrl" 
  ///   "jwt" 
  ///   "accessToken" 
  ///
  Future<Map<String, dynamic>> getUserInfo();

  /// Get custom menu
  Future<List<CustomMenu>> getCustomMenus(String appId);

  ///Customized menu click handling
  Future onCustomMenuClick(String appId, int menuId);
}

7. API de extensão de registro

Se nossa API SDK Applet fizer, você poderá registrar uma API de applet personalizada e depois ligar para sua própria pousada, os Applets.

dart
///
/// register extension api
/// Register extension api
///
void registerExtensionApi(String name, ExtensionApiHandler handler) ···

iOS precisa criar o PhizClipConf.js arquivo na raiz do applet, com a configuração seguinte exmpler

bash
module.exports = {
  extApi:[
    { //General Interaction API
      name: 'onCustomEvent', //Extended api name The api must be implemented on the Native side
      params: { //Extended api parameter format, required field
        url: ''
      }
    }
  ]
}

Para obter informações de configuração de API mais personalizadas, consulte pz.loadExtApi

8. Registre a API de extensão da WebView

A API personalizada também pode ser usada no WebView dentro do applet, simplesmente usando o

dart
  ///
  /// register webview extension api
  /// Register webview extension api
  ///
  void addWebExtentionApi(String name, ExtensionApiHandler handler)

9. Chamadas nativas para os métodos JS no Webview

dart
  ///
  /// Native calls to js methods in webview
  /// [appId] Applet id
  /// [eventName] Method name
  /// [nativeViewId] webviewId
  /// [eventData] Parameters
  ///
  Future<void> callJS(String appId, String eventName, String nativeViewId,
      Map<String, dynamic> eventData)

10. Envie eventos para applets nativamente

dart
  ///
  /// Native send event to applet
  /// [appId] applet id
  /// [eventData] event object
  Future<void> sendCustomEvent(
      String appId, Map<String, dynamic> eventData)

11. Feche o applet

dart
  ///
  /// Close the applet The applet will exist in the memory
  ///
  Future<void> closeApplet(String appletId, bool animated)

12. Termine o applet

dart
  ///
  /// Ending the applet The applet will be cleared from memory
  ///
  Future<void> finishRunningApplet(String appletId, bool animated)

13. Defina a animação de comutação de applet

dart
  ///
  /// Set the phizclip to switch animation Android
  ///
  Future setActivityTransitionAnim(Anim anim)

14. Código QR para abrir o pequeno programa

dart
  ///
  /// Open the applet via QR code
  /// [qrcode] QR code content
  ///
  Future qrcodeOpenApplet(String qrcode)