新版仿ok交易所-后端
1
zj
2025-12-04 a26015e5d93b6ebfd3c67ac45f7da1a87c0f489b
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
@@ -8,14 +8,17 @@
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.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,6 +35,8 @@
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;
@@ -39,7 +44,10 @@
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;
@@ -65,6 +73,8 @@
    private SysUserService sysUserService;
    @Autowired
    RechargeBlockchainOrderService rechargeBlockchainOrderService;
    @Autowired
    protected UserService partyService;
    private final String gateway =  "https://sig11.udun.io";
    private final String merchantKey =  "7fd79e4ed59e7c31e1fa2e13d64f7e6c";
@@ -129,103 +139,59 @@
        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());
        }
            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);
        //后台设置地址
        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("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);
        }
//        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);