微信小程序如下方法与 Native 对应关系,当开发者在小程序开发过程中调用对应方法时,会调用到 native 对应事件,开发者需要监听事件并返回数据。
微信方法 | native事件 |
wx.login | login |
wx.getUserInfo | getUserInfo |
wx.getUserProfile | getUserProfile |
wx.getPhoneNumber | getPhoneNumber |
@JsPlugin(secondary = true)public class WxApiPlugin extends BaseJsPlugin {/*** 对应小程序wx.login调用* 调用环境:子进程** @param req*/@JsEvent("login")public void login(final RequestEvent req) {//获取参数//req.jsonParams//异步返回数据//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);}/*** 对应小程序wx.getUserInfo调用* 调用环境:子进程** @param req*/@JsEvent("getUserInfo")public void getUserInfo(final RequestEvent req) {//获取参数//req.jsonParams//异步返回数据//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);}/*** 对应小程序wx.getUserProfile调用* 调用环境:子进程** @param req*/@JsEvent("getUserProfile")public void getUserProfile(final RequestEvent req) {//获取参数//req.jsonParams//异步返回数据//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);}/*** 对应小程序wx.getPhoneNumber调用* 调用环境:子进程** @param req*/@JsEvent("wx.getPhoneNumber")public void getPhoneNumber(final RequestEvent req) {//获取参数//req.jsonParams//异步返回数据//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);}}