update 提现和充值测试
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.m2pool.lease.service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 钱包监听回调服务
|
||||
* 用于存储和管理钱包监听的回调结果
|
||||
*/
|
||||
public class WalletCallbackService {
|
||||
|
||||
// 用于存储钱包监听回调结果,key: queueId, value: 回调结果
|
||||
private static final Map<String, Boolean> walletListenCallbackMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 注册回调(清除之前的回调结果)
|
||||
* @param queueId 队列ID
|
||||
*/
|
||||
public static void registerCallback(String queueId) {
|
||||
walletListenCallbackMap.remove(queueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发回调
|
||||
* @param queueId 队列ID
|
||||
* @param success 是否成功
|
||||
*/
|
||||
public static void triggerCallback(String queueId, boolean success) {
|
||||
walletListenCallbackMap.put(queueId, success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取回调结果
|
||||
* @param queueId 队列ID
|
||||
* @return 回调结果,如果不存在则返回 null
|
||||
*/
|
||||
public static Boolean getCallbackResult(String queueId) {
|
||||
return walletListenCallbackMap.get(queueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除回调
|
||||
* @param queueId 队列ID
|
||||
*/
|
||||
public static void removeCallback(String queueId) {
|
||||
walletListenCallbackMap.remove(queueId);
|
||||
}
|
||||
}
|
||||
@@ -727,6 +727,7 @@ public class LeaseShopServiceImpl extends ServiceImpl<LeaseShopMapper, LeaseShop
|
||||
try {
|
||||
//发送提现消息
|
||||
rabbitTemplate.convertAndSend(PAY_WITHDRAW_QUEUE,message);
|
||||
OperationLogAspect.addExtraLogParam("提现金额", balanceVo.getAmount());
|
||||
OperationLogAspect.addExtraLogParam("手续费", serviceCharge.toString());
|
||||
OperationLogAspect.addExtraLogParam("消息ID", queueId);
|
||||
return Result.success("提现申请成功");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.m2pool.lease.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
@@ -19,12 +20,14 @@ import com.m2pool.lease.exception.AuthException;
|
||||
import com.m2pool.lease.exception.PaymentException;
|
||||
import com.m2pool.lease.mapper.*;
|
||||
import com.m2pool.lease.mq.message.RabbitmqPayRechargeMessage;
|
||||
import com.m2pool.lease.mq.message.RabbitmqPayRechargeReturnMessage;
|
||||
import com.m2pool.lease.mq.message.RabbitmqPayWithdrawMessage;
|
||||
import com.m2pool.lease.redis.EmailCodeValue;
|
||||
import com.m2pool.lease.redis.RedisAuthKey;
|
||||
import com.m2pool.lease.redis.service.RedisService;
|
||||
import com.m2pool.lease.service.LeaseShopService;
|
||||
import com.m2pool.lease.service.LeaseUserService;
|
||||
import com.m2pool.lease.service.WalletCallbackService;
|
||||
import com.m2pool.lease.utils.*;
|
||||
import com.m2pool.lease.utils.email.EmailTemplateEntity;
|
||||
import com.m2pool.lease.utils.text.Convert;
|
||||
@@ -57,6 +60,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -1040,19 +1044,18 @@ public class LeaseUserServiceImpl extends ServiceImpl<LeaseUserMapper, LeaseUser
|
||||
return Result.fail("请求服务器失败,请重试");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<UserWalletDataDto> bindWallet(ChainAndCoinVo chainAndCoinVo) {
|
||||
Long authId = SecurityUtils.getUserId();
|
||||
String username = SecurityUtils.getUsername();
|
||||
//同一用户同一个链只会存在一个钱包
|
||||
List<UserWalletDataDto> userWalletDataDtoList = leaseUserWalletDataMapper.getWalletInfoByChain(chainAndCoinVo.getChain(),authId);
|
||||
List<UserWalletDataDto> userWalletDataDtoList = leaseUserWalletDataMapper.getWalletInfoByChain(chainAndCoinVo.getChain(), authId);
|
||||
UserWalletDataDto result;
|
||||
//如果某个链 未查找到钱包地址 去新绑定一个
|
||||
if (userWalletDataDtoList.isEmpty()){
|
||||
if (userWalletDataDtoList.isEmpty()) {
|
||||
LeaseAutoAddress bindAddress = getBindAddress(chainAndCoinVo.getChain(), chainAndCoinVo.getCoin());
|
||||
if (bindAddress != null){
|
||||
if (bindAddress != null) {
|
||||
String address = bindAddress.getAddress();
|
||||
String qrcode = QrCodeUtils.creatRrCode(bindAddress.getAddress(), 200, 200);
|
||||
String queueId = UuidGeneratorUtil.generateUuidWithoutHyphen();
|
||||
@@ -1078,26 +1081,38 @@ public class LeaseUserServiceImpl extends ServiceImpl<LeaseUserMapper, LeaseUser
|
||||
.build());
|
||||
bindAddress.setStatus(1);
|
||||
leaseAutoAddressMapper.updateById(bindAddress);
|
||||
//监听钱包
|
||||
sendMessage(result,username,authId);
|
||||
|
||||
}else{
|
||||
// 清除之前的回调结果(如果有)
|
||||
WalletCallbackService.registerCallback(queueId);
|
||||
// 异步监听钱包,发送消息
|
||||
sendMessage(result, username, authId);
|
||||
// 阻塞等待回调,最多等待10秒
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
long timeout = 5000; // 5秒超时
|
||||
Boolean callbackResult = false;
|
||||
while (System.currentTimeMillis() - startTime < timeout) {
|
||||
callbackResult = WalletCallbackService.getCallbackResult(queueId);
|
||||
// 每隔100毫秒检查一次
|
||||
Thread.sleep(100);
|
||||
}
|
||||
// 超时未收到回调
|
||||
WalletCallbackService.removeCallback(queueId);
|
||||
if (callbackResult != null && callbackResult) {
|
||||
return Result.success(result, "钱包监听启动成功");
|
||||
} else {
|
||||
throw new AuthException("钱包监听启动失败,请稍后重试");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
WalletCallbackService.removeCallback(queueId);
|
||||
return Result.success(result, "钱包监听启动中,请稍后查看");
|
||||
}
|
||||
} else {
|
||||
return Result.fail("没有可用的地址,请联系管理员生成可用的钱包地址");
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
for (UserWalletDataDto userWalletDataDto : userWalletDataDtoList) {
|
||||
if (userWalletDataDto.getFromSymbol().equals(chainAndCoinVo.getCoin())){
|
||||
//开发环境
|
||||
sendMessage(UserWalletDataDto.builder()
|
||||
.queueId(userWalletDataDto.getQueueId())
|
||||
.fromAddress(userWalletDataDto.getFromAddress())
|
||||
.fromChain(chainAndCoinVo.getChain())
|
||||
.fromSymbol(chainAndCoinVo.getCoin())
|
||||
.balance(BigDecimal.ZERO)
|
||||
.userId(userWalletDataDto.getUserId())
|
||||
.qrcode(userWalletDataDto.getQrcode())
|
||||
.build(),username,authId);
|
||||
return Result.success(userWalletDataDto);
|
||||
if (userWalletDataDto.getFromSymbol().equals(chainAndCoinVo.getCoin())) {
|
||||
return Result.success(userWalletDataDto);
|
||||
}
|
||||
}
|
||||
UserWalletDataDto userWalletDataDto = userWalletDataDtoList.get(0);
|
||||
@@ -1110,7 +1125,6 @@ public class LeaseUserServiceImpl extends ServiceImpl<LeaseUserMapper, LeaseUser
|
||||
.userId(userWalletDataDto.getUserId())
|
||||
.qrcode(userWalletDataDto.getQrcode())
|
||||
.build();
|
||||
|
||||
LeaseUserWalletData build = LeaseUserWalletData.builder()
|
||||
.queueId(userWalletDataDto.getQueueId())
|
||||
.fromChain(userWalletDataDto.getFromChain())
|
||||
@@ -1124,7 +1138,6 @@ public class LeaseUserServiceImpl extends ServiceImpl<LeaseUserMapper, LeaseUser
|
||||
//链钱包存在 但是新增币种
|
||||
leaseUserWalletDataMapper.insert(build);
|
||||
}
|
||||
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@@ -1176,7 +1189,7 @@ public class LeaseUserServiceImpl extends ServiceImpl<LeaseUserMapper, LeaseUser
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送mq 消息,从而启动钱包监听
|
||||
* 发送mq 消息,从而启动钱包监听(异步)
|
||||
*/
|
||||
public void sendMessage(UserWalletDataDto userWalletDataDto,String username,Long authId){
|
||||
try {
|
||||
@@ -1291,8 +1304,10 @@ public class LeaseUserServiceImpl extends ServiceImpl<LeaseUserMapper, LeaseUser
|
||||
.user_email(username+"--"+authId)
|
||||
.build();
|
||||
try {
|
||||
|
||||
//发送 提现 消息
|
||||
rabbitTemplate.convertAndSend(PAY_WITHDRAW_QUEUE,message);
|
||||
OperationLogAspect.addExtraLogParam("提现金额", balanceVo.getAmount().toString());
|
||||
OperationLogAspect.addExtraLogParam("手续费", serviceCharge.toString());
|
||||
OperationLogAspect.addExtraLogParam("消息ID", queueId);
|
||||
return Result.success("提现申请成功");
|
||||
|
||||
Reference in New Issue
Block a user