package com.ruoyi.system.config;
|
|
import lombok.AllArgsConstructor;
|
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
|
import me.chanjar.weixin.cp.api.WxCpService;
|
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
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;
|
|
/**
|
* @ClassName WxCpConfiguration
|
* @Description TODO
|
* @Author jqs
|
* @Date 2023/8/17 12:42
|
* @Version 1.0
|
*/
|
@Configuration
|
@ConditionalOnClass(WxCpService.class)
|
@EnableConfigurationProperties(WxCpProperties.class)
|
@AllArgsConstructor
|
public class WxCpConfiguration {
|
|
private WxCpProperties properties;
|
|
@Bean
|
@ConditionalOnMissingBean(name = "wxService")
|
public WxCpService wxService() {
|
WxCpDefaultConfigImpl wxCpConfigStorage = new WxCpDefaultConfigImpl();
|
wxCpConfigStorage.setCorpId(properties.getCorpId());
|
wxCpConfigStorage.setAgentId(properties.getAgentId());
|
wxCpConfigStorage.setCorpSecret(properties.getAgentSecret());
|
wxCpConfigStorage.setAesKey(properties.getEncodingAESKey());
|
wxCpConfigStorage.setToken(properties.getToken());
|
WxCpService wxService = new WxCpServiceImpl();
|
wxService.setWxCpConfigStorage(wxCpConfigStorage);
|
return wxService;
|
}
|
|
@Bean
|
@ConditionalOnMissingBean(name = "adWxService")
|
public WxCpService adWxService() {
|
WxCpDefaultConfigImpl wxAdCpConfigStorage = new WxCpDefaultConfigImpl();
|
wxAdCpConfigStorage.setCorpId(properties.getCorpId());
|
wxAdCpConfigStorage.setAgentId(properties.getAgentId());
|
wxAdCpConfigStorage.setCorpSecret(properties.getAddressSecret());
|
wxAdCpConfigStorage.setAesKey(properties.getEncodingAESKey());
|
wxAdCpConfigStorage.setToken(properties.getToken());
|
WxCpService adWxService = new WxCpServiceImpl();
|
adWxService.setWxCpConfigStorage(wxAdCpConfigStorage);
|
return adWxService;
|
}
|
|
|
@Bean
|
@ConditionalOnMissingBean
|
public WxCryptUtil wxCryptUtil() {
|
WxCryptUtil wxCryptUtil = new WxCryptUtil(properties.getToken(), properties.getEncodingAESKey(), properties.getCorpId());
|
return wxCryptUtil;
|
}
|
}
|