package com.hai.config; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import org.springframework.context.annotation.Configuration; import javax.annotation.PostConstruct; @Configuration public class WxMaConfiguration { private static WxMaService maService; private static WxMaService maQyxService; private static WxMaService maZxjzService; public static WxMaService getMaService() { if (maService == null) { throw new IllegalArgumentException(String.format("未找到对应的配置,请核实!")); } return maService; } public static WxMaService getMaService(Integer type) { if (maService == null || maQyxService == null || maZxjzService == null) { throw new IllegalArgumentException(String.format("未找到对应的配置,请核实!")); } // type 1:嗨森逛小程序参数 2:黔印象小程序参数 3.智行九州 if (type == 1) { return maService; } else if (type == 2) { return maQyxService; } return maZxjzService; } @PostConstruct public void init() { WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); config.setAppid(CommonSysConst.getSysConfig().getWxAppId()); config.setSecret(CommonSysConst.getSysConfig().getWxAppSecret()); maService = new WxMaServiceImpl(); maService.setWxMaConfig(config); WxMaDefaultConfigImpl qyxConfig = new WxMaDefaultConfigImpl(); qyxConfig.setAppid(CommonSysConst.getSysConfig().getWxQyxAppId()); qyxConfig.setSecret(CommonSysConst.getSysConfig().getWxQyxAppSecret()); maQyxService = new WxMaServiceImpl(); maQyxService.setWxMaConfig(qyxConfig); WxMaDefaultConfigImpl zxjzConfig = new WxMaDefaultConfigImpl(); zxjzConfig.setAppid(CommonSysConst.getSysConfig().getWxZxjzAppId()); zxjzConfig.setSecret(CommonSysConst.getSysConfig().getWxZxjzAppSecret()); maZxjzService = new WxMaServiceImpl(); maZxjzService.setWxMaConfig(zxjzConfig); } }