package beilv.common.weixin.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信小程序配置文件
 *
 * @author: moxiangrong
 **/
@Configuration
@ConditionalOnClass(WxMaService.class)
@EnableConfigurationProperties(WxMiniProgramProperties.class)
public class WxMiniProgramConfig {

    /*注入小程序相关配置*/
    @Autowired
    private WxMiniProgramProperties properties;

    /**
     * 配置默认参数
     */
    @Bean
    @ConditionalOnMissingBean
    public WxMaConfig wxMaConfig() {
        WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
        //设置默认参数-appid,secret
//        wxMaDefaultConfig.setAppid(this.properties.getAppid());
//        wxMaDefaultConfig.setSecret(this.properties.getSecret());
        wxMaDefaultConfig.setAppid("wxe44c64c20fa20d69");
        wxMaDefaultConfig.setSecret("bbaaa2292da0bcc3336dc2a0f2f8493a");
        return wxMaDefaultConfig;
    }

    /**
     * 配置WxMaService
     */
    @Bean
    @ConditionalOnMissingBean
    public WxMaService wxMaService(WxMaConfig wxMaConfig) {
        WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(wxMaConfig);
        return wxMaService;
    }


}
