| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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<Integer, WxMaService> 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;
- }
- }
|