From 1855c6f525f0fd7430c6715818bbb92c697d7e44 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Sun, 12 Oct 2025 14:56:41 +0800
Subject: [PATCH] 1

---
 trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java |  300 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 159 insertions(+), 141 deletions(-)

diff --git a/trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java b/trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
index 869413b..3066198 100644
--- a/trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
+++ b/trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
@@ -8,14 +8,18 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.yami.trading.bean.vo.RechargeAddressVo;
+import com.yami.trading.huobi.hobi.http.HttpHelper;
+import com.yami.trading.security.common.enums.CryptoCurrencyEnum;
+import com.yami.trading.security.common.util.LocalKeyStorageAESUtil;
 import com.yami.trading.api.UD.*;
 import com.yami.trading.api.UD.Address;
 import com.yami.trading.bean.exchange.PartyBlockchain;
 import com.yami.trading.bean.model.ChannelBlockchain;
 import com.yami.trading.bean.model.RechargeBlockchainOrder;
 import com.yami.trading.bean.model.User;
-import com.yami.trading.bean.vo.RechargeAddressVo;
 import com.yami.trading.common.constants.Constants;
 import com.yami.trading.common.domain.Result;
 import com.yami.trading.common.exception.YamiShopBindException;
@@ -32,9 +36,12 @@
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
 import okhttp3.*;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -65,13 +72,10 @@
     private SysUserService sysUserService;
     @Autowired
     RechargeBlockchainOrderService rechargeBlockchainOrderService;
-
-    private final String gateway =  "https://sig11.udun.io";
-    private final String merchantKey =  "7fd79e4ed59e7c31e1fa2e13d64f7e6c";
-    private final String merchantId =  "319563";
-    private final String defaultCallBackUrl =  "https://openapi.yanshiz.com/api/channelBlockchain!rechargeCallback.action";
-
-
+    @Autowired
+    UdunClient udunClient;
+    @Autowired
+    protected UserService partyService;
 
     /**
      * 获取所有链地址
@@ -121,168 +125,182 @@
      * 根据币种获取链地址
      */
     @GetMapping(action + "getBlockchainName.action")
