| | |
| | | package com.yami.trading.api.controller.exchange; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.lang.Console; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | @Autowired |
| | | protected UserService partyService; |
| | | |
| | | private String normalizeChainKey(String value) { |
| | | if (value == null) { |
| | | return ""; |
| | | } |
| | | return value.replace("-", "").replace("_", "").replace(" ", "").toUpperCase(Locale.ROOT); |
| | | } |
| | | |
| | | /** |
| | | * 获取所有链地址 |
| | | */ |
| | |
| | | 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 -> { |
| | | 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())) { |
| | | 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); |
| | | data.get(i).setImgStr(null); |
| | | data.get(i).setAddress(null); |
| | | } |
| | | } |
| | | 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 -> { |
| | | // 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())) { |
| | | // 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); |
| | | // data.get(i).setImgStr(null); |
| | | // data.get(i).setAddress(null); |
| | | // } |
| | | // } |
| | | // return Result.succeed(data); |
| | | // } |
| | | |
| | | /** |
| | | * 根据币种获取链地址 |
| | | */ |
| | | /*@GetMapping(action + "getBlockchainName.action") |
| | | public Object getBlockchainName(HttpServletRequest request) throws Exception { |
| | | String coin = request.getParameter("coin"); |
| | | coin = coin.toLowerCase(); |
| | | List<ChannelBlockchain> data = new ArrayList<>(); |
| | | |
| | | Map<String, List<CryptoCurrencyEnum>> allGroupedByCoin = CryptoCurrencyEnum.getAllGroupedByCoin(); |
| | | List<CryptoCurrencyEnum> currencyEnums = allGroupedByCoin.get(coin); |
| | | @GetMapping(action + "getBlockchainName.action") |
| | | public Object getBlockchainName(HttpServletRequest request) { |
| | | try { |
| | | String coin = request.getParameter("coin"); |
| | | |
| | | String partyId = SecurityUtils.getUser().getUserId(); |
| | | |
| | | *//*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"); |
| | | 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); |
| | | |
| | | 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")){ |
| | | if(org.apache.commons.lang3.StringUtils.isNoneBlank(loadedMap.get("usdcErc2").asText())){ |
| | | 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); |
| | | }else { |
| | | ChannelBlockchain blockchain = new ChannelBlockchain(); |
| | | blockchain.setBlockchain_name("ERC20"); |
| | | blockchain.setAddress(loadedMap.get("usdcErc1").asText()); |
| | | blockchain.setCoin(coin); |
| | | blockchain.setAuto(false); |
| | | blockchain.setImg(null); |
| | | data.add(blockchain); |
| | | coin = coin.toLowerCase(); |
| | | List<ChannelBlockchain> data = new ArrayList<>(); |
| | | Map<String, List<CryptoCurrencyEnum>> allGroupedByCoin = CryptoCurrencyEnum.getAllGroupedByCoin(); |
| | | List<CryptoCurrencyEnum> currencyEnums = allGroupedByCoin.get(coin); |
| | | List<Coin> coinList = udunClient.listSupportCoin(false); |
| | | if (CollectionUtil.isEmpty(currencyEnums) || CollectionUtil.isEmpty(coinList)) { |
| | | return Result.succeed(data); |
| | | } |
| | | currencyEnums.forEach((currencyEnum) -> { |
| | | String coinName = currencyEnum.getName(); |
| | | String normalizedCoinName = normalizeChainKey(coinName); |
| | | Coin c = coinList.stream().filter(x -> |
| | | normalizedCoinName.equals(normalizeChainKey(x.getName())) |
| | | || normalizedCoinName.equals(normalizeChainKey(x.getCoinType())) |
| | | || normalizedCoinName.equals(normalizeChainKey(x.getSymbol())) |
| | | || (normalizeChainKey(currencyEnum.getCoin()).equals(normalizeChainKey(x.getCoinType())) |
| | | && normalizeChainKey(currencyEnum.getChain()).contains("BSC") |
| | | && (normalizeChainKey(x.getName()).contains("BSC") |
| | | || normalizeChainKey(x.getMainCoinType()).contains("BSC") |
| | | || normalizeChainKey(x.getSymbol()).contains("BSC"))) |
| | | ).findFirst().orElse(null); |
| | | if (c != null) { |
| | | ChannelBlockchain rechargeAddressVo = new ChannelBlockchain(); |
| | | //创建地址 |
| | | Address address; |
| | | String ress = (String)redisTemplate.opsForValue().get(RedisKeys.BLOCKCHAIN_ADDRESS + partyId + coinName); |
| | | if(StringUtils.isNotEmpty(ress)){ |
| | | rechargeAddressVo.setAddress(ress); |
| | | }else{ |
| | | address = udunClient.createAddress(c.getMainCoinType()); |
| | | rechargeAddressVo.setAddress(address.getAddress()); |
| | | redisTemplate.opsForValue().set(RedisKeys.BLOCKCHAIN_ADDRESS + partyId + coinName, address.getAddress()); |
| | | } |
| | | rechargeAddressVo.setCoin(currencyEnum.getCoin()); |
| | | rechargeAddressVo.setBlockchain_name(currencyEnum.getChain()); |
| | | rechargeAddressVo.setAuto(false); |
| | | rechargeAddressVo.setImg(null); |
| | | |
| | | 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); |
| | | //缓存订单 |
| | | RechargeBlockchainOrder recharge = new RechargeBlockchainOrder(); |
| | | recharge.setBlockchainName(currencyEnum.getChain()); |
| | | recharge.setSymbol(currencyEnum.getCoin()); |
| | | recharge.setPartyId(partyId); |
| | | redisTemplate.opsForValue().set(rechargeAddressVo.getAddress(), recharge); |
| | | |
| | | data.add(rechargeAddressVo); |
| | | } |
| | | }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(RedisKeys.BLOCKCHAIN_ADDRESS + partyId + coinName); |
| | | if(StringUtils.isNotEmpty(ress)){ |
| | | rechargeAddressVo.setAddress(ress); |
| | | }else{ |
| | | address = udunClient.createAddress(c.getMainCoinType()); |
| | | rechargeAddressVo.setAddress(address.getAddress()); |
| | | redisTemplate.opsForValue().set(RedisKeys.BLOCKCHAIN_ADDRESS + 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.getSymbol()); |
| | | recharge.setPartyId(partyId); |
| | | redisTemplate.opsForValue().set(rechargeAddressVo.getAddress(), recharge); |
| | | |
| | | data.add(rechargeAddressVo); |
| | | } |
| | | }); |
| | | }); |
| | | return Result.succeed(data); |
| | | //} |
| | | |
| | | }catch (Exception e){ |
| | | log.error("获取充值地址错误:",e); |
| | | return Result.failed("充值链暂不可用"); |
| | | return Result.failed("失败"); |
| | | } |
| | | return Result.succeed(data); |
| | | }*/ |
| | | } |
| | | |
| | | @PostMapping(action +"rechargeCallback.action") |
| | | public ResultMsg rechargeCallback(HttpServletRequest request){ |