package com.dora.config;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信公众号配置类
 * 用于配置微信公众号相关的服务和参数
 * 
 * @author dora
 * @date 2024/12/01
 */
@Configuration
public class WeChatMpConfig {

    @Value("${wx.mp.appid}")
    private String appId;

    @Value("${wx.mp.secret}")
    private String appSecret;

    @Value("${wx.mp.token}")
    private String token;

    @Value("${wx.mp.aesKey}")
    private String aesKey;

    /**
     * 微信公众号服务Bean
     * 用于处理微信公众号相关的API调用
     */
    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
        
        // 基本配置
        config.setAppId(appId);
        config.setSecret(appSecret);
        config.setToken(token);
        config.setAesKey(aesKey);
        
        wxMpService.setWxMpConfigStorage(config);
        return wxMpService;
    }
}