tencent cloud

All product documents
Tencent Cloud Super App as a Service
Open APIs
Last updated: 2025-01-09 15:27:43
Open APIs
Last updated: 2025-01-09 15:27:43
The mini program SDK provides some open APIs for implementing features that are provided by host apps, such as login, user information retrieval, and payment.
Note:
Starting from version 2.1.0, the SDK APIs come with default implementations for login (wx.login), user information (wx.getPhoneNumber, wx.getEmail, wx.chooseAvatar, wx.getNickName), and session status checks (wx.checkSession). This allows developers to easily configure and integrate user login and host application user information logic for mini programs.
The default implementation starting from version 2.1.0 is only supported on SaaS.

SDK version 2.1.0 and later

For SDK version 2.1.0 and later, the following table shows the custom open APIs:
Mini program method
TMFMiniAppSDKDelegate proxy implementation method
Description
Default implementation
wx.login
login
Login API SDK.
Default implementation from version 2.1.0
wx.getPhoneNumber
getPhoneNumber
Retrieves phone number.
Default implementation from version 2.1.0
wx.checkSession
checkSession
Checks if the login session is expired.
Default implementation from version 2.1.0
wx.getEmail
getEmail
Retrieves user email.
Default implementation from version 2.1.0
wx.chooseAvatar
chooseAvatar
Retrieves the user profile photo.
Default implementation from version 2.1.0
wx.getNickName
getNickName
Retrieves the user nickname.
Default implementation from version 2.1.0
wx.getUserInfo
getUserInfo
Retrieves basic user information.
No default implementation
wx.getUserProfile
getUserProfile
Retrieves user profile information.
No default implementation
wx.requestPayment
requestPayment
Initiates a payment.
No default implementation
App developers can override the TMFMiniAppSDKDelegate proxy methods to implement logic for retrieving basic user information (wx.getUserInfo), user profile information (wx.getUserProfile), and initiating payments (wx.requestPayment).
Starting from version 2.1.0, if you want to use the default implementation, you need to return the obtained UID (the current user account identifier on the host platform) to the SDK engine through the proxy API after logging into the host app. For example, after logging in to the host app, if the UID is set in [DemoUserInfo sharedInstance].userId, the implementation of the proxy API is as follows:
- (NSString *)getAppUID {
return [DemoUserInfo sharedInstance].userId;
}

Related APIs in the proxy class

// Initiates a payment
// @param app mini program/mini game instance
// @param params parameters
// @param completionHandler callback results
- (void)requestPayment:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// login
// @param app mini program/mini game instance
// @param params parameters
// @param completionHandler callback results
- (void)login:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// checkSession
// @param app mini program/mini game instance
// @param params parameters
// @param completionHandler callback results
- (void)checkSession:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// getUserProfile
// @param app mini program/mini game instance
// @param params parameters
// @param completionHandler callback results
- (void)getUserProfile:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;


// getPhoneNumber
// @param app mini program/mini game instance
// @param params parameters
// @param completionHandler callback results
- (void)getPhoneNumber:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// getUserInfo
// @param app mini program/mini game instance
// @param params parameters
// @param completionHandler callback results
- (void)getUserInfo:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

// Whether to use the custom OpenApi
// @param app mini program/mini game instance
- (BOOL)whetherToUseCustomOpenApi:(TMFMiniAppInfo *)app;

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);
}
}

SDK version 2.0.15 and earlier

For SDK version 2.0.15 and earlier, the following table shows the custom open APIs:
Mini program method
TMFMiniAppSDKDelegate method
Description
wx.login
login
Login API.
wx.getUserInfo
getUserInfo
Retrieves basic user information.
wx.getUserProfile
getUserProfile
Retrieves user profile information.
wx.getPhoneNumber
getPhoneNumber
Retrieves phone number.
wx.requestPayment
requestPayment
Initiates a payment.
wx.checkSession
checkSession
Checks if the login session is expired.
Users can implement the TMFMiniAppSDKDelegate proxy to link data interactions between the mini program and the host app.

Compatibility of custom login logic

Since SDK version 2.1.0 and later come with built-in login and user information retrieval logic, existing customers who have already implemented custom user login logic by overriding the TMFMiniAppSDKDelegate proxy need to configure the SDK to continue using their custom logic after updating to version 2.1.0 or later. Here’s how to do it:
// Whether to use the custom OpenApi
// Returns YES to disable the default login implementation, NO to use the default login implementation. The default value is YES.
// @param app mini program/mini game instance
- (BOOL)whetherToUseCustomOpenApi:(TMFMiniAppInfo *)app;
Note:
Mini program developers use the apiVersion field in app.json to control versions of the APIs starting from 2.1.0 version with default implementation. When the field is not configured, uses the value returned by the whetherToUseCustomOpenApi proxy API. When the field is configured, keep the API version for consistency. That means,
the priority of apiVersion configuration is higher than the value returned by the whetherToUseCustomOpenApi proxy API.
For example: If the apiVersion is configured to V2, all APIs will use the default implementation, even if whetherToUseCustomOpenApi returns YES.

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
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon