生成二维码类

master
e 2018-10-18 23:46:43 +08:00
parent 9fa86d2b3a
commit 94c702917a
1 changed files with 70 additions and 3 deletions

View File

@ -5,6 +5,8 @@ import com.zzjee.wm.entity.*;
import com.zzjee.wm.page.*;
import com.zzjee.wm.service.WmOmNoticeHServiceI;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@ -69,9 +71,6 @@ import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import org.springframework.http.ResponseEntity;
@ -2006,6 +2005,74 @@ public class WmOmNoticeHController extends BaseController {
req.setAttribute("controller_name", "wmOmNoticeHController");
return new ModelAndView("common/upload/pub_excel_upload2");
}
/**
* /
* @param response
* @param request
* @throws Exception
* http://localhost:8080/zzjee/wmOmNoticeHController/showOrDownqrcodeByurl.do?&qrvalue=1111223333 调用
*/
@RequestMapping(value="showOrDownqrcodeByurl",method = RequestMethod.GET)
public void getQrImgByurl(HttpServletResponse response, HttpServletRequest request) throws Exception{
request.setCharacterEncoding("UTF-8");
String flag=request.getParameter("down");//是否下载否则展示图片
String qrvalue = request.getParameter("qrvalue");
String dbpath = qrvalue+".jpg";
String localPath=ResourceUtil.getConfigByName("webUploadpath");
try{
String imgurl = localPath+File.separator+dbpath;
QRcodeUtil.encode(qrvalue,imgurl);
}catch (Exception e){
}
if("1".equals(flag)){
response.setContentType("application/x-msdownload;charset=utf-8");
String fileName=dbpath.substring(dbpath.lastIndexOf(File.separator)+1);
String userAgent = request.getHeader("user-agent").toLowerCase();
if (userAgent.contains("msie") || userAgent.contains("like gecko") ) {
fileName = URLEncoder.encode(fileName, "UTF-8");
}else {
fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
}
response.setHeader("Content-disposition", "attachment; filename="+ fileName);
}else{
response.setContentType("image/jpeg;charset=utf-8");
}
InputStream inputStream = null;
OutputStream outputStream=null;
try {
String imgurl = localPath+File.separator+dbpath;
inputStream = new BufferedInputStream(new FileInputStream(imgurl));
outputStream = response.getOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, len);
}
response.flushBuffer();
} catch (Exception e) {
}finally{
if(inputStream!=null){
inputStream.close();
}
if(outputStream!=null){
outputStream.close();
}
}
}
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public List<WmOmNoticeHEntity> list() {