45
ballcat-starters/ballcat-spring-boot-starter-pay/pom.xml
Normal file
45
ballcat-starters/ballcat-spring-boot-starter-pay/pom.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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-starters</artifactId>
|
||||
<groupId>com.hccake</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ballcat-spring-boot-starter-pay</artifactId>
|
||||
<description>支付模块</description>
|
||||
|
||||
<properties>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>live.lingting</groupId>
|
||||
<artifactId>virtual-currency</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- spring boot 配置所需依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<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>
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.hccake.starter.pay;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import live.lingting.virtual.currency.properties.InfuraProperties;
|
||||
import live.lingting.virtual.currency.properties.OmniProperties;
|
||||
import live.lingting.virtual.currency.properties.TronscanProperties;
|
||||
import live.lingting.virtual.currency.service.impl.InfuraServiceImpl;
|
||||
import live.lingting.virtual.currency.service.impl.OmniServiceImpl;
|
||||
import live.lingting.virtual.currency.service.impl.TronscanServiceImpl;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/1/5 9:52
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@EnableConfigurationProperties({ PayProperties.class })
|
||||
public class PayAutoConfiguration {
|
||||
|
||||
private final PayProperties properties;
|
||||
|
||||
/*
|
||||
* Ethereum 配置
|
||||
*/
|
||||
|
||||
/**
|
||||
* infura 配置类
|
||||
* @author lingting 2021-01-05 10:40
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public InfuraProperties infuraProperties() {
|
||||
PayProperties.Ethereum.Infura infura = properties.getEthereum().getInfura();
|
||||
return new InfuraProperties()
|
||||
// 节点
|
||||
.setEndpoints(infura.getEndpoints())
|
||||
// project id
|
||||
.setProjectId(infura.getProjectId())
|
||||
// project secret
|
||||
.setProjectSecret(infura.getProjectSecret());
|
||||
}
|
||||
|
||||
/**
|
||||
* infura 平台实现类
|
||||
* @author lingting 2021-01-05 10:35
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public InfuraServiceImpl infuraService(InfuraProperties properties) {
|
||||
return new InfuraServiceImpl(properties);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tronscan 配置
|
||||
*/
|
||||
|
||||
/**
|
||||
* tronscan 配置类
|
||||
* @author lingting 2021-01-05 10:40
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TronscanProperties tronscanProperties() {
|
||||
return new TronscanProperties()
|
||||
// 节点
|
||||
.setEndpoints(properties.getTronscan().getEndpoints());
|
||||
}
|
||||
|
||||
/**
|
||||
* tronscan 平台实现类
|
||||
* @author lingting 2021-01-05 10:35
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TronscanServiceImpl tronscanService(TronscanProperties properties) {
|
||||
return new TronscanServiceImpl(properties);
|
||||
}
|
||||
|
||||
/*
|
||||
* bitcoin 配置
|
||||
*/
|
||||
|
||||
/**
|
||||
* bitcoin 配置类
|
||||
* @author lingting 2021-01-05 10:40
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public OmniProperties bitcoinProperties() {
|
||||
return new OmniProperties()
|
||||
// 节点
|
||||
.setEndpoints(properties.getBitcoin().getOmni().getEndpoints());
|
||||
}
|
||||
|
||||
/**
|
||||
* bitcoin 平台实现类
|
||||
* @author lingting 2021-01-05 10:35
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public OmniServiceImpl bitcoinService(OmniProperties properties) {
|
||||
return new OmniServiceImpl(properties);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.hccake.starter.pay;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
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;
|
||||
|
||||
@Data
|
||||
public static class Omni {
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private OmniEndpoints endpoints;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.hccake.starter.pay.viratual;
|
||||
|
||||
import com.hccake.ballcat.common.core.thread.AbstractQueueThread;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import live.lingting.virtual.currency.Transaction;
|
||||
|
||||
/**
|
||||
* 用于校验交易的线程
|
||||
*
|
||||
* @author lingting 2021/1/5 11:08
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractVerifyThread<T extends VerifyObj, R> extends AbstractQueueThread<T> {
|
||||
|
||||
@Override
|
||||
public long getBatchSize() {
|
||||
// 校验对象不需要堆积太多, 10条直接处理
|
||||
return 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据校验对象信息获取交易数据
|
||||
* @param obj 校验对象信息
|
||||
* @return live.lingting.virtual.currency.Transaction
|
||||
* @author lingting 2021-01-05 11:22
|
||||
*/
|
||||
public abstract Optional<Transaction> getTransaction(T obj);
|
||||
|
||||
/**
|
||||
* 处理交易
|
||||
* @param obj 校验对象信息
|
||||
* @param optional 交易数据
|
||||
* @author lingting 2021-01-05 11:13
|
||||
*/
|
||||
public abstract void handler(T obj, @NotNull Optional<Transaction> optional);
|
||||
|
||||
/**
|
||||
* 失败处理
|
||||
* @param obj 校验对象
|
||||
* @param optional 交易数据
|
||||
* @param r 处理结果
|
||||
* @author lingting 2021-01-05 11:18
|
||||
*/
|
||||
public abstract void failed(T obj, @NotNull Optional<Transaction> optional, R r);
|
||||
|
||||
/**
|
||||
* 成功处理
|
||||
* @param obj 校验对象
|
||||
* @param optional 交易数据
|
||||
* @param r 处理结果
|
||||
* @author lingting 2021-01-05 11:19
|
||||
*/
|
||||
public abstract void success(T obj, @NotNull Optional<Transaction> optional, R r);
|
||||
|
||||
/**
|
||||
* 缓存校验对象
|
||||
* @param obj 校验对象
|
||||
* @author lingting 2021-01-05 11:17
|
||||
*/
|
||||
public abstract void cache(T obj);
|
||||
|
||||
/**
|
||||
* 读取所有缓存的校验对象
|
||||
* @return java.util.List<T>
|
||||
* @author lingting 2021-01-05 11:17
|
||||
*/
|
||||
public abstract List<T> readCache();
|
||||
|
||||
/**
|
||||
* 异常处理
|
||||
* @param obj 校验对象
|
||||
* @param e 异常信息
|
||||
* @author lingting 2021-01-05 11:29
|
||||
*/
|
||||
public abstract void error(T obj, Throwable e);
|
||||
|
||||
@Override
|
||||
public void preProcessor() {
|
||||
for (T obj : readCache()) {
|
||||
// 把缓存中的所有数据插入线程
|
||||
putObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(List<T> list) throws Exception {
|
||||
for (T obj : list) {
|
||||
try {
|
||||
handler(obj, getTransaction(obj));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
error(obj, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
setName(this.getClass().getSimpleName());
|
||||
super.afterPropertiesSet();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.hccake.starter.pay.viratual;
|
||||
|
||||
/**
|
||||
* 线程处理对象需要实现此类
|
||||
*
|
||||
* @author lingting 2021/1/5 11:15
|
||||
*/
|
||||
public interface VerifyObj {
|
||||
|
||||
/**
|
||||
* 获取当前订单的交易hash
|
||||
* @return java.lang.String
|
||||
* @author lingting 2021-01-05 11:15
|
||||
*/
|
||||
String getHash();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.hccake.starter.pay.PayAutoConfiguration
|
||||
@@ -25,6 +25,7 @@
|
||||
<module>ballcat-spring-boot-starter-swagger</module>
|
||||
<module>ballcat-spring-boot-starter-sms</module>
|
||||
<module>ballcat-spring-boot-starter-websocket</module>
|
||||
<module>ballcat-spring-boot-starter-pay</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user