提交 c3a45dfc authored 作者: zhoushaopan's avatar zhoushaopan

[二维码]修改

上级 0b7a008d
...@@ -7,7 +7,9 @@ import com.google.zxing.common.BitMatrix; ...@@ -7,7 +7,9 @@ import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer; import com.google.zxing.common.HybridBinarizer;
import javassist.NotFoundException; import javassist.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest; import org.springframework.web.multipart.MultipartRequest;
import sun.misc.BASE64Encoder; import sun.misc.BASE64Encoder;
...@@ -27,6 +29,8 @@ import java.util.UUID; ...@@ -27,6 +29,8 @@ import java.util.UUID;
* Author:zsp * Author:zsp
*/ */
public class ZXingUtil { public class ZXingUtil {
/** 二维码上传位置 */ /** 二维码上传位置 */
private static String codePath = "src/"; private static String codePath = "src/";
/** 二维码宽度 */ /** 二维码宽度 */
...@@ -77,7 +81,7 @@ public class ZXingUtil { ...@@ -77,7 +81,7 @@ public class ZXingUtil {
encodeHints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); encodeHints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(String.valueOf(taskId), BitMatrix bitMatrix = new MultiFormatWriter().encode(String.valueOf(taskId),
BarcodeFormat.QR_CODE, width, height, encodeHints); BarcodeFormat.QR_CODE, width, height, encodeHints);
String filepath = codePath + UUID.randomUUID() + ".png"; String filepath = ResourceUtils.getURL("classpath:").getPath() + UUID.randomUUID() + ".png";
Path path = FileSystems.getDefault().getPath(filepath); Path path = FileSystems.getDefault().getPath(filepath);
MatrixToImageWriter.writeToPath(bitMatrix,"png",path); MatrixToImageWriter.writeToPath(bitMatrix,"png",path);
return ImageToBase64ByLocal(filepath); return ImageToBase64ByLocal(filepath);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论