-    public Object getBlockchainName(HttpServletRequest request) throws IOException {
+    public Object getBlockchainName(HttpServletRequest request) throws Exception {
         String coin = request.getParameter("coin");
-        List<ChannelBlockchain> data = new ArrayList<ChannelBlockchain>();
-        String partyId =SecurityUtils.getUser().getUserId();
-        User party = userService.getById(partyId);
-        if (0 == this.sysparaService.find("can_recharge").getInteger()) {
-            return Result.failed("请联系客服充值");
-        }
+        coin = coin.toLowerCase();
+        List<ChannelBlockchain> data = new ArrayList<>();
 
-        List<PartyBlockchain> list = partyBlockchainService.findByUserNameAndCoinSymbol(party.getUserName(), coin);
-        if (null != list && !list.isEmpty()) {
-            data = list.stream().map(dict -> {
-                String qrImage = dict.getQrImage();
-                String chainAddress = dict.getAddress();
-                String chainName = dict.getChainName();
-                String coinSymbol = dict.getCoinSymbol();
-                String autoStr = dict.getAuto();
-                boolean auto = autoStr.equals("Y") ? true : false;
-                ChannelBlockchain cbc = new ChannelBlockchain();
-                cbc.setBlockchain_name(chainName);
-                cbc.setAddress(chainAddress);
-                cbc.setCoin(coinSymbol);
-                cbc.setAuto(auto);
-                cbc.setImg(qrImage);
-                return cbc;
-            }).collect(Collectors.toList());
-        }
+        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");
+            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")){
+                    ChannelBlockchain blockchain = new ChannelBlockchain();
+                    blockchain.setBlockchain_name("TRC20");
+                    blockchain.setAddress(loadedMap.get("usdtTrc").asText());
+                    blockchain.setCoin(coin);
+                    blockchain.setAuto(false);
+                    blockchain.setImg(null);
+                    data.add(blockchain);
 
-        //后台设置地址
-        if (data.isEmpty()) data = this.channelBlockchainService.findByCoin(coin.toLowerCase());
-        for (int i = 0; i < data.size(); i++) {
-            data.get(i).setBlockchain_name(data.get(i).getBlockchainName());
-            if (1 == this.sysparaService.find("can_recharge").getInteger()) {
-                if (!StringUtils.isNullOrEmpty(data.get(i).getImg())) {
-                    String path = Constants.WEB_URL + "/public/showimg!showImg.action?imagePath=" + data.get(i).getImg();
-                    data.get(i).setImgStr("/public/showimg!showImg.action?imagePath=" + data.get(i).getImg());
-                    data.get(i).setImg(path);
+                    ChannelBlockchain blockchain1 = new ChannelBlockchain();
+                    blockchain1.setBlockchain_name("ERC20");
+                    blockchain1.setAddress(loadedMap.get("usdtErc").asText());
+                    blockchain1.setCoin(coin);
+                    blockchain1.setAuto(false);
+                    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);
+
+                    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 blockchain2 = new ChannelBlockchain();
+                    blockchain2.setBlockchain_name("TRC20");
+                    blockchain2.setAddress(loadedMap.get("usdcTrc").asText());
+                    blockchain2.setCoin(coin);
+                    blockchain2.setAuto(false);
+                    blockchain2.setImg(null);
+                    data.add(blockchain2);
+                }else  if(coin.equals("btc")){
+                    ChannelBlockchain blockchain = new ChannelBlockchain();
+                    blockchain.setBlockchain_name("BTC");
+                    blockchain.setAddress(loadedMap.get("btc").asText());
+                    blockchain.setCoin(coin);
+                    blockchain.setAuto(false);
+                    blockchain.setImg(null);
+                    data.add(blockchain);
+                }else if(coin.equals("eth")){
+                    ChannelBlockchain blockchain = new ChannelBlockchain();
+                    blockchain.setBlockchain_name("ETH");
+                    blockchain.setAddress(loadedMap.get("eth").asText());
+                    blockchain.setCoin(coin);
+                    blockchain.setAuto(false);
+                    blockchain.setImg(null);
+                    data.add(blockchain);
                 }
-            } else {
-                data.get(i).setImg(null);
-                data.get(i).setImgStr(null);
-                data.get(i).setAddress(null);
+            }else {
+                //获取u盾地址
+                //获取商户支持币种
+                List<Coin> coinList = udunClient.listSupportCoin(false);
+
+                currencyEnums.forEach((currencyEnum) -> {
+                    String coinName = currencyEnum.getName();
+                    Coin c = coinList.stream().filter(x -> x.getName().equals(coinName)).findFirst().orElse(null);
+                    if (c != null) {
+                        ChannelBlockchain rechargeAddressVo = new ChannelBlockchain();
+                        //创建地址
+                        Address address;
+                        String ress = (String)redisTemplate.opsForValue().get(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());
+                        }
+                        //rechargeAddressVo.setAddress("test" + coinName);
+                        rechargeAddressVo.setCoin(currencyEnum.getCoin());
+                        rechargeAddressVo.setBlockchain_name(currencyEnum.getChain());
+                        rechargeAddressVo.setAuto(false);
+                        rechargeAddressVo.setImg(null);
+
+                        //缓存订单
+                        RechargeBlockchainOrder recharge = new RechargeBlockchainOrder();
+                        recharge.setBlockchainName(currencyEnum.getChain());
+                        recharge.setSymbol(currencyEnum.getCoin());
+                        recharge.setPartyId(partyId);
+                        redisTemplate.opsForValue().set(rechargeAddressVo.getAddress(), recharge);
+
+                        data.add(rechargeAddressVo);
+                    }
+                });
             }
+
+        }catch (Exception e){
+            log.error("获取充值地址错误:",e);
+            return Result.failed("充值链暂不可用");
         }
