tencent cloud

Open APIs
Last updated:2026-02-10 19:54:17
Open APIs
Last updated: 2026-02-10 19:54:17
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:
Starting from SDK version 2.1.0, the SDK APIs have 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.
The default implementations introduced in version 2.1.0 are only supported in the public cloud version.

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
MiniOpenApiProxy proxy implementation method
Description
Default implementation
wx.login
login
Login API SDK
Default implementation from version 2.1.0
wx.getUserInfo
getUserInfo
Retrieves basic user information
No default implementation
wx.getUserProfile
getUserProfile
Retrieves the user profile information
No default implementation
wx.getPhoneNumber
getPhoneNumber
Retrieves the phone number
Default implementation from version 2.1.0
wx.requestPayment
requestPayment
Initiates a payment
No default implementation
wx.requestMidasPaymentGameItem
requestMidasPaymentGameItem
Initiates the mini game payment
Supported since version 2.2.4, with no default implementation
wx.checkSession
checkSession
Checks if the login session has expired
Default implementation from version 2.1.0
wx.getEmail
getEmail
Retrieves the 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.requestVirtualPayment
requestVirtualPayment
Virtual payment in mini programs
Supported since version 2.2.17, with no default implementation
Superapp developers can override the MiniOpenApiProxy proxy implementation to implement logic for retrieving basic user information (wx.getUserInfo), user profile information (wx.getUserProfile), and initiating payments (wx.requestPayment), virtual payments (wx.requestVirtualPayment) and mini game payments (wx.requestMidasPaymentGameItem).
@ProxyService(proxy = MiniOpenApiProxy.class)
public class MiniOpenApiProxyImpl extends MiniOpenApiProxy {
private static final String TAG = "MiniOpenApiProxyImpl";

@Override
public void getUserInfo(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "getUserInfo:" + params);
JSONObject jsonObject = new JSONObject();
try {
final JSONObject userInfo = new JSONObject();
TmfMiniSDK.callMainProcessPlugin(OpenDataIPC.OPEN_DATA_IPC_EVENT_GET_USER_ID, new Bundle(), new IpcCallback() {
@Override
public void result(boolean b, Bundle bundle) {
try {
userInfo.put("nickName", bundle.getString("userId"));
userInfo.put("avatarUrl", bundle.getString("avatarUrl"));
} catch (JSONException e) {
e.printStackTrace();
}
}
});
userInfo.put("gender", 0);
userInfo.put("country", "CN");
userInfo.put("province", "BeiJing");
userInfo.put("city", "BeiJing");
userInfo.put("language", "en");
jsonObject.put("userInfo", userInfo);
} catch (JSONException e) {
e.printStackTrace();
}
result.onReceiveResult(true, jsonObject);
}

@Override
public void getUserProfile(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "getUserProfile:" + params);
JSONObject jsonObject = new JSONObject();
try {
final JSONObject userInfo = new JSONObject();
TmfMiniSDK.callMainProcessPlugin(OpenDataIPC.OPEN_DATA_IPC_EVENT_GET_USER_ID, new Bundle(), new IpcCallback() {
@Override
public void result(boolean b, Bundle bundle) {
try {
userInfo.put("nickName", bundle.getString("userId"));
userInfo.put("avatarUrl", bundle.getString("avatarUrl"));
} catch (JSONException e) {
e.printStackTrace();
}
}
});
userInfo.put("gender", 0);
userInfo.put("country", "CN");
userInfo.put("province", "BeiJing");
userInfo.put("city", "BeiJing");
userInfo.put("language", "en");
jsonObject.put("userInfo", userInfo);
} catch (JSONException e) {
e.printStackTrace();
}
result.onReceiveResult(true, jsonObject);
}

