tencent cloud

Tencent Cloud Super App as a Service

DocumentaçãoTencent Cloud Super App as a Service

Customizing Mini Program APIs

Baixar
Modo Foco
Tamanho da Fonte
Última atualização: 2026-01-29 00:28:08
If a mini program needs capabilities from the superapp that the SDK doesn't support, developers can register custom APIs to enable these capabilities. This allows the mini program to call custom APIs provided by the superapp.
Define a custom mini program API and associate it with an API handler. apiName: The name of the custom API. The mini program can use this API by calling wx.invokeNativePlugin().
apiHandler: The function that handles the API calls.
void registerMiniAppApi(String apiName, TcmppMiniAppApiHandler apiHandler)
Example:
final _tcmppFlutterPlugin = TcmppFlutter();

...

@override
void initState() {
super.initState();

...

/// Must register before the mini program starts up
_tcmppFlutterPlugin.registerMiniAppApi("myApiName",myApiHandler);
}
The mini program calls the Flutter-registered myApiName by passing api_name via wx.invokeNativePlugin.
Mini program calling example:
example code:
/// Mini Program Call
var opts = {
api_name: 'myApiName',
success: function(res) {
log(res);
},
fail: function(res) {
log(res);
},
complete: function(res) {
log(res);
},
data: {
name : 'kka',
age : 22
}
}
wx.invokeNativePlugin(opts);
Implement the myApiHandler function on the Flutter side:
/// Client APIs
Future<Map<String, dynamic>?> myApiHandler(MiniApiCall call) async {
print("API : ${call.apiName}");
print("AppInfo: ${call.appInfo}");
print("WebView ID: ${call.webViewId}");
print("params: ${call.params}");

return {"result": "success","method":"myApiHandler"};
}
MiniApiCall
params parameter description
Note:
Version 2.2.16 and earlier
Android and iOS callback parameters were inconsistent.
Android example params:
{param1: test, param2: 189}
iOS example params:
{stateEvent: requestCustomApi, api_name: customApi, data: {param1: test, param2: 189}, webviewId: 4}

Version 2.2.17 and later
The params format is unified across Android and iOS as follows:
{stateEvent: requestCustomApi, api_name: customApi, data: {param1: test, param2: 189}, webviewId: 4}
class MiniApiCall {
/// Mini program information
AppInfo? appInfo;
/// The current custom API name
String apiName;
/// The WebView page ID
int webViewId;
/// Request parameter information. Example: {stateEvent: requestCustomApi, api_name: customApi, data: {param1: test, param2: 189}, webviewId: 4}
Map<String, dynamic>? params;
}



Ajuda e Suporte

Esta página foi útil?

comentários