From db07dc37fda3ac90c6b8fd7eef6da8bf3c7aa1a1 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Mon, 01 Dec 2025 19:05:42 +0800
Subject: [PATCH] yml

---
 trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java |  182 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 150 insertions(+), 32 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..feea7fc 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,23 @@
 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.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.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 +26,29 @@
 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.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -43,6 +67,21 @@
     UserService userService;
     @Autowired
     PartyBlockchainService partyBlockchainService;
+    @Autowired
+    RedisTemplate redisTemplate;
+    @Autowired
+    private SysUserService sysUserService;
+    @Autowired
+    RechargeBlockchainOrderService rechargeBlockchainOrderService;
+    @Autowired
+    protected UserService partyService;
+
+    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";
+
+
 
     /**
      * 获取所有链地址
@@ -100,43 +139,122 @@
         if (0 == this.sysparaService.find("can_recharge").getInteger()) {
             return Result.failed("请联系客服充值");
         }
+        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);
 
-        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());
-        }
-        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);
-                }
-            } else {
-                data.get(i).setImg(null);
-                data.get(i).setImgStr(null);
-                data.get(i).setAddress(null);
-            }
+            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);
     }
 
+
+    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")
+    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");
+        try{
+            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 resultMsg = new ResultMsg();
+                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();
+            resultMsg.setCode(200);
+            return resultMsg;
+        }catch (Exception e){
+            ResultMsg resultMsg = new ResultMsg();
+            resultMsg.setCode(500);
+            resultMsg.setMessage("回调处理失败");
+            return resultMsg;
+        }
+    }
+
     /**
      * 根据第三方充值链接
      */

--
Gitblit v1.9.3