tencent cloud

Feedback

Custom APIs

Last updated: 2024-11-21 18:41:53

    invokeNativePlugin

    The TCMPP Mini Program SDK offers interfaces that enable the implementation of certain Open Platform APIs, which can be directly transmitted to the host client, such as login and user information retrieval. Some host clients can be expanded to maintain UI and functionality consistency, such as scanning and sharing. Additionally, it is possible to extend custom APIs for direct transmission to the host client.

    Usage method at mini program end

    var opts = {
    api_name: '', // Name of the API
    success: function(res) {},
    fail: function(res) {},
    complete: function(res) {},
    data: { // Input Parameters
    name : 'kka',
    age : 22,
    data: {...}
    }
    }
    wx.invokeNativePlugin(opts); // Invocation

    Methods

    Method
    Description
    View onCreateLoadingView()
    Create a loading view, permitting the host client to render mini program/mini game brand and custom display styles. If returned as null, the default loading view will be exhibited.
    View onCreateCapsuleView()
    Establish a capsule button, allowing the host to customize the capsule button style. If returned as null, the default capsule button will be displayed.
    boolean onShowMenu()
    Triggered when the "..." more button is clicked. If onCreateCapsuleView returns null and onShowMenu returns false, the default menu will be displayed.
    void onExit()
    Activated when the "〇" exit button is clicked. If onCreateCapsuleView returns null and onExit returns false, the default operation will be executed.
    boolean onAuthorize(JSONObject params, Value Callback callback)
    Implementation of the wx.authorize interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onOpenSetting(JSONObject params, ValueCallback callback)
    Implementation of the wx.openSetting interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onGetSetting(JSONObject params, ValueCallback callback)
    Implementation of the wx.getSetting interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onLogin(JSONObject params, ValueCallback callback)
    Implementation of the wx.login interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onRefreshSession(JSONObject params, ValueCallback callback)
    Implementation of the wx.checkSession interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onRequestPayment(JSONObject params, ValueCallback callback)
    Implementation of the wx.requestPayment interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onGetUserInfo(JSONObject params, ValueCallback callback)
    Implementation of the wx.getUserInfo interface. If it returns false, the notification of wx api call failure will be directly sent. For more details, see onGetUserInfo.
    boolean onShareAppMessage(JSONObject params, ValueCallback callback)
    Implementation of the wx.shareAppMessage interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onNavigateToMiniProgram(JSONObject params, ValueCallback callback)
    Implementation of the wx.navigateToMiniProgram interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onScanCode(JSONObject params, ValueCallback callback)
    Implementation of the wx.scanCode interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onOpenDocument(JSONObject params, ValueCallback callback)
    Implementation of the wx.openDocument interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onOpenLocation(JSONObject params, ValueCallback callback)
    Implementation of the wx.openLocation interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onChooseLocation(JSONObject params, ValueCallback callback)
    Implementation of the wx.chooseLocation interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onPreviewImage(JSONObject params, ValueCallback callback)
    Implementation of the wx.rviewImage interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onChooseImage(JSONObject params, ValueCallback callback)
    Implementation of the wx.chooseImage interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onChooseVideo(JSONObject params, ValueCallback callback)
    Implementation of the wx.chooseVideo interface. If it returns false, the notification of wx api call failure will be directly sent.
    boolean onShowToast(JSONObject params, ValueCallback callback)
    Implementation of the wx.showToast and wx.showLoading interfaces. If it returns false, the default style will be displayed.
    boolean onHideToast(JSONObject params, ValueCallback callback)
    Implementation of the wx.hideToast and wx.hideLoading interfaces. If it returns false, the default style will be displayed.
    boolean onShowModal(JSONObject params, ValueCallback callback)
    Implementation of the wx.showModal interface. If it returns false, the default style will be displayed.
    boolean onInvokeWebAPI(String event, JSONObject params, ValueCallback callback)
    Implementation of the custom wx api. If it returns false, the notification of wx api call failure will be directly sent. For more details, see onInvokeWebAPI.
    boolean onReportEvent(String event, Map params)
    For more details, see onReportEvent.
    boolean onGetUserInfo(JSONObject params, ValueCallback callback)
    -(void)onGetUserInfoWithParams:(NSDictionary *)params inApp:(NSString *)appId callbackHandler:(WebAPICallbackHandler)handler {
    //TODO
    NSDictionary* userInfo = @{
    @"nickname" : @"morven",
    @"headimgurl" : @"https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKav1ib8qG43xy0resTpgfeCqH00vRpHicEdk0kKMxqTMMUG1WmBuAdgB2tmCf6joGVKlGbsicelhluw/0",
    @"sex" : @(1),
    @"province" : @"Guangdong",
    @"city" : @"Shenzhen",
    @"country" : @"China"
    };
    NSMutableDictionary* result = [NSMutableDictionary dictionaryWithCapacity:1];
    NSMutableDictionary* userInfoDic = [NSMutableDictionary dictionaryWithCapacity:6];
    NSMutableDictionary* resultDataDic = [NSMutableDictionary dictionaryWithCapacity:1];
    [userInfoDic setValue:userInfo[@"nickname"] forKey:@"nickName"];
    [userInfoDic setValue:userInfo[@"headimgurl"] forKey:@"avatarUrl"];
    [userInfoDic setValue:userInfo[@"sex"] forKey:@"gender"];
    [userInfoDic setValue:userInfo[@"province"] forKey:@"province"];
    [userInfoDic setValue:userInfo[@"city"] forKey:@"city"];
    [userInfoDic setValue:userInfo[@"country"] forKey:@"country"];
    
    NSData *data=[NSJSONSerialization dataWithJSONObject:userInfoDic options:NSJSONWritingPrettyPrinted error:nil];
    
    [resultDataDic setValue:[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding] forKey:@"data"];
    [result setValue:resultDataDic forKey:@"data"];
    [result setValue:@"getUserInfo:ok" forKey:@"errMsg"];
    
    if (handler) {
    //success
    handler(result, nil);
    }
    }
    boolean onInvokeWebAPI(String event, JSONObject params, ValueCallback callback)
    - (BOOL)onInvokeWebAPIWithEvent:(NSString*)event params:(NSDictionary*)params callbackHandler:(WebAPICallbackHandler _Nullable)handler {
    NSLog(@"onInvokeWebAPIWithEvent, event:%@, params:%@", event, params);
    if (handler) {
    handler(@{@"errMsg" : @"onInvokeWebAPIWithEvent"}, nil);
    }
    return YES;
    }
    boolean onReportEvent(String event, Map<String, String> params)
    Event reporting. The events are as follows:
    1. Launch the mini program, event: MS_EVENT_LAUNCH, keys for params: pagePath, d;
    2. Duration of mini program usage, event: MS_EVENT_USE_TIME, keys for params: useTime, startId, appId; the unit of useTime is milliseconds;
    3. Successful launch of the mini program, event: MS_EVENT_LAUNCH_SUCCESS, keys for params: appId.
    4. Opening a page within the mini program, event: MS_EVENT_OPEN_PAGE, keys for params: pagePath, appId.
    5. Failure to launch the mini program, event: MS_EVENT_LAUNCH_FAIL, keys for params: pagePath, reason, appId.
    
    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 avaliable.

    7x24 Phone Support