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 |
@ProxyService(proxy = MiniOpenApiProxy.class)public class MiniOpenApiProxyImpl extends MiniOpenApiProxy {private static final String TAG = "MiniOpenApiProxyImpl";@Overridepublic 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() {@Overridepublic 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);}@Overridepublic 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() {@Overridepublic 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);}@Overridepublic 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);}@Overridepublic void requestMidasPaymentGameItem(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {// call your custom payment implementationboolean paySuccess = PaymentManagerV2.g().startMidasPayment(miniAppContext, params, result);// notify payment result with AsynResultif(paySuccess){result.onReceiveResult(true,successData);}else{result.onReceiveResult(false,failedData);}}@Overridepublic void requestVirtualPayment(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {// call your custom payment implementationboolean paySuccess = PaymentManagerV2.g().startMidasPayment(miniAppContext, params, result);// notify payment result with AsynResultif(paySuccess){result.onReceiveResult(true,successData);}else{result.onReceiveResult(false,failedData);}}}
@ProxyService(proxy = MiniAppProxy.class)public class MiniAppProxyImpl extends MiniOpenApiProxy {@Overridepublic String getAccount() {// Superapp user identifierString uid = getHostAppUserId();return uid;}}
TmfMiniSDK.stopAllMiniApp(MainActivity.this);
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 |
@ProxyService(proxy = MiniOpenApiProxy.class)public class MiniOpenApiProxyImpl extends MiniOpenApiProxy {private static final String TAG = "MiniOpenApiProxyImpl";@Overridepublic 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);}@Overridepublic 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);}@Overridepublic 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);}@Overridepublic 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);}@Overridepublic 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);}@Overridepublic 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);}
@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}*/@OverrideString defaultApiLevel(IMiniAppContext miniAppContext) {return MiniOpenApiProxy.API_LEVEL_V1;}}
Feedback