package com.softwarebr.nunu.config;

import com.softwarebr.nunu.config.domain.ConfigService;
import com.softwarebr.nunu.domain.PayConfig;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Component
public class WxMpConfig {

    @Autowired
    ConfigService<PayConfig> payConfigService;

    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        PayConfig payConfig = payConfigService.get();
        //设置为内存存储
        WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
        configStorage.setAppId(payConfig.getWxAppId());
        configStorage.setSecret(payConfig.getWxAppSecret());
        //configStorage.setToken(payConfig.getWxToken());
        //configStorage.setAesKey(payConfig.getWxAesKey());
        return configStorage;
    }


    @Bean
    public WxMpService wxMpService(WxMpConfigStorage wxMpConfigStorage){
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage);
        return wxMpService;
    }

}
