tencent cloud

All product documents
Tencent Cloud Super App as a Service
Customizing Mini Program APIs
Last updated: 2024-09-10 18:52:52
Customizing Mini Program APIs
Last updated: 2024-09-10 18:52:52
If a mini program needs capabilities from the host app 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 host application.
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)
Sample code:
final _tcmppFlutterPlugin = TcmppFlutter();

...

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

...

/// The custom APIs must be registered prior to mini program startup
_tcmppFlutterPlugin.registerMiniAppApi("myApiName",myApiHandler);
}
The mini program uses wx.invokeNativePlugin with api_name to call the Flutter-registered myApiName.
Sample code:
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 API
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"};
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support