| | |
| | | package com.yami.trading.service.user.impl; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | @Override |
| | | public String generate(String content) { |
| | | String image_name = "/qr/" + content + ".png"; |
| | | content = Constants.WEB_URL + "/register.html?usercode=" + content; |
| | | final String userCode = content; |
| | | content = Constants.buildRegisterInviteLink(userCode); |
| | | boolean openButton = sysparaService.find("short_url_open_button").getBoolean() ; |
| | | if(openButton) { |
| | | content = sysparaService.find("agent_qr_url").getSvalue() + "/register.html?usercode=" + content; |
| | | String agentBase = Constants.normalizeWebUrl(sysparaService.find("agent_qr_url").getSvalue()); |
| | | content = agentBase + "/#/register?usercode=" + userCode; |
| | | boolean isCn = sysparaService.find("short_url_cn_button").getBoolean() ; |
| | | if(isCn) { |
| | | content = shortUrlCn(content); |
| | |
| | | int width = 260; |
| | | int height = 260; |
| | | String format = "png"; |
| | | Map hints = new HashMap(); |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
| | | try { |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | writeQrImageToFile(bitMatrix, format, file); |
| | | } catch (Exception e) { |
| | | log.error("write to image error:", e); |
| | | } |
| | |
| | | int width = 260; |
| | | int height = 260; |
| | | String format = "png"; |
| | | Map hints = new HashMap(); |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
| | | try { |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | writeQrImageToFile(bitMatrix, format, file); |
| | | } catch (Exception e) { |
| | | log.error("write to image error:", e); |
| | | } |
| | |
| | | @Override |
| | | public String generate185(String content) { |
| | | String image_name = "/qr/" + content + "2.png"; |
| | | content = Constants.WEB_URL + "/register.html?usercode=" + content; |
| | | content = Constants.buildRegisterInviteLink(content); |
| | | // String image_name = "/qr/" + UUIDGenerator.getUUID() + ".png"; |
| | | String filepath = Constants.IMAGES_DIR + image_name; |
| | | File file = new File(filepath); |
| | | int width = 185; |
| | | int height = 185; |
| | | String format = "png"; |
| | | Map hints = new HashMap(); |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
| | | hints.put(EncodeHintType.MARGIN, 1);// 二维码空白区域,最小为0也有白边,只是很小,最小是6像素左右 |
| | | |
| | | try { |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | writeQrImageToFile(bitMatrix, format, file); |
| | | } catch (Exception e) { |
| | | log.error("write to image error:", e); |
| | | } |
| | |
| | | public String generateWithdraw(String content, String address) { |
| | | String image_name = "/qr/" + content + ".png"; |
| | | String filepath = Constants.IMAGES_DIR + image_name; |
| | | File file=new File( Constants.IMAGES_DIR); |
| | | if (!file.isDirectory()){ |
| | | file.mkdirs(); |
| | | } |
| | | file = new File(filepath); |
| | | File file = new File(filepath); |
| | | int width = 260; |
| | | int height = 260; |
| | | String format = "png"; |
| | | Map hints = new HashMap(); |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
| | | try { |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(address, BarcodeFormat.QR_CODE, width, height, hints); |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | writeQrImageToFile(bitMatrix, format, file); |
| | | } catch (Exception e) { |
| | | log.error("write to image error:", e); |
| | | } |
| | |
| | | |
| | | return list_image; |
| | | } |
| | | |
| | | private void writeQrImageToFile(BitMatrix bitMatrix, String format, File file) throws IOException { |
| | | if (bitMatrix == null) { |
| | | throw new IOException("bitMatrix is null"); |
| | | } |
| | | if (file == null) { |
| | | throw new IOException("target file is null"); |
| | | } |
| | | File parent = file.getParentFile(); |
| | | if (parent != null && !parent.exists() && !parent.mkdirs()) { |
| | | throw new IOException("failed to create qr image directory: " + parent.getAbsolutePath()); |
| | | } |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | } |
| | | } |