def authBatch = authLog.getAuthBatch() String text = ConfReader.get("QRCODE_VALIDATE_PATH_PRE") + authBatch // 二维码的图片格式 HashMap<EncodeHintType, String> hints = new HashMap<>(); // 内容所使用编码 hints.put(EncodeHintType.CHARACTER_SET, Constants.UTF8); BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, 400, 400, hints); BufferedImage srcImage = MatrixToImageWriter.toBufferedImage(bitMatrix, new MatrixToImageConfig()) ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(srcImage, "jpg", out); byte[] data = out.toByteArray(); return [ "srcData": "data:image/jpg;base64," + Base64.encodeBase64String(data) ];
时间: 2024-10-18 04:47:39