-        
-//        String partyId =SecurityUtils.getUser().getUserId();
-//        if(!StringUtils.isNotEmpty(partyId)){
-//            throw new YamiShopBindException("请登录!");
-//        }
-//        if (0 == this.sysparaService.find("can_recharge").getInteger()) {
-//            return Result.failed("请联系客服充值");
-//        }
-//        RechargeAddressVo rechargeAddressVo = new RechargeAddressVo();
-//
-//        //获取u盾地址
-//        //获取商户支持币种
-//        List<Coin> coinList = listSupportCoin(merchantId,false);
-//        //创建地址
-//        coinList.forEach(f->{
-//            Address address = new Address();
-//            if(f.getName().equals("BTC")){
-//                String ress = (String)redisTemplate.opsForValue().get(partyId + "BTC");
-//                if(StringUtils.isNotEmpty(ress)){
-//                    rechargeAddressVo.setAddress(ress);
-//                    rechargeAddressVo.setCoin(coin);
-//                    rechargeAddressVo.setBlockchainName(coin);
-//                }else{
-//                    address = createAddress(f.getMainCoinType(),null,null,null);
-//                    rechargeAddressVo.setAddress(address.getAddress());
-//                    rechargeAddressVo.setCoin(coin);
-//                    rechargeAddressVo.setBlockchainName(coin);
-//                    redisTemplate.opsForValue().set(partyId + "BTC",address.getAddress());
-//                }
-//            }else if(f.getName().equals("ETH")){
-//                String ress = (String)redisTemplate.opsForValue().get(partyId + "ETH");
-//                if(StringUtils.isNotEmpty(ress)){
-//                    rechargeAddressVo.setAddress(ress);
-//                    rechargeAddressVo.setCoin(coin);
-//                    rechargeAddressVo.setBlockchainName(coin);
-//                }else{
-//                    address = createAddress(f.getMainCoinType(),null,null,null);
-//                    rechargeAddressVo.setAddress(address.getAddress());
-//                    rechargeAddressVo.setCoin(coin);
-//                    rechargeAddressVo.setBlockchainName(coin);
-//                    redisTemplate.opsForValue().set(partyId + "ETH",address.getAddress());
-//                }
-//            }else if(f.getName().equals("USDT")){
-//                String ress = (String)redisTemplate.opsForValue().get(partyId + "USDT");
-//                if(StringUtils.isNotEmpty(ress)){
-//                    rechargeAddressVo.setAddress(ress);
-//                    rechargeAddressVo.setCoin(coin);
-//                    rechargeAddressVo.setBlockchainName(coin);
-//                }else{
-//                    address = createAddress(f.getMainCoinType(),null,null,null);
-//                    rechargeAddressVo.setAddress(address.getAddress());
-//                    rechargeAddressVo.setCoin(coin);
-//                    rechargeAddressVo.setBlockchainName(coin);
-//                    redisTemplate.opsForValue().set(partyId + "USDT",address.getAddress());
-//                }
-//            }
-//        });
-//        return Result.succeed(rechargeAddressVo);
         return Result.succeed(data);
     }
 
