生成萬能二維碼 前後端邏輯 完整流程
匯入pom
<dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>com.google.zxing</groupId> <artifactId>javase</artifactId> <version>3.3.0</version> </dependency>
生成二維碼工具類
public class QRCodeUtil { public static String toQRCode(String str) { MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); Map hints = new HashMap(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.put(EncodeHintType.MARGIN, 1); BitMatrix bitMatrix = null; try { bitMatrix = multiFormatWriter.encode(str, BarcodeFormat.QR_CODE, 300, 300, hints); BufferedImage image = toBufferedImage(bitMatrix); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { ImageIO.write(image, "png", outputStream); return Base64.encodeBase64String(outputStream.toByteArray()); } catch (IOException e) { e.printStackTrace(); } } catch (WriterException e1) { e1.printStackTrace(); } return null; } public static BufferedImage toBufferedImage(BitMatrix matrix) { int width = matrix.getWidth(); int height = matrix.getHeight(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { image.setRGB(x, y, matrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); } } return image; } }
生成二維碼controller
@Slf4j @RestController @RequestMapping("/qr_code_generator") @Api(tags = "生成二維碼") public class QRCodeGeneratorController { @GetMapping("/qrimage") @ApiOperation(value = "生成二維碼") public R encodeQrCode(String uniscid) { return new R<>(QRCodeUtil.toQRCode("http://192.168.1.186:8080/enterpriseCode?"+uniscid),"success",0); } }
前端展示二維碼
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAGDUlEQVR42u3aMZbDIBBEQd3/0vIFHELTg+rnemtgik14XklHe2yBBKEEoSQIJQglQShBKAlCCUJJEEoQSoJQglAShBKEkiCUIJQEoQTh/y8nt34fg39r+aEkT9lEQQghhBBCCKGJghBCCCGEEEITBSGEEE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IYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIITz+g5pfe7zBSra35N65ewAghBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCMeZKZnIfoQl21uCsOQJDoQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQghh85SUvMC4tZKjrIKRvMgghBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCFUyCk99+WE9fnfvGjnqIIQQQgghhFAQQgghhBBCKAghhBBCCCEUhBBCCCGEEF40JaPf2YxeV3L6+19uQQghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBmEPa/fel/MVOyrtG31ZRThhBCCCGEEEIIIYQQQgghhBBCCCGEEELHAyGEEEIIIYSOB0IIb1r86JclJa9YkusqeTJ14L8FhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCOHnEbYczOQ5LjEDIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgjhFIT9A9Q/rCXnlbwZIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgibESaD8JS0/hukCjyEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEII4cEzSDbleI5fLv23cHJdEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYTHEUpac4/YAglCCUJJEEoQSoJQglAShBKEkiCUIJQEoQShJAglCCVBKEEoCUIJQkn7+gEp79e5r5nv/wAAAABJRU5ErkJggg=="/>
相關文章
- 打通前後端邏輯,客戶端Flutter程式碼一天上線後端客戶端Flutter
- 從邏輯解偶到物理解耦再到前後端分離解耦後端
- PbootCMS模板自動生成當前頁面二維碼boot
- 二維碼管理平臺 生成二維碼
- Nginx(二): worker 程式處理邏輯-流程框架Nginx框架
- 一行python生成終端二維碼Python
- 前後端開發流程總結後端
- jquery生成二維碼jQuery
- 二維碼線上生成
- Flutter - 生成二維碼與識別二維碼Flutter
- 萬能碼不是普通的二維碼(安全掃碼專業委員會)
- 萬能碼:突破二維碼侷限(安全掃碼專業委員會)
- 直播系統搭建,java二維碼 生成二維碼Java
- iOS 花式二維碼生成和二維碼識別iOS
- Android 二維碼掃描和生成二維碼Android
- Tp框架 生成二維碼框架
- ios--二維碼生成iOS
- 二維碼生成工具類
- 二維碼生成-PythonPython
- c++生成二維碼C++
- JS線上生成二維碼JS
- 二維碼線上生成工具
- iOS 生成二維碼/條形碼iOS
- H5 微信前後端登入流程H5後端
- Tp生成小程式二維碼
- php生成二維碼圖片PHP
- PHP生成簡單二維碼PHP
- java實現二維碼生成Java
- 利用Google API生成二維碼GoAPI
- jq動態生成二維碼
- 使用 Python 生成二維碼Python
- Neditor 2.0.0 釋出,移除後端程式碼,重寫上傳邏輯(Ajax)後端
- 傳奇原始碼分析-客戶端(遊戲邏輯處理源分析二)原始碼客戶端遊戲
- Spring boot 生成動態驗證碼並前後端校驗Spring Boot後端
- 線上生成二維碼程式碼例項
- 從普通二維碼到檔案生成二維碼的轉變
- WEB程式的前後端資料互動流程Web後端
- 微信二次開發(生成二維碼)