com.google.code.kaptcha.Producer类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(520)

本文整理了Java中com.google.code.kaptcha.Producer类的一些代码示例,展示了Producer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Producer类的具体详情如下:
包路径:com.google.code.kaptcha.Producer
类名称:Producer

Producer介绍

[英]Responsible for creating captcha image with a text drawn on it.
[中]负责创建带有文本的验证码图像。

代码示例

代码示例来源:origin: stylefeng/Guns

String capText = producer.createText();
BufferedImage bi = producer.createImage(capText);
ServletOutputStream out = null;
try {

代码示例来源:origin: timebusker/spring-boot

/**
 * 获取验证码
 *
 * @throws CommonException
 * @throws IOException
 */
@RequestMapping("/authcode")
public void captcha() throws CommonException, IOException {
  response.setHeader("Cache-Control", "no-store, no-cache");
  response.setContentType("image/jpeg");
  //生成文字验证码
  String text = producer.createText();
  //生成图片验证码
  BufferedImage image = producer.createImage(text);
  //保存到shiro session
  session.setAttribute(Constants.KAPTCHA_SESSION_KEY, text);
  // 输出验证码图片到页面
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(image, "jpg", out);
  IOUtils.closeQuietly(out);
}

代码示例来源:origin: pig4cloud/pig

/**
 * 创建验证码
 *
 * @param request request
 * @throws Exception
 */
@GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{randomStr}")
public void createCode(@PathVariable String randomStr, HttpServletRequest request, HttpServletResponse response)
    throws Exception {
  Assert.isBlank(randomStr, "机器码不能为空");
  response.setHeader("Cache-Control", "no-store, no-cache");
  response.setContentType("image/jpeg");
  //生成文字验证码
  String text = producer.createText();
  //生成图片验证码
  BufferedImage image = producer.createImage(text);
  userService.saveImageCode(randomStr, text);
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(image, "JPEG", out);
  IOUtils.closeQuietly(out);
}

代码示例来源:origin: com.github.livesense/org.liveSense.service.captcha

@Override
public BufferedImage getImage(String id, String text, Locale locale) {
  // create the text for the image
  String capText = this.kaptchaProducer.createText();
  codeTexts.put(id, capText);
  return this.kaptchaProducer.createImage(capText);
}

代码示例来源:origin: com.github.livesense/org.liveSense.service.captcha

@Override
public BufferedImage getImage(String id, String text, Locale locale) {
  // create the text for the image
  String capText = this.kaptchaProducer.createText();
  codeTexts.put(id, capText);
  return this.kaptchaProducer.createImage(capText);
}

代码示例来源:origin: muyinchen/migo-security

@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
  response.setHeader("Cache-Control", "no-store, no-cache");
  response.setContentType("image/jpeg");
  //生成文字验证码
  String text = producer.createText();
  //生成图片验证码
  BufferedImage image = producer.createImage(text);
  //保存到shiro session
  ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(image, "jpg", out);
}

代码示例来源:origin: zhaoqicheng/renren-fast

@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
  response.setHeader("Cache-Control", "no-store, no-cache");
  response.setContentType("image/jpeg");
  //生成文字验证码
  String text = producer.createText();
  //生成图片验证码
  BufferedImage image = producer.createImage(text);
  //保存到shiro session
  ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(image, "jpg", out);
  IOUtils.closeQuietly(out);
}

代码示例来源:origin: opplus/springboot-admin

@RequestMapping("/captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
  response.setHeader("Cache-Control", "no-store, no-cache");
  response.setContentType("image/jpeg");
  //生成文字验证码
  String text = producer.createText();
  //生成图片验证码
  BufferedImage image = producer.createImage(text);
  //保存到shiro session
  ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(image, "jpg", out);
  IOUtils.closeQuietly(out);
}

代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-core

@NoRequestLogging
 @GetMapping("/captcha.jpg")
 public void captcha(HttpServletRequest request, HttpServletResponse response)
   throws IOException {
  response.setHeader("Cache-Control", "no-store, no-cache");
  response.setContentType("image/jpeg");
  //生成文字验证码
  String text = producer.createText();
  //生成图片验证码
  BufferedImage image = producer.createImage(text);
  //保存到 session
  request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, text);
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(image, "jpg", out);
 }
}

代码示例来源:origin: yzcheng90/X-SpringBoot

/**
 * 验证码
 */
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
  response.setHeader("Cache-Control", "no-store, no-cache");
  response.setContentType("image/jpeg");
  //生成文字验证码
  String text = producer.createText();
  //生成图片验证码
  BufferedImage image = producer.createImage(text);
  //保存到shiro session
  ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(image, "jpg", out);
  IOUtils.closeQuietly(out);
}

代码示例来源:origin: liuweijw/fw-cloud-framework

/**
 * 创建验证码
 */