@Override
public void requestPayment(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "requestPayment:" + params);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.requestPayment");
} catch (JSONException e) {
e.printStackTrace();
}
PaymentManager.g(miniAppContext.getContext()).startPayment(miniAppContext, params, result);
}
@Override
public void requestMidasPaymentGameItem(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
// call your custom payment implementation
boolean paySuccess = PaymentManagerV2.g().startMidasPayment(miniAppContext, params, result);
// notify payment result with AsynResult
if(paySuccess){
result.onReceiveResult(true,successData);
}else{
result.onReceiveResult(false,failedData);
}
}
@Override
public void requestVirtualPayment(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
// call your custom payment implementation
boolean paySuccess = PaymentManagerV2.g().startMidasPayment(miniAppContext, params, result);
// notify payment result with AsynResult
if(paySuccess){
result.onReceiveResult(true,successData);
}else{
result.onReceiveResult(false,failedData);
}
}

}
To use the SDK's default login logic, developers need to override the getAccount method in MiniAppProxy to pass the superapp's UID to the SDK. The SDK will use this UID to exchange and retrieve user information from the mini program's backend service.
@ProxyService(proxy = MiniAppProxy.class)
public class MiniAppProxyImpl extends MiniOpenApiProxy {
@Override
public String getAccount() {
// Superapp user identifier
String uid = getHostAppUserId();
return uid;
}
}
Note:
When the user logs out, it is necessary to call to terminate the mini program to avoid cross-sharing of sandbox data between different users. Example code:
TmfMiniSDK.stopAllMiniApp(MainActivity.this);

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
MiniOpenApiProxy method
Description
wx.login
login
Login API
wx.getUserInfo
getUserInfo
Retrieves the basic user information
wx.getUserProfile
getUserProfile
Retrieves the user profile information
wx.getPhoneNumber
getPhoneNumber
Retrieves the phone number
wx.requestPayment
requestPayment
Initiates a payment
wx.checkSession
checkSession
Checks if the login session has expired
Users can associate data interactions between the mini program and superapp by implementing the MiniOpenApiProxy proxy. See the example below:
Note:
IMiniAppContext provides the current context information of the mini program.
JSONObject contains the parameters passed when the mini program calls the open APIs.
AsyncResult is an asynchronous callback API used to return the superapp's open API results back to the mini program.
@ProxyService(proxy = MiniOpenApiProxy.class)
public class MiniOpenApiProxyImpl extends MiniOpenApiProxy {
private static final String TAG = "MiniOpenApiProxyImpl";
@Override
public void login(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "login:" + params);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.login");
} catch (JSONException e) {
e.printStackTrace();
}
result.onReceiveResult(true, jsonObject);
}

@Override
public void checkSession(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "checkSession:" + params);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.checkSession");
} catch (JSONException e) {
e.printStackTrace();
}
result.onReceiveResult(true, jsonObject);
}

@Override
public void getUserInfo(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "getUserInfo:" + params);
JSONObject jsonObject = new JSONObject();
try {
final JSONObject userInfo = new JSONObject();

userInfo.put("nickName", "userInfo test");
// userInfo.put("avatarUrl", bundle.getString("avatarUrl"));

userInfo.put("gender", 0);
userInfo.put("country", "CN");
userInfo.put("province", "BeiJing");
userInfo.put("city", "BeiJing");
userInfo.put("language", "en");
jsonObject.put("userInfo", userInfo);
} catch (JSONException e) {
e.printStackTrace();
}
result.onReceiveResult(true, jsonObject);
}

@Override
public void getUserProfile(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "getUserProfile:" + params);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.getUserProfile");
} catch (JSONException e) {
e.printStackTrace();
}
result.onReceiveResult(true, jsonObject);
}

@Override
public void getPhoneNumber(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "getPhoneNumber:" + params);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.getPhoneNumber");
} catch (JSONException e) {
e.printStackTrace();
}
result.onReceiveResult(true, jsonObject);
}

@Override
public void requestPayment(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {
QMLog.d(TAG, "requestPayment:" + params);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.requestPayment");
} catch (JSONException e) {
e.printStackTrace();
}
result.onReceiveResult(true, jsonObject);
}

Compatibility of custom login logic

Since the SDK versions 2.1.0 and later come with built-in logic for login and user information retrieval by default, existing customers who update to version 2.1.0 or later must configure their setup to continue using their custom login and user information retrieval logic if they have previously overridden the MiniOpenApiProxy proxy. To continue using your custom login and user information retrieval logic, you must configure it as follows:
@ProxyService(proxy = MiniOpenApiProxy.class)
public class MiniOpenApiProxyImpl extends MiniOpenApiProxy {
/**
* Specifies the default API version
*
* @param miniAppContext The mini program context, which can be used to obtain the information about the current mini program, the Activity bound to the mini program, etc.
* @return Valid values: {@link #API_LEVEL_UNDEFINED}, {@link #API_LEVEL_V1}, {@link #API_LEVEL_V2}, {@link #API_LEVEL_V3}
*/
@Override
String defaultApiLevel(IMiniAppContext miniAppContext) {
return MiniOpenApiProxy.API_LEVEL_V1;
}
}
Starting from the SDK version 2.2.11, the MiniOpenApiProxyV2 API has been deprecated, and MiniOpenApiProxy has been adjusted from an API to an abstract class. If you have been using the MiniOpenApiProxyV2 proxy, you need to migrate all your implementations to MiniOpenApiProxy after updating to version 2.2.11 or later.


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

Feedback