tencent cloud

All product documents
Tencent Cloud Super App as a Service
Open APIs
Last updated: 2025-04-03 17:53:12
Open APIs
Last updated: 2025-04-03 17:53:12
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.
Default implementation since version 2.1.0 is supported only on SaaS.

SDK version 2.1.0 and later

The custom open APIs supported by SDK v2.1.0 and later versions are shown in the table below:
Mini program method
MiniOpenApiProxyV2 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 user profile information
No default implementation
wx.getPhoneNumber
getPhoneNumber
Retrieves phone number
Default implementation from version 2.1.0
wx.requestPayment
requestPayment
Initiates a payment
No default implementation
wx.requestMidasPaymentGameItem
requestMidasPaymentGameItem
request mini game payment
No default implementation from version 2.2.4
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
App developers can override the MiniOpenApiProxyV2 proxy methods to implement logic for retrieving basic user information (wx.getUserInfo), user profile information (wx.getUserProfile), and initiating payments (wx.requestPayment) ,and mini game payments (wx.requestMidasPaymentGameItem).

@ProxyService(proxy = MiniOpenApiProxyV2.class)
public class MiniOpenApiProxyImplV2 extends MiniOpenApiProxyDefault {
private static final String TAG = "MiniOpenApiProxyImplV2";

@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);
}
}
}
To use the SDK's default login logic, developers need to override the getAccount method of MiniAppProxy to pass the host application'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 BaseMiniAppProxyImpl {
@Override
public String getAccount() {
// User identifier of the host application
String uid = getHostAppUserId();
return uid;
}
}

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 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 MiniOpenApiProxy proxy to link data interactions between the mini program and the host application. See the example below:
Notes:
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 host application's open API results back to the mini program.
@ProxyService(proxy = MiniOpenApiProxy.class) public class MiniOpenApiProxyImpl implements 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"); // 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 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 MiniOpenApiProxy 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:
@ProxyService(proxy = MiniOpenApiProxyV2.class)
public class DisableDefaultOpenApiProxyImpl extends MiniOpenApiProxyV2 {
@Override
public boolean disableV2API(IMiniAppContext miniAppContext) {
// Return true to disable the default login implementation, false to use the default.
// Default value: false.
return true;
}
}


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