tencent cloud

Open APIs
Last updated: 2025-12-05 22:26:28
Open APIs
Last updated: 2025-12-05 22:26:28
The mini program SDK provides some open APIs for implementing features that are provided by superapps, such as login, user information retrieval, and payment.
Note:
The open APIs currently provide three implementation solutions:
v1: Fully customized by the superapp, and all open APIs must be implemented by superapp developers.
v2: Starting from SDK version 2.1.0, the SDK provides default implementations for login (wx.login), user information (wx.getPhoneNumber, wx.getEmail, wx.chooseAvatar, wx.getNickName), and session checks (wx.checkSession). Users can easily configure these to link the mini program user login with superapp user information.

API description

Mini program method
TMFMiniAppSDKDelegate implementation method
Description
Default implementation
wx.login
login
Login API SDK
The default implementation (v2) is available starting from version 2.1.0.
wx.getPhoneNumber
getPhoneNumber
Retrieves the phone number
The default implementation (v2) is available starting from version 2.1.0.
wx.getEmail
getEmail
Retrieves the user email
The default implementation (v2) is available starting from version 2.1.0.
wx.checkSession
checkSession
Checks if the login session has expired
The default implementation (v2) is available starting from version 2.1.0.
wx.chooseAvatar
chooseAvatar
Retrieves the user profile photo
The default implementation (v2) is available starting from version 2.1.0.
wx.getNickName
getNickName
Retrieves the user nickname
The default implementation (v2) is available starting from version 2.1.0.
wx.getUserInfo
getUserInfo
Retrieves the basic user information
No default implementation
wx.getUserProfile
getUserProfile
Retrieves the user profile information
No default implementation
wx.requestPayment
requestPayment
Initiates a payment
No default implementation
wx.requestMidasPaymentGameItem
requestMidasPaymentGameItem
Mini game payment
No default implementation
wx.requestVirtualPayment
requestVirtualPayment
Virtual payment in mini programs
No default implementation

Related APIs in the delegate class

// Initiates a payment
// @param app Mini program/mini game instance
// @param params Parameters
// @param completionHandler Callback with result
- (void)requestPayment:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// Initiate a payment for a direct virtual item purchase
// @param app Mini game instance
// @param params Parameters
// @param completionHandler Callback with result
- (void)requestMidasPaymentGameItem:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// Initiate virtual payment for mini props
// @param app Mini program/mini game instance
// @param params Parameters
// @param completionHandler Callback with result
- (void)requestVirtualPayment:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

Login
// @param app Mini program/mini game instance
// @param params Parameters
// @param completionHandler Callback with result
- (void)login:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// checkSession
// @param app Mini program/mini game instance
// @param params Parameters
// @param completionHandler Callback with result
- (void)checkSession:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// getUserProfile
// @param app Mini program/mini game instance
// @param params Parameters
// @param completionHandler Callback with result
- (void)getUserProfile:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;


// getPhoneNumber
// @param app Mini program/mini game instance
// @param params Parameters
// @param completionHandler Callback with result
- (void)getPhoneNumber:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// getUserInfo
// @param app Mini program/mini game instance
// @param params Parameters
// @param completionHandler Callback with result
- (void)getUserInfo:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// OpenAPI version
// @param app Mini program/mini game instance
// @reutn v1/v2
- (NSString *)openApiVersion:(TMFMiniAppInfo *)app;

Implementation description

Superapp developers can implement the open API logic by overriding the proxy implementation of MiniOpenApiProxy.

Implementation description for v1

All APIs in v1 must be implemented by superapp developers.

Example


- (void)getUserInfo:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler {
if (completionHandler) {
completionHandler();
@"nickName": [DemoUserInfo sharedInstance].nickName,
@"avatarUrl": [DemoUserInfo sharedInstance].avatarUrl,
@"gender": [NSNumber numberWithUnsignedInt:[DemoUserInfo sharedInstance].gender],
@"country": [DemoUserInfo sharedInstance].country,
@"province": [DemoUserInfo sharedInstance].province,
@"city": [DemoUserInfo sharedInstance].city,
@"language": 'zh-cn':{
(nil)
}
}

- (void)getUserProfile:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler {
if (completionHandler) {
completionHandler();
@"nickName": [DemoUserInfo sharedInstance].nickName,
@"avatarUrl": [DemoUserInfo sharedInstance].avatarUrl,
@"gender": [NSNumber numberWithUnsignedInt:[DemoUserInfo sharedInstance].gender],
@"country": [DemoUserInfo sharedInstance].country,
@"province": [DemoUserInfo sharedInstance].province,
@"city": [DemoUserInfo sharedInstance].city,
@"language": 'zh-cn':{
(nil)
}
}

Implementation description for v2

After logging into the superapp, the obtained UID (the current user account identifier in the superapp) must be returned to the SDK engine via the delegate API. For example, if the UID is stored in [DemoUserInfo sharedInstance].userId after login, the delegate method can be implemented as follows:
- (NSString *)getAppUID {
return [DemoUserInfo sharedInstance].userId;
}

Compatibility of custom login logic

Starting with SDK version 2.2.10, the SDK interface can be implemented with v1 by superapp via interface configuration on top of the v2 default implementation.
// OpenAPI version
// @param app Mini program/mini game instance
// @reutn v1/v2
- (NSString *)openApiVersion:(TMFMiniAppInfo *)app;
Note:
Mini program developers can use the apiVersion field in app.json to control versions for APIs that are implemented by default in SDK versions later than 2.1.0. When this field is not set, the version follows the value returned by the delegate API's openApiVersion method. Once configured, the API version matches the configured one. In other words,
The apiVersion configuration has higher priority than the value returned by the openApiVersion delegate method.
(For example, if apiVersion is set to v2, all APIs will use the v2 implementation exclusively. Version mixing is not supported; even if openApiVersion returns a different value, the SDK will use the v2 implementation.)

Example:

- (NSString *)openApiVersion:(TMFMiniAppInfo *)app {
// This superapp uses the v2 version of the openAPI
return @"v2";
}
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback