标签:vcf
/**
* 获取通讯录
* @param modelMap
* @param id
* @param request
* @return
*/
@RequestMapping(value = "mp_ajax_vcf.html")
public String ajaxVcf(ModelMap modelMap,@RequestParam(value = "id",required = false)String id,HttpServletRequest request,HttpServletResponse response){
QueryCondition queryCondition = new QueryCondition();
queryCondition.setQueryObject(MpBasInfo.class);
queryCondition.addField(new QueryField("id",id,QueryField.CONDITION_EQ));
CrmMicroBusinessCardVO crmMicroBusinessCardVO = mpBasInfoService.queryCondition(queryCondition);
if(crmMicroBusinessCardVO.getId()!=null){
String myPath = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+myPath+"/";
String filename = crmMicroBusinessCardVO.getAccount() +".vcf";
try {
filename = new String(filename.getBytes("utf-8"),"iso-8859-1");
response.reset();
response.setHeader("Content-disposition", "attachment;filename="+filename);
PrintWriter printWriter = response.getWriter();
printWriter.write("BEGIN:VCARD");
printWriter.write("\r\n");
printWriter.write("VERSION:2.1");
printWriter.write("\r\n");
printWriter.write("N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:"+ QpUtil.qpEncodeingUTF8(crmMicroBusinessCardVO.getCardName())+";");
printWriter.write("\r\n");
printWriter.write("TEL;CELL:"+crmMicroBusinessCardVO.getAccount());
printWriter.write("\r\n");
printWriter.write("EMAIL:"+crmMicroBusinessCardVO.getEmail());
printWriter.write("\r\n");
printWriter.write("END:VCARD");
printWriter.write("\r\n");
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
return null;
}
package com.chenghan.yun.mp.utils;
/**
* Created with IntelliJ IDEA.
* User: zherongxu
* Date: 15-1-16
* Time: 下午1:48
* To change this template use File | Settings | File Templates.
*/
public class QpUtil {
/**
* 编码 UTF8 quoted-printable
* @param str 需要编码的字符串
* @return 编码后的字符串
* @throws Exception
*/
public static String qpEncodeingUTF8(String str) throws Exception {
if (str != null) {
char[] encode = str.toCharArray();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < encode.length; i++) {
if ((encode[i] >= ‘!‘) && (encode[i] <= ‘~‘)
&& (encode[i] != ‘=‘) && (encode[i] != ‘\n‘)) {
sb.append(encode[i]);
} else if (encode[i] == ‘=‘) {
sb.append("=3D");
} else if (encode[i] == ‘\n‘) {
sb.append("\n");
} else {
StringBuffer sbother = new StringBuffer();
sbother.append(encode[i]);
String ss = sbother.toString();
byte[] buf = null;
buf = ss.getBytes("utf-8");
// UTF-8: buf.length == 3
// GBK: buf.length == 2
if (buf.length == 3) {
for (int j = 0; j < buf.length; j++) {
String s16 = String.valueOf(Integer
.toHexString(buf[j]));
char c16_6;
char c16_7;
if (s16.charAt(6) >= 97 && s16.charAt(6) <= 122) {
c16_6 = (char) (s16.charAt(6) - 32);
} else {
c16_6 = s16.charAt(6);
}
if (s16.charAt(7) >= 97 && s16.charAt(7) <= 122) {
c16_7 = (char) (s16.charAt(7) - 32);
} else {
c16_7 = s16.charAt(7);
}
sb.append("=" + c16_6 + c16_7);
}
}
}
}
str = sb.toString();
}
return str;
}
}
本文出自 “小博客” 博客,请务必保留此出处http://9686567.blog.51cto.com/9676567/1605934
标签:vcf
原文地址:http://9686567.blog.51cto.com/9676567/1605934