@GetMapping(SecurityConstant.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{randomStr}")
public void createCode(@PathVariable String randomStr, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
  response.setHeader("Cache-Control", "no-store, no-cache");
  response.setContentType("image/jpeg");
  // 生成文字验证码
  String text = producer.createText();
  // 生成图片验证码
  BufferedImage image = producer.createImage(text);
  userService.saveImageCode(randomStr, text);
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(image, "JPEG", out);
  IOUtils.closeQuietly(out);
}

代码示例来源:origin: FenixEdu/fenixedu-academic

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws Exception {
  response.setHeader("Cache-Control", "no-store, no-cache");
  // return a jpeg
  response.setContentType("image/jpeg");
  // create the text for the image
  String capText = kaptchaProducer.createText();
  // create the image with the text
  BufferedImage bi = kaptchaProducer.createImage(capText);
  try (ServletOutputStream out = response.getOutputStream()) {
    // write the data out
    ImageIO.write(bi, "jpg", out);
    request.getSession().setAttribute(KAPTCHA_SESSION_KEY, new KaptchaSession(capText));
    return null;
  }
}

代码示例来源:origin: tumao2/hdw-dubbo

@GetMapping("captcha.jpg")
public void kaptcha(HttpServletResponse response, String uuid) throws IOException {
  logger.info("前台请求的UUID:" + uuid);
  if (StringUtils.isBlank(uuid)) {
    throw new RuntimeException("uuid不能为空");
  }
  //生成文字验证码
  String code = producer.createText();
  redisService.set(uuid, code);
  response.setHeader("Cache-Control", "no-store,no-cache");
  response.setContentType("image/jpeg");
  BufferedImage image = producer.createImage(code);
  ServletOutputStream outputStream = response.getOutputStream();
  ImageIO.write(image, "jpg", outputStream);
  IOUtils.closeQuietly(outputStream);
}

代码示例来源:origin: com.github.axet/kaptcha

String capText = this.kaptchaProducer.createText();
BufferedImage bi = this.kaptchaProducer.createImage(capText);

代码示例来源:origin: jtalks-org/jcommune

/**
 * Refresh captcha image on registration form.
 *
 * @param request http request
 * @param response http response
 * @throws IOException
 */
public void refreshCaptchaImage(HttpServletRequest request, HttpServletResponse response)
    throws IOException {
  ServletOutputStream out = response.getOutputStream();
  response.setContentType("image/jpeg");
  String capText = getCaptchaProducer().createText();
  request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
  BufferedImage bi = getCaptchaProducer().createImage(capText);
  ImageIO.write(bi, "jpg", out);
  out.flush();
}

代码示例来源:origin: com.github.vindell/spring-boot-starter-kaptcha

/** */
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
    // Set to expire far in the past.
    resp.setDateHeader("Expires", 0);
    // Set standard HTTP/1.1 no-cache headers.
    resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
    resp.addHeader("Cache-Control", "post-check=0, pre-check=0");
    // Set standard HTTP/1.0 no-cache header.
    resp.setHeader("Pragma", "no-cache");

    // return a jpeg
    resp.setContentType("image/jpeg");

    // create the text for the image
    String capText = this.kaptchaProducer.createText();
    
    this.captchaResolver.setCaptcha(req, resp, capText, new Date());

    // create the image with the text
    BufferedImage bi = this.kaptchaProducer.createImage(capText);

    ServletOutputStream out = resp.getOutputStream();

    // write the data out
    ImageIO.write(bi, "jpg", out);
  }
}

代码示例来源:origin: com.github.penggle/kaptcha

String capText = this.kaptchaProducer.createText();
BufferedImage bi = this.kaptchaProducer.createImage(capText);

代码示例来源:origin: com.wuyushuo/vplus-data

public static void producerCaptcha(Producer captchaProducer, HttpServletRequest request, HttpServletResponse response, String captchaKey) throws Exception {
  if(null == captchaProducer || null == request || null == response){
    throw new NullPointerException("系统参数没有实例化");
  }
  HttpSession session = request.getSession();
  response.setDateHeader("Expires", 0);
  response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
  response.addHeader("Cache-Control", "post-check=0, pre-check=0");
  response.setHeader("Pragma", "no-cache");
  response.setContentType("image/jpeg");
  String capText = captchaProducer.createText();
  String sessionKey = captchaKey(captchaKey);
  log.debug("[captcha] key:{}, value", sessionKey, capText);
  session.setAttribute(sessionKey, capText);
  BufferedImage bi = captchaProducer.createImage(capText);
  ServletOutputStream out = response.getOutputStream();
  ImageIO.write(bi, "jpg", out);
  try {
    out.flush();
  } finally {
    out.close();
  }
}

代码示例来源:origin: liuht777/Taroco

/**
   * 创建验证码
   *
   * @throws Exception
   */
  @GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{randomStr}")
  public void createCode(@PathVariable String randomStr, HttpServletResponse response)
      throws Exception {
    Assert.notEmpty(randomStr, "机器码不能为空");
    response.setHeader("Cache-Control", "no-store, no-cache");
    response.setContentType("image/jpeg");
    //生成文字验证码
    String text = producer.createText();
    //生成图片验证码
    BufferedImage image = producer.createImage(text);
    userService.saveImageCode(randomStr, text);
    ServletOutputStream out = response.getOutputStream();
    ImageIO.write(image, "JPEG", out);
    IOUtils.closeQuietly(out);
  }
}

代码示例来源:origin: penggle/kaptcha

String capText = this.kaptchaProducer.createText();
BufferedImage bi = this.kaptchaProducer.createImage(capText);

相关文章