package com.hfkj.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 WxMaConfig {

    private static WxMaService maService;

    public static WxMaService getMaService() {
        if (maService == null) {
            throw new IllegalArgumentException(String.format("未找到对应的配置，请核实！"));
        }

        return maService;
    }

    @PostConstruct
    public void init() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(CommonSysConst.getSysConfig().getWechatMaAppid());
        config.setSecret(CommonSysConst.getSysConfig().getWechatMaSecret());
        maService = new WxMaServiceImpl();
        maService.setWxMaConfig(config);
    }

}