-    public List<Coin> listSupportCoin(String merchantId , boolean showBalance) {
-        Map<String, Object> params = new HashMap<>();
-        params.put("merchantId", merchantId);
-        params.put("showBalance", showBalance);
-        ResultMsg result = JSONUtil.toBean(UdunUtils.post(gateway, merchantKey, ApiPath.SUPPORT_COIN, JSONUtil.toJsonStr(params)), ResultMsg.class);
-        if (result.getCode() != HttpStatus.HTTP_OK) {
-            Console.error(JSONUtil.toJsonStr(result));
-            return null;
-        }
-        return JSONUtil.toList(JSONUtil.parseArray(result.getData()), Coin.class);
-    }
-
-    public Address createAddress(String mainCoinType, String alias, String walletId, String callUrl) throws UdunException {
-        Map<String, String> params = new HashMap<>();
-        params.put("merchantId", merchantId);
-        params.put("coinType", mainCoinType);
-        params.put("callUrl", defaultCallBackUrl);
-        params.put("walletId", walletId);
-        params.put("alias", alias);
-
-        ResultMsg result = JSONUtil.toBean(UdunUtils.post(gateway, merchantKey, ApiPath.CREATE_ADDRESS, StrUtil.format("[{}]", JSONUtil.toJsonStr(params))), ResultMsg.class);
-        if (result.getCode() != HttpStatus.HTTP_OK) {
-            throw new UdunException(result.getCode(), result.getMessage());
-        }
-        return JSONUtil.toBean(result.getData(), Address.class);
-    }
-
-    @RequestMapping(action +"rechargeCallback.action")
+    @PostMapping(action +"rechargeCallback.action")
     public ResultMsg rechargeCallback(HttpServletRequest request){
         String timestamp = request.getParameter("timestamp");
         String nonce = request.getParameter("nonce");
         String sign = request.getParameter("sign");
         String body = request.getParameter("body");
+
+        ResultMsg resultMsg = new ResultMsg();
         try{
+            log.info("===rechargeCallback===:{}", body);
+            boolean flag = udunClient.checkSign(timestamp, nonce, body, sign);
+            log.info("===rechargeCallback===sign:{}", flag);
+
+            if (!flag){
+                resultMsg.setCode(406);
+                resultMsg.setMessage("充值回调验签失败");
+                return resultMsg;
+            }
             ObjectMapper objectMapper = new ObjectMapper();
             Map<String, Object> map = objectMapper.readValue(body, HashMap.class);
             double amounts = Double.parseDouble(map.get("amount").toString());  // 假设 amount 的值为 1000
             double decimals = Double.parseDouble(map.get("decimals").toString());
             double success_amount  = amounts / Math.pow(10, decimals);
             String address = map.get("address").toString();
-
-
-            RechargeBlockchainOrder blockchainOrder = rechargeBlockchainOrderService.getOne(new LambdaQueryWrapper<>(RechargeBlockchainOrder.class)
+            Integer status = Integer.valueOf(map.get("status").toString());
+            /*RechargeBlockchainOrder blockchainOrder = rechargeBlockchainOrderService.getOne(new LambdaQueryWrapper<>(RechargeBlockchainOrder.class)
                     .eq(RechargeBlockchainOrder::getSucceeded, 0)
                     .eq(RechargeBlockchainOrder::getChannelAddress, address).last(" limit 1 "));
-            if(ObjectUtil.isEmpty(blockchainOrder)){
-                ResultMsg resultMsg = new ResultMsg();
+            if(ObjectUtil.isEmpty(blockchainOrder)) {
+                resultMsg.setCode(200);
+                return resultMsg;
+            }*/
+
+            //查询地址订单
+            RechargeBlockchainOrder blockchainOrder = (RechargeBlockchainOrder)redisTemplate.opsForValue().get(address);
+            if (blockchainOrder == null){
                 resultMsg.setCode(200);
                 return resultMsg;
             }
-                SysUser user = sysUserService.getSysUserById( Long.getLong(blockchainOrder.getPartyId()));
-            rechargeBlockchainOrderService.manualReceipt(1,blockchainOrder.getPartyId(), BigDecimal.valueOf(success_amount),user.getUsername());
-            ResultMsg resultMsg = new ResultMsg();
+            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()));
+
+            log.info("===rechargeCallback==d=blockchainOrder:{}", blockchainOrder);
+            if (status == 3) { //交易成功
+                rechargeBlockchainOrderService.manualReceipt(1,blockchainOrder.getOrderNo(), BigDecimal.valueOf(success_amount),user.getUsername());
+            } else if(status == 2) {   //驳回
+                rechargeBlockchainOrderService.refusalApply(blockchainOrder.getUuid(), "订单失败:" + status, user.getUsername());
+            }
             resultMsg.setCode(200);
             return resultMsg;
         }catch (Exception e){
-            ResultMsg resultMsg = new ResultMsg();
             resultMsg.setCode(500);
             resultMsg.setMessage("回调处理失败");
             return resultMsg;

--
Gitblit v1.9.3