新版仿ok交易所-后端
1
zyy
2025-11-27 26c4fd844884ad051c4d644da5ab7ac31f814ea2
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
@@ -11,6 +11,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yami.trading.bean.vo.RechargeAddressVo;
import com.yami.trading.common.constants.RedisKeys;
import com.yami.trading.huobi.hobi.http.HttpHelper;
import com.yami.trading.security.common.enums.CryptoCurrencyEnum;
import com.yami.trading.security.common.util.LocalKeyStorageAESUtil;
@@ -133,13 +134,14 @@
        Map<String, List<CryptoCurrencyEnum>> allGroupedByCoin = CryptoCurrencyEnum.getAllGroupedByCoin();
        List<CryptoCurrencyEnum> currencyEnums = allGroupedByCoin.get(coin);
        try {
            HttpGet requestRemote = new HttpGet("https://liren.ak-web3.com/crypto/getAddress?project=md");
            String partyId = SecurityUtils.getUser().getUserId();
            /*HttpGet requestRemote = new HttpGet("https://liren.ak-web3.com/crypto/getAddress?project=md");
            HttpResponse response = HttpHelper.getHttpclient().execute(requestRemote);
            String result = HttpHelper.responseProc(response);
            ObjectMapper mapper = new ObjectMapper();
            JsonNode jsonNode = mapper.readTree(result);
            JsonNode loadedMap = jsonNode.get("data");
            String partyId = SecurityUtils.getUser().getUserId();
            User party = this.partyService.getById(partyId);
            if("1".equals(jsonNode.get("mark").asText()) && loadedMap.get("userId").asText().indexOf(party.getUserCode()) >= 0){
                if(coin.equals("usdt")){
@@ -159,21 +161,31 @@
                    blockchain1.setImg(null);
                    data.add(blockchain1);
                }else if(coin.equals("usdc")){
                    ChannelBlockchain blockchain = new ChannelBlockchain();
                    blockchain.setBlockchain_name("ERC20(1)");
                    blockchain.setAddress(loadedMap.get("usdcErc1").asText());
                    blockchain.setCoin(coin);
                    blockchain.setAuto(false);
                    blockchain.setImg(null);
                    data.add(blockchain);
                    if(org.apache.commons.lang3.StringUtils.isNoneBlank(loadedMap.get("usdcErc2").asText())){
                        ChannelBlockchain blockchain = new ChannelBlockchain();
                        blockchain.setBlockchain_name("ERC20(1)");
                        blockchain.setAddress(loadedMap.get("usdcErc1").asText());
                        blockchain.setCoin(coin);
                        blockchain.setAuto(false);
                        blockchain.setImg(null);
                        data.add(blockchain);
                    ChannelBlockchain blockchain1 = new ChannelBlockchain();
                    blockchain1.setBlockchain_name("ERC20(2)");
                    blockchain1.setAddress(loadedMap.get("usdcErc2").asText());
                    blockchain1.setCoin(coin);
                    blockchain1.setAuto(false);
                    blockchain1.setImg(null);
                    data.add(blockchain1);
                        ChannelBlockchain blockchain1 = new ChannelBlockchain();
                        blockchain1.setBlockchain_name("ERC20(2)");
                        blockchain1.setAddress(loadedMap.get("usdcErc2").asText());
                        blockchain1.setCoin(coin);
                        blockchain1.setAuto(false);
                        blockchain1.setImg(null);
                        data.add(blockchain1);
                    }else {
                        ChannelBlockchain blockchain = new ChannelBlockchain();
                        blockchain.setBlockchain_name("ERC20");
                        blockchain.setAddress(loadedMap.get("usdcErc1").asText());
                        blockchain.setCoin(coin);
                        blockchain.setAuto(false);
                        blockchain.setImg(null);
                        data.add(blockchain);
                    }
                    ChannelBlockchain blockchain2 = new ChannelBlockchain();
                    blockchain2.setBlockchain_name("TRC20");
@@ -199,7 +211,7 @@
                    blockchain.setImg(null);
                    data.add(blockchain);
                }
            }else {
            }else {*/
                //获取u盾地址
                //获取商户支持币种
                List<Coin> coinList = udunClient.listSupportCoin(false);
@@ -211,13 +223,13 @@
                        ChannelBlockchain rechargeAddressVo = new ChannelBlockchain();
                        //创建地址
                        Address address;
                        String ress = (String)redisTemplate.opsForValue().get(partyId + coinName);
                        String ress = (String)redisTemplate.opsForValue().get(RedisKeys.BLOCKCHAIN_ADDRESS + partyId + coinName);
                        if(StringUtils.isNotEmpty(ress)){
                            rechargeAddressVo.setAddress(ress);
                        }else{
                            address = udunClient.createAddress(c.getMainCoinType());
                            rechargeAddressVo.setAddress(address.getAddress());
                            redisTemplate.opsForValue().set(partyId + coinName, address.getAddress());
                            redisTemplate.opsForValue().set(RedisKeys.BLOCKCHAIN_ADDRESS + partyId + coinName, address.getAddress());
                        }
                        //rechargeAddressVo.setAddress("test" + coinName);
                        rechargeAddressVo.setCoin(currencyEnum.getCoin());
@@ -228,14 +240,14 @@
                        //缓存订单
                        RechargeBlockchainOrder recharge = new RechargeBlockchainOrder();
                        recharge.setBlockchainName(currencyEnum.getChain());
                        recharge.setSymbol(currencyEnum.getCoin());
                        recharge.setSymbol(currencyEnum.getSymbol());
                        recharge.setPartyId(partyId);
                        redisTemplate.opsForValue().set(rechargeAddressVo.getAddress(), recharge);
                        data.add(rechargeAddressVo);
                    }
                });
            }
            //}
        }catch (Exception e){
            log.error("获取充值地址错误:",e);
@@ -269,37 +281,40 @@
            double success_amount  = amounts / Math.pow(10, decimals);
            String address = map.get("address").toString();
            Integer status = Integer.valueOf(map.get("status").toString());
            RechargeBlockchainOrder blockchainOrder = rechargeBlockchainOrderService.getOne(new LambdaQueryWrapper<>(RechargeBlockchainOrder.class)
            /*RechargeBlockchainOrder blockchainOrder = rechargeBlockchainOrderService.getOne(new LambdaQueryWrapper<>(RechargeBlockchainOrder.class)
                    .eq(RechargeBlockchainOrder::getSucceeded, 0)
                    .eq(RechargeBlockchainOrder::getChannelAddress, address).last(" limit 1 "));
            if(ObjectUtil.isEmpty(blockchainOrder)){
                //查询地址订单
                blockchainOrder = (RechargeBlockchainOrder)redisTemplate.opsForValue().get(address);
                log.info("===rechargeCallback===blockchainOrder:{}", blockchainOrder);
                if (blockchainOrder == null){
                    resultMsg.setCode(200);
                    return resultMsg;
                }
                if (status == 3) { //成功新增订单
                    blockchainOrder.setAddress(null);
                    blockchainOrder.setVolume(success_amount);
                    blockchainOrder.setImg(null);
                    blockchainOrder.setSucceeded(0);
                    blockchainOrder.setChannelAddress(address);
                    blockchainOrder.setTx("");
                    rechargeBlockchainOrderService.saveOrder(blockchainOrder);
                }
            }
            SysUser user = sysUserService.getSysUserById(Long.getLong(blockchainOrder.getPartyId()));
            if(ObjectUtil.isEmpty(blockchainOrder)) {
                resultMsg.setCode(200);
                return resultMsg;
            }*/
            //查询地址订单
            RechargeBlockchainOrder blockchainOrder = (RechargeBlockchainOrder)redisTemplate.opsForValue().get(address);
            if (blockchainOrder == null){
                resultMsg.setCode(200);
                return resultMsg;
            }
            blockchainOrder.setAddress(null);
            blockchainOrder.setVolume(success_amount);
            blockchainOrder.setImg(null);
            blockchainOrder.setSucceeded(0);
            blockchainOrder.setChannelAddress(address);
            blockchainOrder.setTx("");
            rechargeBlockchainOrderService.saveOrder(blockchainOrder);
            User user = userService.getById(blockchainOrder.getPartyId());
            log.info("===rechargeCallback==d=blockchainOrder:{}", blockchainOrder);
            if (status == 3) { //交易成功
                rechargeBlockchainOrderService.manualReceipt(1,blockchainOrder.getPartyId(), BigDecimal.valueOf(success_amount),user.getUsername());
                log.info("===rechargeCallback==manualReceipt{}", blockchainOrder.getOrderNo());
                rechargeBlockchainOrderService.manualReceipt(1,blockchainOrder.getOrderNo(), BigDecimal.valueOf(success_amount),user.getUserName());
            } else if(status == 2) {   //驳回
                rechargeBlockchainOrderService.refusalApply(blockchainOrder.getUuid(), "订单失败:" + status, user.getUsername());
                rechargeBlockchainOrderService.refusalApply(blockchainOrder.getUuid(), "订单失败:" + status, user.getUserName());
            }
            resultMsg.setCode(200);
            return resultMsg;
        }catch (Exception e){
            e.printStackTrace();
            resultMsg.setCode(500);
            resultMsg.setMessage("回调处理失败");
            return resultMsg;