发票二维码含义, 及java生成二维码
二维码
从发票上截取的二维码
扫描结果
01,10,011001800211,65651348,105.46,20180709,05903676700178588016,C62D,
结果解析
样例
增值税电子普通发票:
01,10,011001800211,65651348,105.46,20180709,05903676700178588016,C62D,
该字符串以逗号分隔每一个属性值,从左到右依次是:
01:第一个属性值,尚未搞清楚含义;
10:第二个属性值,代表发票种类代码,10-增值税电子普通发票,04-增值税普通发票,01-增值税专用发票;
011001800211:第三个属性值,代表发票代码;
65651348:第四个属性值,代表发票号码;
105.46:第五个属性值,代表开票金额;
20180709:第六个属性值,代表开票日期,该值为2018年7月9日;
05903676700178588016:第七个属性值,代码发票校验码,我们都知道增值税专用发票是没有发票校验码的,没有则为空字符串;
C62D:第八个属性值,为随机产生的机密信息;
增值税专用发票:
01,01,1200154130,03630024,94339.62,20180721,,AE2D,
其中"AE2D"为随机产生的机密信息;
增值税普通发票:
01,04,011001800211,65651348,1105.46,20180709,05903676700178588016,C62D,
其中"C62D"为随机产生的机密信息;
引入依赖
字符串二维码或二维码读取
package com.bosssoft.cloud.coreservice.pdf.help;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.imageio.ImageIO;
import org.slf4j.LoggerFactory;
import com.swetake.util.Qrcode;
import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.data.QRCodeImage;
import jp.sourceforge.qrcode.exception.DecodingFailedException;
public class QRCodeUtil {
private static Logger logger = LoggerFactory.getLogger(QRCodeUtil.class);
public static byte[] qrCodeEncode(String encodeddata) throws IOException {
Qrcode qrcode = new Qrcode();
qrcode.setQrcodeErrorCorrect('L');
qrcode.setQrcodeEncodeMode('B');
qrcode.setQrcodeVersion(7);
byte[] d = encodeddata.getBytes("GBK");
BufferedImage bi = new BufferedImage(139, 139, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, 139, 139);
if (d.length > 0 && d.length < 123) {
boolean[][] b = qrcode.calQrcode(d);
for (int i = 0; i < b.length; i++) {
for (int j = 0; j < b.length; j++) {
g.fillRect(j 3 + 2, i 3 + 2, 3, 3);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(bi, "png", bos);
return bos.toByteArray();
public static String qrCodeDecode(byte[] imageByte) {
String decodedData = null;
QRCodeDecoder decoder = new QRCodeDecoder();
BufferedImage image = null;
ByteArrayInputStream bais = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bais);
} catch (IOException e) {
logger.error("二维码解析Error: " + e.getMessage());
decodedData = new String(decoder.decode(new MyQRCodeImage(image)), "GBK");
} catch (DecodingFailedException dfe) {
logger.error("Error: " + dfe.getMessage());
} catch (UnsupportedEncodingException e) {
logger.error("Error: " + e.getMessage());
static class MyQRCodeImage implements QRCodeImage {
public MyQRCodeImage(BufferedImage image) {
return image.getHeight();
public int getPixel(int x, int y) {
return image.getRGB(x, y);
二维码测试
String filePath = "D:\practice\targetQR.png";
String encodeddata = "01,04,011001800211,65651348,1105.46,20180709,05903676700178588016,C62D,";
byte[] qrCodeEncode = null;
qrCodeEncode = QRCodeUtil.qrCodeEncode(encodeddata);
writeFile(qrCodeEncode, filePath);
} catch (IOException e) {
String reText = QRCodeUtil.qrCodeDecode(qrCodeEncode);
System.out.println(reText);
private void writeFile(byte[] bytes, String target) {
File file = new File(target);
FileOutputStream fos = new FileOutputStream(file);
System.out.println("写入文件异常");
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。