com.zopen.ato.autoconfigure.AliPayAutoConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zopen-ato-starter Show documentation
Show all versions of zopen-ato-starter Show documentation
Alibaba Tencent And Others For Spring Boot.
package com.zopen.ato.autoconfigure;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.zopen.ato.properties.AlipayProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(AlipayProperties.class)
@ComponentScan("com.zopen.alipay.pay")
@ConditionalOnProperty(prefix = "zopen.alipay.pay", name = "open", havingValue = "true")
public class AliPayAutoConfiguration {
private static final Logger logger = LoggerFactory.getLogger(AliPayAutoConfiguration.class);
private final AlipayProperties properties;
public AliPayAutoConfiguration(AlipayProperties properties) {
this.properties = properties;
logger.info("初始化 Alipay 配置:" + properties);
}
@Bean
@ConditionalOnMissingBean
public AlipayClient alipayClient() {
String serverUrl = "https://openapi.alipay.com/gateway.do";
return new DefaultAlipayClient(serverUrl, properties.getAppId(), properties.getAppPrivateKey(),
"json", "UTF-8", properties.getAlipayPublicKey(), "RSA2");
}
}