mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix qr test
This commit is contained in:
parent
93a901d864
commit
a77dce46cd
@ -15,6 +15,7 @@
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复UrlBuilder.addPath歧义问题(issue#1912@Github)
|
||||
* 【core 】 修复StrBuilder中总长度计算问题(issue#I4F9L7@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -579,7 +579,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
||||
private static int totalLength(CharSequence... strs) {
|
||||
int totalLength = 0;
|
||||
for (CharSequence str : strs) {
|
||||
totalLength += (null == str ? 4 : str.length());
|
||||
totalLength += (null == str ? 0 : str.length());
|
||||
}
|
||||
return totalLength;
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package cn.hutool.crypto.digest;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
* 摘要算法工具类
|
||||
*
|
||||
@ -424,7 +423,7 @@ public class DigestUtil {
|
||||
* 创建HMac对象,调用digest方法可获得hmac值
|
||||
*
|
||||
* @param algorithm {@link HmacAlgorithm}
|
||||
* @param key 密钥,如果为<code>null</code>生成随机密钥
|
||||
* @param key 密钥,如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
* @since 3.0.3
|
||||
*/
|
||||
@ -436,7 +435,7 @@ public class DigestUtil {
|
||||
* 创建HMac对象,调用digest方法可获得hmac值
|
||||
*
|
||||
* @param algorithm {@link HmacAlgorithm}
|
||||
* @param key 密钥{@link SecretKey},如果为<code>null</code>生成随机密钥
|
||||
* @param key 密钥{@link SecretKey},如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
* @since 3.0.3
|
||||
*/
|
||||
|
@ -313,9 +313,10 @@ public class QrCodeUtil {
|
||||
// 默认配置
|
||||
config = new QrConfig();
|
||||
}
|
||||
|
||||
BitMatrix bitMatrix;
|
||||
try {
|
||||
bitMatrix = multiFormatWriter.encode(content, format, config.width, config.height, config.toHints());
|
||||
bitMatrix = multiFormatWriter.encode(content, format, config.width, config.height, config.toHints(format));
|
||||
} catch (WriterException e) {
|
||||
throw new QrCodeException(e);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ 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.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
|
||||
@ -331,13 +332,31 @@ public class QrConfig {
|
||||
* @return 配置
|
||||
*/
|
||||
public HashMap<EncodeHintType, Object> toHints() {
|
||||
return toHints(BarcodeFormat.QR_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Zxing的二维码配置
|
||||
*
|
||||
* @param format 格式,根据格式不同,{@link #errorCorrection}的值类型有所不同
|
||||
* @return 配置
|
||||
*/
|
||||
public HashMap<EncodeHintType, Object> toHints(BarcodeFormat format) {
|
||||
// 配置
|
||||
final HashMap<EncodeHintType, Object> hints = new HashMap<>();
|
||||
if (null != this.charset) {
|
||||
hints.put(EncodeHintType.CHARACTER_SET, charset.toString().toLowerCase());
|
||||
}
|
||||
if (null != this.errorCorrection) {
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, this.errorCorrection);
|
||||
Object value;
|
||||
if(BarcodeFormat.AZTEC == format || BarcodeFormat.PDF_417 == format){
|
||||
// issue#I4FE3U@Gitee
|
||||
value = this.errorCorrection.getBits();
|
||||
} else {
|
||||
value = this.errorCorrection;
|
||||
}
|
||||
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, value);
|
||||
}
|
||||
if (null != this.margin) {
|
||||
hints.put(EncodeHintType.MARGIN, this.margin);
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
@ -87,4 +88,10 @@ public class QrCodeUtilTest {
|
||||
final String decode = QrCodeUtil.decode(ImgUtil.read("d:/test/qr_a.png"), false, true);
|
||||
Console.log(decode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pdf417Test(){
|
||||
final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.PDF_417, QrConfig.create());
|
||||
Assert.assertNotNull(image);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user