新版仿ok交易所-后端
1
zj
2026-05-13 f7bde8a9d9bf8e3c67c0912cbd8c50fe4f7097aa
1
6 files modified
391 ■■■■ changed files
trading-order-admin/src/main/java/com/yami/trading/api/UD/UdunClient.java 6 ●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java 275 ●●●●● patch | view | raw | blame | history
trading-order-admin/src/main/resources/application-prod.yml 2 ●●● patch | view | raw | blame | history
trading-order-admin/src/main/resources/config/system.properties 4 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/EmailServer.java 17 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/impl/InternalEmailSenderServiceImpl.java 87 ●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/UD/UdunClient.java
@@ -21,17 +21,17 @@
    /**
     * UDUN API Gateway
     */
    private final String gateway =  "https://sig10.udun.io";
    private final String gateway =  "https://sig11.udun.io";
    /**
     * UDUN Merchant Key
     */
    private final String merchantKey =  "ced10252df2ffad4e9d3059924ece9b0";
    private final String merchantKey =  "39caa62bca6344435c69c1b2bcc37d24";
    /**
     * UDUN Merchant Number
     */
    private final String merchantId =  "322571";
    private final String merchantId =  "323145";
    /**
     * Callback 充值
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
@@ -1,5 +1,6 @@
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;
@@ -80,6 +81,13 @@
    @Autowired
    protected UserService partyService;
    private String normalizeChainKey(String value) {
        if (value == null) {
            return "";
        }
        return value.replace("-", "").replace("_", "").replace(" ", "").toUpperCase(Locale.ROOT);
    }
    /**
     * 获取所有链地址
     */
