|
@@ -10,16 +10,34 @@ import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.util.Base64;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
public class QRCodeController {
|
|
|
|
|
|
- @GetMapping(value = "/hisCountQrCode", produces = MediaType.IMAGE_PNG_VALUE)
|
|
|
- public byte[] getQRCode(@RequestParam String content) throws IOException, WriterException {
|
|
|
- BufferedImage qrImage = QRCodeGenerator.generateQRCode(content, 300, 300);
|
|
|
-
|
|
|
+ @GetMapping(value = "/hisCountQrCode")
|
|
|
+ public Map<String, Object> getQRCode(@RequestParam String content) throws IOException, WriterException {
|
|
|
+ BufferedImage qrImage = QRCodeGenerator.generateQRCode(URLDecoder.decode(content, "UTF-8"), 100, 100);
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
ImageIO.write(qrImage, "PNG", baos);
|
|
|
- return baos.toByteArray();
|
|
|
+ byte[] imageBytes = baos.toByteArray();
|
|
|
+ String base64Image = Base64.getEncoder().encodeToString(imageBytes);
|
|
|
+ String imageSrc = "data:image/png;base64," + base64Image;
|
|
|
+
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ try {
|
|
|
+ resultMap.put("code", 0);
|
|
|
+ resultMap.put("message", "生成二维码成功!");
|
|
|
+ resultMap.put("data", imageSrc);
|
|
|
+ return resultMap;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ resultMap.put("code", -1);
|
|
|
+ resultMap.put("message", "生成二维码失败!");
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
}
|
|
|
}
|