package com.poteviohealth.ym.ipos.utils; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import lombok.extern.slf4j.Slf4j; import java.util.HashMap; import java.util.Map; /** * 微信 token接口 * * @author cxw */ @Slf4j public class WechatServiceApi { private static Map map = new HashMap<>(); private WechatServiceApi() { } /** * 获取实例 * * @param operatorId operatorId * @return 实例 */ public static synchronized WxMaService getInstance(Integer operatorId) { return map.get(operatorId); } public static synchronized WxMaService initInstance(Integer operatorId, String appid, String secret) { WxMaService wxMaService = map.get(operatorId); if (wxMaService != null) { return wxMaService; } WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl(); wxMaConfig.setAppid(appid); wxMaConfig.setSecret(secret); wxMaService = new WxMaServiceImpl(); //设置配置文件 wxMaService.setWxMaConfig(wxMaConfig); map.put(operatorId, wxMaService); return wxMaService; } }