mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix qrcode bug
This commit is contained in:
parent
f9f73e4c02
commit
3421a8f54d
@ -22,6 +22,8 @@
|
|||||||
* 【core 】 修复UrlBuilder地址参数问题(issue#I1UWCA@Gitee)
|
* 【core 】 修复UrlBuilder地址参数问题(issue#I1UWCA@Gitee)
|
||||||
* 【core 】 修复StrUtil.toSymbolCase转换问题(issue#1075@Github)
|
* 【core 】 修复StrUtil.toSymbolCase转换问题(issue#1075@Github)
|
||||||
* 【log 】 修复打印null对象显示{msg}异常问题(issue#1084@Github)
|
* 【log 】 修复打印null对象显示{msg}异常问题(issue#1084@Github)
|
||||||
|
* 【extra 】 修复ServletUtil.getReader中未关闭的问题
|
||||||
|
* 【extra 】 修复QrCodeUtil在新版本zxing报错问题(issue#1088@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
package cn.hutool.extra.qrcode;
|
package cn.hutool.extra.qrcode;
|
||||||
|
|
||||||
|
import cn.hutool.core.img.ImgUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
|
import com.google.zxing.EncodeHintType;
|
||||||
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.google.zxing.EncodeHintType;
|
|
||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
||||||
|
|
||||||
import cn.hutool.core.img.ImgUtil;
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 二维码设置
|
* 二维码设置
|
||||||
*
|
*
|
||||||
@ -34,8 +33,8 @@ public class QrConfig {
|
|||||||
protected Integer backColor = WHITE;
|
protected Integer backColor = WHITE;
|
||||||
/** 边距1~4 */
|
/** 边距1~4 */
|
||||||
protected Integer margin = 2;
|
protected Integer margin = 2;
|
||||||
/** 设置二维码中的信息量,可设置0-40的整数,二维码图片也会根据qrVersion而变化,0表示根据传入信息自动变化 */
|
/** 设置二维码中的信息量,可设置1-40的整数 */
|
||||||
protected Integer qrVersion = 0;
|
protected Integer qrVersion;
|
||||||
/** 纠错级别 */
|
/** 纠错级别 */
|
||||||
protected ErrorCorrectionLevel errorCorrection = ErrorCorrectionLevel.M;
|
protected ErrorCorrectionLevel errorCorrection = ErrorCorrectionLevel.M;
|
||||||
/** 编码 */
|
/** 编码 */
|
||||||
|
@ -27,6 +27,7 @@ import javax.servlet.http.Cookie;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -91,8 +92,8 @@ public class ServletUtil {
|
|||||||
* @since 4.0.2
|
* @since 4.0.2
|
||||||
*/
|
*/
|
||||||
public static String getBody(ServletRequest request) {
|
public static String getBody(ServletRequest request) {
|
||||||
try {
|
try(final BufferedReader reader = request.getReader()) {
|
||||||
return IoUtil.read(request.getReader());
|
return IoUtil.read(reader);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IORuntimeException(e);
|
throw new IORuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,12 @@ import cn.hutool.core.codec.Base64;
|
|||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.lang.Console;
|
import cn.hutool.core.lang.Console;
|
||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,9 +21,9 @@ import java.io.File;
|
|||||||
public class QrCodeUtilTest {
|
public class QrCodeUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void generateTest() {
|
public void generateTest() {
|
||||||
QrCodeUtil.generate("https://hutool.cn/", 300, 300, FileUtil.file("e:/qrcode.jpg"));
|
final BufferedImage image = QrCodeUtil.generate("https://hutool.cn/", 300, 300);
|
||||||
|
Assert.assertNotNull(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user