1. maven 依赖
2. 代码编写
生成
publicstaticvoidqrCode()throwsWriterException,IOException{
StringfilePath="D://";
StringfileName="zxing.png";
Stringcontent=handlerEvent();
intwidth=200;// 图像宽度
intheight=200;// 图像高度
Stringformat="png";// 图像类型
Maphints=newHashMap();
hints.put(EncodeHintType.CHARACTER_SET,"UTF-8");
BitMatrixbitMatrix=newMultiFormatWriter().encode(content,
BarcodeFormat.QR_CODE,width,height,hints);// 生成矩阵
Pathpath=FileSystems.getDefault().getPath(filePath,fileName);
MatrixToImageWriter.toBufferedImage(bitMatrix);
MatrixToImageWriter.writeToPath(bitMatrix,format,path);// 输出图像
}
vcard 生成
publicstaticStringhandlerEvent(){
VCardcard=newVCard();
card.addEmail(newEmail("[email protected]"));
Addressorgial=newAddress();
orgial.addParameter("name","dalong");
card.addAddress(newAddress(orgial));
card.addExpertise("软件开发");
Nicknamenickname=newNickname();
nickname.addParameter("姓名","荣锋亮");
card.addNickname(newNickname(nickname));
card.setNickname("大龙");
card.setCategories("北京");
card.setMailer("男");
card.setGeo(116.419791,39.936404);
card.setOrganization("北京公司");
card.setProductId("beijing");
card.setClassification("开发");
Agentagent=newAgent("beijing");
card.setAgent(agent);
card.addExtendedProperty("TEL","XXXXXXXXXXXXX");
Gsonjson=newGson();
returncard.write();
}
3. 结果
4. 微信扫描结果