我使用的是android客户端提交数据文件,然后使用zxing生成二维码信息:
步骤一:
客户端基本数据信息:
1:用户姓名
2:身份证号
3:手机号码
4:住址信息
步骤二:
服务端接受到客户端数据之后:
传递参数:
String codefor = encode(timeInfor, "", Consts.imgPath, true,reportType);
/**
* 生成二维码(内嵌LOGO)
*
* @param content
* 内容
* @param imgPath
* LOGO地址
* @param destPath
* 存放目录
* @param needCompress
* 是否压缩LOGO
* @throws Exception
*/
public static String encode(String content, String imgPath, String destPath, boolean needCompress,String reportType) throws Exception {
BufferedImage image = createImage(content, imgPath, needCompress,reportType);
mkdirs(destPath);
// String file = new Random().nextInt(99999999) + ".jpg";
String file = content + ".jpg";
ImageIO.write(image, FORMAT_NAME, new File(destPath + "/" + file));
return file;
}
private static BufferedImage createImage(String content, String imgPath, boolean needCompress,String reportType) throws Exception {
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
if(reportType.equals("绿码")){
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF0cad83 : 0xFFFFFFFF);
}
}
}else if(reportType.equals("黄码")){
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFFF5D96E : 0xFFFFFFFF);
}
}
}else if(reportType.equals("红码")){
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFFFF0000 : 0xFFFFFFFF);
}
}
}
if (imgPath == null || "".equals(imgPath)) {
return image;
}
// 插入图片
// QRCodeUtils.insertImage(image, imgPath, needCompress);
return image;
}
最后在客户端的显示效果: