@Api(tags = "二维码下载接口")
@Controller
public class QrCodeController {
@Autowired
private SysApkService sysApkService;
/**
* make the QRCode by url
* @param response
* @param id
* @throws IOException
*/
@ApiOperation(value = "生成二维码",notes = "生成二维码")
@ApiImplicitParams({
@ApiImplicitParam(type = "query",name = "id",value = "ID",required = true)
})
@GetMapping("/qrcode/createCommonQRCode")
@CrossOrigin(origins = "*", allowCredentials = "true",allowedHeaders = "*",methods = {RequestMethod.GET, RequestMethod.DELETE, RequestMethod.HEAD, RequestMethod.OPTIONS, RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH})
@ResponseBody
public void createCommonQRCode(HttpServletResponse response,
Long id) throws IOException {
System.out.println("id:"+id);

ServletOutputStream stream = null;
try{
SysApk sysApk = sysApkService.findById(id);
//返回图片内容
response.setContentType("image/jpeg");
stream = response.getOutputStream();
//String imgUrl = "./";
//produce the QRCode
QRCodeUtil.encode(sysApk.getApkUrl(),
"/usr/local/hc_logo.png",sysApk.getApkName(),stream,true);
}catch (Exception e){
e.printStackTrace();
}finally {
if(stream != null){
stream.flush();
stream.close();
}
}
}
}