新版仿ok交易所-后端
1
zj
8 hours ago be8c9767089b5e52ed462ea1d083d846e7420a45
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
@@ -3,6 +3,8 @@
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;
@@ -83,33 +85,12 @@
     */
    @RequestMapping(action + "list.action")
    public Object list() throws IOException {
        List<ChannelBlockchain> data = new ArrayList<ChannelBlockchain>();
        String partyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(partyId);
        List<PartyBlockchain> list = partyBlockchainService.findByUserName(party.getUserName());
        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.setBlockchainName(chainName);
                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 = channelBlockchainService.list();
        List<ChannelBlockchain> data = buildAddressList(party, null);
        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).setImg(path);
@@ -122,10 +103,66 @@
        return Result.succeed(data);
    }
    @GetMapping(action + "getBlockchainName.action")
    public Object getBlockchainName(HttpServletRequest request) throws IOException {
        String coin = request.getParameter("coin");
        String partyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(partyId);
        if (0 == this.sysparaService.find("can_recharge").getInteger()) {
            return Result.failed("请联系客服充值");
        }
        List<ChannelBlockchain> data = buildAddressList(party, coin);
        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())) {
                    QrConfig config = new QrConfig(150, 150);
                    config.setMargin(3);
                    String qr = QrCodeUtil.generateAsBase64(data.get(i).getAddress(), config, "png");
                    data.get(i).setImgStr(qr);
                }
            } else {
                data.get(i).setImg(null);
                data.get(i).setImgStr(null);
                data.get(i).setAddress(null);
            }
        }
        return Result.succeed(data);
    }
    private List<ChannelBlockchain> buildAddressList(User party, String coin) {
        List<ChannelBlockchain> templates = StringUtils.isNullOrEmpty(coin)
                ? channelBlockchainService.list()
                : channelBlockchainService.findByCoin(coin.toLowerCase());
        List<PartyBlockchain> partyList = StringUtils.isNullOrEmpty(coin)
                ? partyBlockchainService.findByUserName(party.getUserName())
                : partyBlockchainService.findByUserNameAndCoinSymbol(party.getUserName(), coin);
        Map<String, String> customAddresses = new HashMap<>();
        for (PartyBlockchain pb : partyList) {
            customAddresses.put(addressKey(pb.getCoinSymbol(), pb.getChainName()), pb.getAddress());
        }
        return templates.stream().map(template -> {
            ChannelBlockchain cbc = new ChannelBlockchain();
            cbc.setUuid(template.getUuid());
            cbc.setCoin(template.getCoin());
            cbc.setBlockchainName(template.getBlockchainName());
            cbc.setBlockchain_name(template.getBlockchainName());
            cbc.setAuto(template.isAuto());
            cbc.setImg(template.getImg());
            String key = addressKey(template.getCoin(), template.getBlockchainName());
            cbc.setAddress(customAddresses.getOrDefault(key, template.getAddress()));
            return cbc;
        }).collect(Collectors.toList());
    }
    private String addressKey(String coin, String chain) {
        return (coin == null ? "" : coin.toLowerCase()) + "|" + (chain == null ? "" : chain.toLowerCase());
    }
    /**
     * 根据币种获取链地址
     */
    @GetMapping(action + "getBlockchainName.action")
    /*@GetMapping(action + "getBlockchainName.action")
    public Object getBlockchainName(HttpServletRequest request) throws Exception {
        String coin = request.getParameter("coin");
        coin = coin.toLowerCase();
@@ -136,7 +173,7 @@
        try {
            String partyId = SecurityUtils.getUser().getUserId();
            /*HttpGet requestRemote = new HttpGet("https://liren.ak-web3.com/crypto/getAddress?project=md");
            *//*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();
@@ -211,7 +248,7 @@
                    blockchain.setImg(null);
                    data.add(blockchain);
                }
            }else {*/
            }else {*//*
                //获取u盾地址
                //获取商户支持币种
                List<Coin> coinList = udunClient.listSupportCoin(false);
@@ -254,7 +291,7 @@
            return Result.failed("充值链暂不可用");
        }
        return Result.succeed(data);
    }
    }*/
    @PostMapping(action +"rechargeCallback.action")
    public ResultMsg rechargeCallback(HttpServletRequest request){
@@ -373,7 +410,7 @@
            Response response = okHttpClient.newCall(requestParm).execute();
            result = response.body().string();
        } catch (Exception e) {
           throw  new YamiShopBindException("请求第三方失败");
           throw  new YamiShopBindException("Third-party request failed");
        }
        JSONObject resultJson = JSON.parseObject(result);
        Integer code = resultJson.getInteger("code");