生成二维码 提供技术支持
public String createUrl1(OrderForm obj, HttpServletRequest request){
String result = "false";
OrderForm bu = new OrderForm();
System.out.println("00");
try{
String url="";
//通用保存在数据库中的数据
存储的一个url 在二维码里面
String returnUrlQr = "http://xxx:9080/#/sendpassword?orderId="+obj.getId();
//生成二维码
String eRname=null;
int width = 300; // 设置二维码的宽
int height = 300; // 设置二维码的长
String format = "png"; // 设置二维码图片的格式
String contents = returnUrlQr; // 设置的连接地址
// 二维码参数
HashMap hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); // 设置支持中文编码
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // 纠错等级。
hints.put(EncodeHintType.MARGIN, 2); // 边框
try
{
BitMatrix bitmatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height);
// String qrUrl = "/D:/load/";
String qrUrl = "/root/upload/";
String qrName= String.valueOf(UUID.randomUUID());
File qrFile = new File(qrUrl + qrName+".png");
if (!qrFile.exists()) {
qrFile.createNewFile();//创建文件
}
Path file = qrFile.toPath(); // 文件路径
MatrixToImageWriter.writeToPath(bitmatrix, format, file);
bu.setPrCode(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()+"/img/"+qrName+".png");//保存二维码的地址
url=(returnUrl+qrName+".png");
return url;
} catch (Exception e)
{
e.printStackTrace();
}
bu.setPrCode(returnUrlQr+"");//保存礼物的访问路径
}catch (Exception e) {
e.printStackTrace();
System.out.print(e.toString());
return "false";
}
return result;
}