|
@@ -1,10 +1,16 @@
|
|
|
package com.ruoyi.web.controller.common;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import com.ruoyi.common.utils.QRCodeUtils;
|
|
|
+import com.ruoyi.common.utils.sign.Base64;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.util.FastByteArrayOutputStream;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
@@ -18,7 +24,9 @@ import com.ruoyi.common.utils.file.FileUtils;
|
|
|
import com.ruoyi.framework.config.ServerConfig;
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
* 通用请求处理
|
|
@@ -131,4 +139,33 @@ public class CommonController {
|
|
|
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
|
|
|
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据url获取二维码
|
|
|
+ * @param response
|
|
|
+ * @param url
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @GetMapping("/common/qrcode")
|
|
|
+ public AjaxResult getQrcode(HttpServletResponse response, String url) throws Exception {
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(url)) {
|
|
|
+ return AjaxResult.error("url为空");
|
|
|
+ }
|
|
|
+ //二维码图片
|
|
|
+ BufferedImage image = QRCodeUtils.createImage(url,null,true);
|
|
|
+ // 转换流信息写出
|
|
|
+ FastByteArrayOutputStream os = new FastByteArrayOutputStream();
|
|
|
+ try {
|
|
|
+ ImageIO.write(image, "jpg", os);
|
|
|
+ }
|
|
|
+ catch (IOException e) {
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ ajax.put("img", Base64.encode(os.toByteArray()));
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
}
|