com.pentahohub.nexus.boot.autoconfigure.weixin.WeixinAutoConfiguration Maven / Gradle / Ivy
package com.pentahohub.nexus.boot.autoconfigure.weixin;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.pentahohub.nexus.weixin.WeixinConfiguration;
import com.pentahohub.nexus.weixin.domain.WeixinAccount;
import com.pentahohub.nexus.weixin.exception.WeixinException;
@Configuration
@ConditionalOnProperty(prefix = WeixinProperties.PREFIX, name = "enable", havingValue = "true")
@EnableConfigurationProperties(WeixinProperties.class)
public class WeixinAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public WeixinConfiguration weixinConfiguration(WeixinProperties weixinProperties) throws WeixinException {
WeixinAccount weixinAccount = new WeixinAccount();
weixinAccount.setAppId(weixinProperties.getAppId());
weixinAccount.setAppSecret(weixinProperties.getAppSecret());
weixinAccount.setToken(weixinProperties.getToken());
weixinAccount.setEncryptType(weixinProperties.getEncryptType());
weixinAccount.setEncodingAesKey(weixinProperties.getEncodingAesKey());
WeixinConfiguration weixinConfiguration = new WeixinConfiguration();
weixinConfiguration.init(weixinAccount);
return weixinConfiguration;
}
}