小程序方法 | MiniOpenApiProxy 代理实现方法 | 描述 | 默认实现 |
wx.login | login | 登录接口 SDK | 2.1.0版本起,提供默认实现 |
wx.getUserInfo | getUserInfo | 获取用户基本信息 | 无默认实现 |
wx.getUserProfile | getUserProfile | 获取用户属性信息 | 无默认实现 |
wx.getPhoneNumber | getPhoneNumber | 获取电话号码 | 2.1.0版本起,提供默认实现 |
wx.requestPayment | requestPayment | 发起支付 | 无默认实现 |
wx.requestMidasPaymentGameItem | requestMidasPaymentGameItem | 发起小游戏支付 | 2.2.4版本起支持,无默认实现 |
wx.checkSession | checkSession | 检查登录状态是否过期 | 2.1.0版本起,提供默认实现 |
wx.getEmail | getEmail | 获取用户邮箱 | 2.1.0版本起,提供默认实现 |
wx.chooseAvatar | chooseAvatar | 获取用户头像 | 2.1.0版本起,提供默认实现 |
wx.getNickName | getNickName | 获取用户昵称 | 2.1.0版本起,提供默认实现 |
wx.requestVirtualPayment | requestVirtualPayment | 小程序虚拟支付 | 2.2.17版本起支持,无默认实现 |
@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 BaseMiniAppProxyImpl {@Overridepublic String getAccount() {//superapp的用户标识符String uid = getHostAppUserId();return uid;}}
小程序方法 | MiniOpenApiProxy 方法 | 描述 |
wx.login | login | 登录接口 |
wx.getUserInfo | getUserInfo | 获取用户基本信息 |
wx.getUserProfile | getUserProfile | 获取用户属性信息 |
wx.getPhoneNumber | getPhoneNumber | 获取电话号码 |
wx.requestPayment | requestPayment | 发起支付 |
wx.checkSession | checkSession | 检查登录状态是否过期 |
@ProxyService(proxy = MiniOpenApiProxy.class)public class MiniOpenApiProxyImpl implements 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测试");// 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 {/*** 指定默认 api 版本** @param miniAppContext 小程序上下文,可以获取当前小程序信息、小程序绑定的Activity等* @return 合法值: {@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;}}
文档反馈