java 二维码生成(vcard)

1. maven 依赖

   com.googlecode.ez-vcard

   ez-vcard

   0.10.1

   com.google.zxing

   javase

   3.3.0

   com.google.zxing

   core

   3.3.0

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. 结果


java 二维码生成(vcard)_第1张图片

4. 微信扫描结果


java 二维码生成(vcard)_第2张图片

你可能感兴趣的:(java 二维码生成(vcard))