批量生成二维码

/**
     * 批量生成二维码
     * @param session
     * @param request
     * @param c
     * @param r
     * @throws Throwable
     */
    private void create2DCodeBatch( HttpRequest request,
            JSONObject c, JSONObject r) throws Throwable {
        if (!user.getRight().isNonFuncEnabled()){
            throw new KoneException(NON_FUNC_HINT);
        }
        String[] ids = request.getParameter("idlist").split(",");        
        for(int i=0;i<ids.length;i++){
            String id = ids[i];
            Device device = DeviceLocalCacheHelper.deviceMap.get(Integer.valueOf(id));
            if(device != null){
                //设备ID、设备编码、出厂编码、设备类型、设备型号ID
                String text = device.getDeviceId()+"-"+device.getDeviceCode()+"-"+device.getFactoryCode()+"-"+device.getDeviceType()+"-"+device.getDeviceModelId();
                //二维生成返回BufferedImage 图片流
                BufferedImage bufferedImage = ZXingUtil.createQRCodeBufImage(text,null,0,0);
                
                bufferedImage.flush();                
                WebSession session = getSession();
                HttpServletResponse response = session.getResponse();
                ImageIO.write(bufferedImage, "png",  response.getOutputStream());    //直接将图片显示在页面。            
            }
        }        
    }
   

posted @ 2015-06-18 10:27  stt_spring  阅读(157)  评论(0)    收藏  举报