工具类WxMaConfiguration获取WxMaService
public static WxMaService getWxMaService(String appid) {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setMsgDataFormat("JSON");
config.setAppid("xxxxxxx");
config.setSecret("xxxxxxxx");
WxMaService wxMaService = new WxMaServiceImpl();
wxMaService.setWxMaConfig(config);
return wxMaService;
}
获取小程序外部链接url
path:跳转的小程序页面路径
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
public static String getUrlScheme2() throws WxErrorException {
WxMaService wxMaService = WxMaConfiguration.getWxMaService("wxccacc2ac353ffa5d");
WxMaSchemeService linkService = wxMaService.getWxMaSchemeService();
WxMaGenerateSchemeRequest.JumpWxa jumpWxa = WxMaGenerateSchemeRequest.JumpWxa.newBuilder().path("pages/home/index").build();
WxMaGenerateSchemeRequest build = WxMaGenerateSchemeRequest.newBuilder().jumpWxa(jumpWxa).build();
String url = linkService.generate(build);
return url;
}