tencent cloud

Feedback

WeChat Mini Program Events

Last updated: 2024-03-08 14:32:55
The following methods correspond to the Native in the WeChat Mini Program. When developers invoke the corresponding methods during the development of the mini program, they will trigger the corresponding events in the Native. Developers need to monitor these events and return the data.
WeChat Method
Native Events
wx.login
login
wx.getUserInfo
getUserInfo
wx.getUserProfile
getUserProfile
wx.getPhoneNumber
getPhoneNumber
@JsPlugin(secondary = true)
public class WxApiPlugin extends BaseJsPlugin {
/**
* Corresponds to the invocation of wx.login in the Mini Program
* Invocation environment: Subprocess
*
* @param req
*/
@JsEvent("login")
public void login(final RequestEvent req) {
//Get parameters
//req.jsonParams
//Asynchronously Return Data
//req.fail();
//req.ok();
Log.d(ModuleApplet.TAG, "login=" + req.jsonParams);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.login");
} catch (JSONException e) {
e.printStackTrace();
}
req.ok(jsonObject);
}

/**
* Corresponds to the invocation of wx.getUserInfo in the Mini Program
* Invocation environment: Subprocess
*
* @param req
*/
@JsEvent("getUserInfo")
public void getUserInfo(final RequestEvent req) {
//Get parameters
//req.jsonParams
//Asynchronously Return Data
//req.fail();
//req.ok();
Log.d(ModuleApplet.TAG, "getUserInfo=" + req.jsonParams);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.getUserInfo");
} catch (JSONException e) {
e.printStackTrace();
}
req.ok(jsonObject);
}

/**
* Corresponds to the invocation of wx.getUserProfile in the Mini Program
* Invocation environment: Subprocess
*
* @param req
*/
@JsEvent("getUserProfile")
public void getUserProfile(final RequestEvent req) {
//Get parameters
//req.jsonParams
//Asynchronously Return Data
//req.fail();
//req.ok();
Log.d(ModuleApplet.TAG, "getUserProfile=" + req.jsonParams);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.getUserProfile");
} catch (JSONException e) {
e.printStackTrace();
}
req.ok(jsonObject);
}

/**
* Corresponds to the invocation of wx.getPhoneNumber in the Mini Program
* Invocation environment: Subprocess
*
* @param req
*/
@JsEvent("wx.getPhoneNumber")
public void getPhoneNumber(final RequestEvent req) {
//Get parameters
//req.jsonParams
//Asynchronously Return Data
//req.fail();
//req.ok();
Log.d(ModuleApplet.TAG, "getPhoneNumber=" + req.jsonParams);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("key", "wx.getPhoneNumber");
} catch (JSONException e) {
e.printStackTrace();
}
req.ok(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