tencent cloud

Feedback

Open APIs

Last updated: 2024-11-21 17:34:02
The following table shows the mapping between Weixin mini program methods and native events. When developers call these methods in the mini program, the corresponding native events are triggered, and developers need to listen to these events and return data.
Mini Program Methods
MiniOpenApiProxy Methods
Description of the method
wx.login
login
Login interface
wx.getUserInfo
getUserInfo
Get basic user information
wx.getUserProfile
getUserProfile
Get user profile information
wx.getPhoneNumber
getPhoneNumber
Get phone number
wx.requestPayment
requestPayment
Initiate a payment
wx.checkSession
checkSession
Checks if the login status has expired.
Users can implement MiniOpenApiProxy proxy to correlate the data interactions between mini programs and the host application, the sample code is as follows:
Note:
Parameter IMiniAppContext is the context information of the current mini program;
The parameter JSONObject is the parameter passed when the mini program calls the open interface;
The parameter AsyncResult is the asynchronous callback interface through which the user needs to return the return value of the host application's implementation of the open interface 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", "userInfotest"); // 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); }

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 avaliable.

7x24 Phone Support