图形验证码的使用

登录之图形验证码

1.后台控制禁止页面缓存

response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
response.setContentType(MediaType.IMAGE_JPEG_VALUE);

开发设置中禁用缓存的参考博客:

转载自CSDN:https://blog.csdn.net/u014482758/article/details/43486081/

2.图片的base64编码

点击查看代码
	
/**
 * 将图片二维码base64编码
 *
 * @param os 输出流
 * @return base64字符串
 * @throws IOException
 */
public static String encodeBase64ImgCode(ByteArrayOutputStream os)
    throws IOException {
  Objects.requireNonNull(os);
  byte[] b = os.toByteArray();
  String imgString = Base64.getEncoder().encodeToString(b);
  return BASE64_IMAGE_PREFIX + imgString;
}

图片base64编码的好处:(可阅读下面不错的一个博文)

转载自博客园:https://www.cnblogs.com/coco1s/p/4375774.html

base64编码后的返回值

{"data":{"id":"6eaf038d7fec412ab199fb632a6b6a8a",
         "img":"data:image/JPEG;base64,/9j/...//Z"},
 "success":true}

前端如何处理base64编码后的图片

转载自百度经验:https://jingyan.baidu.com/article/f7ff0bfcee3cc22e26bb13c4.html

原文地址:https://www.cnblogs.com/erlangha/p/14462492.html