@@ -124,187 +132,118 @@
        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){
trading-order-admin/src/main/resources/application-prod.yml
@@ -5,7 +5,7 @@
#    url: jdbc:mysql://127.0.0.1:6306/8.4?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&serverTimezone=America/New_York&useLegacyDatetimeCode=false
    url: jdbc:mysql://127.0.0.1:3306/trading_order?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&serverTimezone=America/New_York&useLegacyDatetimeCode=false
    username: trading_order
    password: dzptt5sWi6y6p4Fs
    password: yaNmSJACseBdSXmZ
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.zaxxer.hikari.HikariDataSource
    hikari:
trading-order-admin/src/main/resources/config/system.properties
@@ -3,11 +3,11 @@
admin_url=https://127.0.0.1:8080/admin
web_url=http://127.0.0.1:8080/wap/
images_http=https://img.orionx.cyou/
images_http=https://img.bitxworld.com/
loca.images.dir=/www/wwwroot/img
admin_rest_url=https://enjdhdg.site/api
api_http=https://api.orionx.cyou/
api_http=https://api.bitxworld.com/
email.host=smtp.gmail.com
trading-order-service/src/main/java/com/yami/trading/EmailServer.java
@@ -59,28 +59,19 @@
     */
    public void run() {
        while (true) {
            try {
                EmailMessage item = EmailMessageQueue.poll();
                if (item != null) {
                    System.out.println("邮寄地址:" + item.getTomail());
                    taskExecutor.execute(new HandleRunner(item));
                }
                else {
                    /*
                     * 限速,最多1秒20个
                     */
                if (null!=item) {
                    logger.info("邮寄地址:" + item.getTomail()+"内容:"+item.getContent());
                    internalEmailSenderService.send(item);
                }else {
                    ThreadUtils.sleep(50);
                }
            } catch (Throwable e) {
                logger.error("EmailServer taskExecutor.execute() fail", e);
            }
        }
    }
    public class HandleRunner implements Runnable {
        private EmailMessage item;
trading-order-service/src/main/java/com/yami/trading/service/impl/InternalEmailSenderServiceImpl.java
@@ -1,5 +1,6 @@
package com.yami.trading.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.manager.email.EmailMessage;
import com.yami.trading.common.util.PropertiesUtil;
@@ -7,6 +8,7 @@
import com.yami.trading.service.InternalEmailSenderService;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
@@ -63,32 +65,75 @@
        freeMarkerConfigurer.afterPropertiesSet();
    }
    private static final OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(10, java.util.concurrent.TimeUnit.SECONDS)  // 设置连接超时
            .readTimeout(30, java.util.concurrent.TimeUnit.SECONDS)     // 设置读取超时
            .writeTimeout(30, java.util.concurrent.TimeUnit.SECONDS)    // 设置写入超时
            .build();
    private static final String API_URL = "https://apiv2.aoksend.com/index/api/send_email";
    private static final String APP_KEY = "a437b8c8c89d17a67c74751c3bc7dbbd";
    private static final String TEMPLATE_ID_REGISTER = "E_145471003444";
    @Override
    public void send(EmailMessage emailMessage) {
        // 验证邮件信息数据的有效性
        if (emailMessage == null || emailMessage.getTomail() == null || emailMessage.getContent() == null) {
            logger.error("无效的邮件信息数据。");
            return;
        }
        try {
            MimeMessage mailMsg = this.mailSender.createMimeMessage();
            MimeMessageHelper messageHelper = new MimeMessageHelper(mailMsg, true, "UTF-8");
            messageHelper.setTo(emailMessage.getTomail());// 接收邮箱
            messageHelper.setFrom(this.mailMessage.getFrom());// 发送邮箱
            messageHelper.setSentDate(new Date());// 发送时间
            messageHelper.setSubject(emailMessage.getSubject());// 邮件标题
            if (StringUtils.isNullOrEmpty(emailMessage.getFtlname())) {
                messageHelper.setText(emailMessage.getContent());// 邮件内容
            } else {
                messageHelper.setText(this.getMailText(emailMessage.getFtlname(), emailMessage.getMap()), true);// 邮件内容
            logger.info("----- 开始发送邮件 -----");
            logger.info("发送邮件到: " + emailMessage.getTomail() + ", 来自: " + emailMessage.getContent());
            String codeValue = emailMessage.getContent();
            if (codeValue == null) {
                codeValue = "";
            }
            // true 表示启动HTML格式的邮件
            if (emailMessage.getFile() != null) {
                // 添加邮件附件
                FileSystemResource rarfile = new FileSystemResource(emailMessage.getFile());
                // addAttachment addInline 两种附件添加方式
                // 以附件的形式添加到邮件
                // 使用MimeUtility.encodeWord 解决附件名中文乱码的问题
                messageHelper.addAttachment(MimeUtility.encodeWord(emailMessage.getFilename()), rarfile);
            // 使用 URL 构建器构建带有查询参数的 URL
            HttpUrl.Builder urlBuilder = HttpUrl.parse(API_URL).newBuilder();
            urlBuilder.addQueryParameter("app_key", APP_KEY);
            urlBuilder.addQueryParameter("template_id", TEMPLATE_ID_REGISTER);
            urlBuilder.addQueryParameter("to", emailMessage.getTomail());
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String, String> dataMap = new HashMap<>();
            dataMap.put("code", codeValue);
            String json = objectMapper.writeValueAsString(dataMap);
            urlBuilder.addQueryParameter("data", json);
            // 构建请求体,使用 POST 方法
            RequestBody body = RequestBody.create(
                    json, MediaType.parse("application/json; charset=utf-8")
            );
            // 构建 POST 请求
            Request request = new Request.Builder()
                    .url(urlBuilder.build())
                    .post(body)  // 使用 POST 方法,并传递请求体
                    .addHeader("app_key", APP_KEY)
                    .build();
            // 执行请求
            try (Response response = client.newCall(request).execute()) {
                if (!response.isSuccessful()) {
                    logger.error("邮件发送失败。HTTP 响应码: " + response.code());
                    return;
                }
                logger.info("----- 邮件发送成功 -----");
                // 可选:记录响应体的内容(如果需要)
                logger.info("响应内容: " + response.body().string());
            }
            this.mailSender.send(mailMsg);// 发送
        } catch (MessagingException | UnsupportedEncodingException e) {
            logger.error(e.getMessage(), e);
        } catch (IOException e) {
            logger.error("邮件发送失败【IOException】", e);
        } catch (Exception e) {
            logger.error("邮件发送失败【Exception】", e);
        }
    }