🎨 重构 ballcat-spring-boot-starter-pay模块, 使其按需加载指定支付方式
This commit is contained in:
@@ -209,11 +209,6 @@
|
||||
<artifactId>ballcat-extend-mybatis-plus</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-extend-mybatis-plus-mysql</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-extend-kafka</artifactId>
|
||||
@@ -224,6 +219,11 @@
|
||||
<artifactId>ballcat-extend-kafka-stream</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-extend-pay-virtual</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!--swagger注解-->
|
||||
<dependency>
|
||||
|
||||
30
ballcat-extends/ballcat-extend-pay-virtual/pom.xml
Normal file
30
ballcat-extends/ballcat-extend-pay-virtual/pom.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ballcat-extends</artifactId>
|
||||
<groupId>com.hccake</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ballcat-extend-pay-virtual</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>live.lingting</groupId>
|
||||
<artifactId>virtual-currency</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -16,5 +16,6 @@
|
||||
<module>ballcat-extend-dingtalk</module>
|
||||
<module>ballcat-extend-kafka</module>
|
||||
<module>ballcat-extend-kafka-stream</module>
|
||||
</modules>
|
||||
<module>ballcat-extend-pay-virtual</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -22,6 +22,10 @@
|
||||
<artifactId>ballcat-spring-boot-starter-pay</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-extend-pay-virtual</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.sample.pay.virtual.config;
|
||||
|
||||
import com.hccake.starter.pay.PayProperties;
|
||||
import com.hccake.starter.pay.virtual.BitcoinProperties;
|
||||
import java.util.function.Supplier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -13,16 +13,16 @@ import live.lingting.virtual.currency.properties.OmniProperties;
|
||||
public class OmniConfig {
|
||||
|
||||
@Bean
|
||||
public OmniProperties bitcoinProperties(PayProperties properties) {
|
||||
public OmniProperties bitcoinProperties(BitcoinProperties properties) {
|
||||
// omni 使用的接口限制请求频率(5-10s一次), 需要根据项目实现, 这里直接返回true
|
||||
Supplier<Boolean> lock = () -> true;
|
||||
Supplier<Boolean> unlock = () -> true;
|
||||
|
||||
return new OmniProperties()
|
||||
// 节点
|
||||
.setOmniEndpoints(properties.getBitcoin().getOmni().getEndpoints())
|
||||
.setOmniEndpoints(properties.getOmni().getEndpoints())
|
||||
// 比特节点
|
||||
.setBitcoinEndpoints(properties.getBitcoin().getEndpoints())
|
||||
.setBitcoinEndpoints(properties.getEndpoints())
|
||||
// 请求锁
|
||||
.setLock(lock).setUnlock(unlock);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ ballcat:
|
||||
bitcoin:
|
||||
omni:
|
||||
endpoints: mainnet
|
||||
enabled: true
|
||||
ethereum:
|
||||
infura:
|
||||
endpoints: mainnet
|
||||
@@ -10,6 +11,7 @@ ballcat:
|
||||
project-id: b6066b4cfce54e7384ea38d52f9260ac
|
||||
tronscan:
|
||||
endpoints: mainnet
|
||||
enabled: true
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>live.lingting</groupId>
|
||||
<artifactId>virtual-currency</artifactId>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-extend-pay-virtual</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -36,10 +37,5 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<!-- 用于校验参数 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.hccake.starter.pay;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import live.lingting.virtual.currency.endpoints.BitcoinEndpoints;
|
||||
import live.lingting.virtual.currency.endpoints.Endpoints;
|
||||
import live.lingting.virtual.currency.endpoints.InfuraEndpoints;
|
||||
import live.lingting.virtual.currency.endpoints.OmniEndpoints;
|
||||
import live.lingting.virtual.currency.endpoints.TronscanEndpoints;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/1/5 9:58
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "ballcat.pay")
|
||||
public class PayProperties {
|
||||
|
||||
/**
|
||||
* 以太坊
|
||||
*/
|
||||
private Ethereum ethereum;
|
||||
|
||||
/**
|
||||
* 波场
|
||||
*/
|
||||
private Tronscan tronscan;
|
||||
|
||||
/**
|
||||
* 比特
|
||||
*/
|
||||
private Bitcoin bitcoin;
|
||||
|
||||
@Data
|
||||
public static class Ethereum {
|
||||
|
||||
/**
|
||||
* 使用 infura 平台. 网址 https://infura.io/dashboard
|
||||
*/
|
||||
private Infura infura;
|
||||
|
||||
@Data
|
||||
public static class Infura {
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private InfuraEndpoints endpoints;
|
||||
|
||||
/**
|
||||
* 在 <a href="https://infura.io/dashboard"/> 注册后, 创建的app的 projectId
|
||||
*/
|
||||
private String projectId;
|
||||
|
||||
/**
|
||||
* projectSecret
|
||||
*/
|
||||
private String projectSecret;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Tronscan {
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private TronscanEndpoints endpoints;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Bitcoin {
|
||||
|
||||
/**
|
||||
* 使用 omni 平台
|
||||
*/
|
||||
private Omni omni;
|
||||
|
||||
/**
|
||||
* 比特节点
|
||||
*/
|
||||
private BitcoinEndpoints endpoints;
|
||||
|
||||
@Data
|
||||
public static class Omni {
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private OmniEndpoints endpoints;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.hccake.starter.pay.virtual;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import live.lingting.virtual.currency.endpoints.BitcoinEndpoints;
|
||||
import live.lingting.virtual.currency.endpoints.OmniEndpoints;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/1/22 17:45
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "ballcat.pay.bitcoin")
|
||||
public class BitcoinProperties {
|
||||
|
||||
/**
|
||||
* 是否开启
|
||||
*/
|
||||
private Boolean enabled = true;
|
||||
|
||||
/**
|
||||
* 使用 omni 平台
|
||||
*/
|
||||
private Omni omni;
|
||||
|
||||
/**
|
||||
* 比特节点
|
||||
*/
|
||||
private BitcoinEndpoints endpoints;
|
||||
|
||||
@Data
|
||||
public static class Omni {
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private OmniEndpoints endpoints;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.hccake.starter.pay.virtual;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import live.lingting.virtual.currency.endpoints.InfuraEndpoints;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/1/22 17:47
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "ballcat.pay.ethereum")
|
||||
public class EthereumProperties {
|
||||
|
||||
/**
|
||||
* 是否开启
|
||||
*/
|
||||
private Boolean enabled = true;
|
||||
|
||||
/**
|
||||
* 使用 infura 平台. 网址 https://infura.io/dashboard
|
||||
*/
|
||||
private Infura infura;
|
||||
|
||||
@Data
|
||||
public static class Infura {
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private InfuraEndpoints endpoints;
|
||||
|
||||
/**
|
||||
* 在 <a href="https://infura.io/dashboard"/> 注册后, 创建的app的 projectId
|
||||
*/
|
||||
private String projectId;
|
||||
|
||||
/**
|
||||
* projectSecret
|
||||
*/
|
||||
private String projectSecret;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.hccake.starter.pay.virtual;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import live.lingting.virtual.currency.endpoints.TronscanEndpoints;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/1/22 17:47
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "ballcat.pay.tronscan")
|
||||
public class TronscanProperties {
|
||||
|
||||
/**
|
||||
* 是否开启
|
||||
*/
|
||||
private Boolean enabled = true;
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private TronscanEndpoints endpoints;
|
||||
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.hccake.starter.pay;
|
||||
package com.hccake.starter.pay.virtual;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
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 live.lingting.virtual.currency.properties.InfuraProperties;
|
||||
@@ -17,10 +20,10 @@ import live.lingting.virtual.currency.service.impl.TronscanServiceImpl;
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@EnableConfigurationProperties({ PayProperties.class })
|
||||
public class PayAutoConfiguration {
|
||||
|
||||
private final PayProperties properties;
|
||||
@ConditionalOnClass(InfuraProperties.class)
|
||||
@EnableConfigurationProperties({ BitcoinProperties.class, EthereumProperties.class,
|
||||
com.hccake.starter.pay.virtual.TronscanProperties.class })
|
||||
public class VirtualPayAutoConfiguration {
|
||||
|
||||
/*
|
||||
* Ethereum 配置
|
||||
@@ -32,8 +35,10 @@ public class PayAutoConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public InfuraProperties infuraProperties() {
|
||||
PayProperties.Ethereum.Infura infura = properties.getEthereum().getInfura();
|
||||
@ConditionalOnProperty(prefix = "ballcat.pay.ethereum", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
public InfuraProperties infuraProperties(EthereumProperties properties) {
|
||||
EthereumProperties.Infura infura = properties.getInfura();
|
||||
return new InfuraProperties()
|
||||
// 节点
|
||||
.setEndpoints(infura.getEndpoints())
|
||||
@@ -49,6 +54,7 @@ public class PayAutoConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(InfuraProperties.class)
|
||||
public InfuraServiceImpl infuraService(InfuraProperties properties) {
|
||||
return new InfuraServiceImpl(properties);
|
||||
}
|
||||
@@ -63,10 +69,12 @@ public class PayAutoConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TronscanProperties tronscanProperties() {
|
||||
@ConditionalOnProperty(prefix = "ballcat.pay.tronscan", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
public TronscanProperties tronscanProperties(com.hccake.starter.pay.virtual.TronscanProperties properties) {
|
||||
return new TronscanProperties()
|
||||
// 节点
|
||||
.setEndpoints(properties.getTronscan().getEndpoints());
|
||||
.setEndpoints(properties.getEndpoints());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +83,7 @@ public class PayAutoConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(TronscanProperties.class)
|
||||
public TronscanServiceImpl tronscanService(TronscanProperties properties) {
|
||||
return new TronscanServiceImpl(properties);
|
||||
}
|
||||
@@ -89,12 +98,14 @@ public class PayAutoConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public OmniProperties bitcoinProperties() {
|
||||
@ConditionalOnProperty(prefix = "ballcat.pay.bitcoin", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
public OmniProperties bitcoinProperties(BitcoinProperties properties) {
|
||||
return new OmniProperties()
|
||||
// 节点
|
||||
.setOmniEndpoints(properties.getBitcoin().getOmni().getEndpoints())
|
||||
.setOmniEndpoints(properties.getOmni().getEndpoints())
|
||||
// 比特节点
|
||||
.setBitcoinEndpoints(properties.getBitcoin().getEndpoints());
|
||||
.setBitcoinEndpoints(properties.getEndpoints());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,6 +114,7 @@ public class PayAutoConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(OmniProperties.class)
|
||||
public BtcOmniServiceImpl bitcoinService(OmniProperties properties) {
|
||||
return new BtcOmniServiceImpl(properties);
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.hccake.starter.pay.PayAutoConfiguration
|
||||
com.hccake.starter.pay.virtual.VirtualPayAutoConfiguration
|
||||
Reference in New Issue
Block a user