All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zopen.ato.autoconfigure.AliPayAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
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");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy