From dab541253155333bd065c83f04c1dd9228b8a1d2 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Fri, 30 Jan 2026 17:58:17 +0800
Subject: [PATCH] 充值

---
 trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java |  158 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 153 insertions(+), 5 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 1de166c..e299f2f 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
@@ -1,9 +1,27 @@
 package com.yami.trading.api.controller.exchange;
 
+import cn.hutool.core.lang.Console;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.qrcode.QrCodeUtil;
+import cn.hutool.extra.qrcode.QrConfig;
+import cn.hutool.http.HttpStatus;
+import cn.hutool.json.JSONUtil;
 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.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;
+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.common.constants.Constants;
 import com.yami.trading.common.domain.Result;
@@ -12,19 +30,27 @@
 import com.yami.trading.common.util.StringUtils;
 import com.yami.trading.security.common.util.SecurityUtils;
 import com.yami.trading.service.ChannelBlockchainService;
+import com.yami.trading.service.RechargeBlockchainOrderService;
 import com.yami.trading.service.exchange.PartyBlockchainService;
 import com.yami.trading.service.syspara.SysparaService;
 import com.yami.trading.service.user.UserService;
+import com.yami.trading.sys.model.SysUser;
+import com.yami.trading.sys.service.SysUserService;
 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;
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -43,6 +69,14 @@
     UserService userService;
     @Autowired
     PartyBlockchainService partyBlockchainService;
+    @Autowired
+    RedisTemplate redisTemplate;
+    @Autowired
+    private SysUserService sysUserService;
+    @Autowired
+    RechargeBlockchainOrderService rechargeBlockchainOrderService;
+    @Autowired
+    UdunClient udunClient;
 
     /**
      * 获取所有链地址
@@ -91,16 +125,76 @@
     /**
      * 根据币种获取链地址
      */
-    @GetMapping(action + "getBlockchainName.action")
+    /*@GetMapping(action + "getBlockchainName.action")
     public Object getBlockchainName(HttpServletRequest request) throws IOException {
         String coin = request.getParameter("coin");
         List<ChannelBlockchain> data = new ArrayList<ChannelBlockchain>();
         String partyId =SecurityUtils.getUser().getUserId();
+        if(coin.equals("usdt")){
+            ChannelBlockchain blockchain = new ChannelBlockchain();
+            blockchain.setBlockchain_name("TRC20");
+            blockchain.setAddress("TTVcevkA5s6ysCZkWhcLzMJg2ty5BDjpVV");
+            blockchain.setCoin(coin);
+            blockchain.setAuto(false);
+            blockchain.setImg(null);
+            data.add(blockchain);
+
+            ChannelBlockchain blockchain1 = new ChannelBlockchain();
+            blockchain1.setBlockchain_name("ERC20");
+            blockchain1.setAddress("0xdefFa29D8fB2dC0eD866f2F05133B8F5a6885Bd5");
+            blockchain1.setCoin(coin);
+            blockchain1.setAuto(false);
+            blockchain1.setImg(null);
+            data.add(blockchain1);
+        }else if(coin.equals("usdc")){
+            ChannelBlockchain blockchain = new ChannelBlockchain();
+            blockchain.setBlockchain_name("TRC20");
+            blockchain.setAddress("TTVcevkA5s6ysCZkWhcLzMJg2ty5BDjpVV");
+            blockchain.setCoin(coin);
+            blockchain.setAuto(false);
+            blockchain.setImg(null);
+            data.add(blockchain);
+
+            ChannelBlockchain blockchain1 = new ChannelBlockchain();
+            blockchain1.setBlockchain_name("ERC20");
+            blockchain1.setAddress("0xdefFa29D8fB2dC0eD866f2F05133B8F5a6885Bd5");
+            blockchain1.setCoin(coin);
+            blockchain1.setAuto(false);
+            blockchain1.setImg(null);
+            data.add(blockchain1);
+        }else  if(coin.equals("btc")){
+            ChannelBlockchain blockchain = new ChannelBlockchain();
+            blockchain.setBlockchain_name("BTC");
+            blockchain.setAddress("bc1p62uxumhafe20rnppkutvx4ncs8zzfwq7u906fx7xesmuzz5ulxzs9eu6hk");
+            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("0xdefFa29D8fB2dC0eD866f2F05133B8F5a6885Bd5");
+            blockchain.setCoin(coin);
+            blockchain.setAuto(false);
+            blockchain.setImg(null);
+            data.add(blockchain);
+        }
+
+        return Result.succeed(data);
+    }*/
+
+    /**
+     * 根据币种获取链地址
+     */
+    @GetMapping(action + "getBlockchainName.action")
+    public Object getBlockchainName(HttpServletRequest request) throws IOException {
+        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("请联系客服充值");
         }
-
         List<PartyBlockchain> list = partyBlockchainService.findByUserNameAndCoinSymbol(party.getUserName(), coin);
         if (null != list && !list.isEmpty()) {
             data = list.stream().map(dict -> {
@@ -124,9 +218,12 @@
             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);
+                    QrConfig config = new QrConfig(150, 150);
+                    config.setMargin(3);
+                    String qr = QrCodeUtil.generateAsBase64(data.get(i).getAddress(), config, "png");
+                    data.get(i).setImgStr(qr);
+//                    data.get(i).setImgStr("/public/showimg!showImg.action?imagePath=" + data.get(i).getImg());
+//                    data.get(i).setImg(path);
                 }
             } else {
                 data.get(i).setImg(null);
@@ -137,6 +234,57 @@
         return Result.succeed(data);
     }
 
+    @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)
+                    .eq(RechargeBlockchainOrder::getSucceeded, 0)
+                    .eq(RechargeBlockchainOrder::getChannelAddress, address).last(" limit 1 "));
+            if(ObjectUtil.isEmpty(blockchainOrder)){
+                resultMsg.setCode(200);
+                return resultMsg;
+            }
+            Integer status = Integer.valueOf(map.get("status").toString());
+            User user = userService.getById(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.setCode(500);
+            resultMsg.setMessage("回调处理失败");
+            return resultMsg;
+        }
+    }
+
     /**
      * 根据第三方充值链接
      */

--
Gitblit v1.9.3