Springboot 生成中文、算术等图形验证码

  • Post author:
  • Post category:其他


<dependencies>
   <dependency>
      <groupId>com.github.whvcse</groupId>
      <artifactId>easy-captcha</artifactId>
      <version>1.6.2</version>
   </dependency>
</dependencies>

@Controller
public class CaptchaController {

    @RequestMapping("/captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        CaptchaUtil.out(request, response);
        /**
         *Captcha captcha = new ChineseCaptcha();
         *获取本次生成的验证码
         *String text = captcha.text();
         *System.out.println(text);
         *
         *输出验证码图片到d盘
         *captcha.out(new FileOutputStream(new File("d:\\test.png")));
         *
         *算术验证码
         *Captcha captcha1 = new ArithmeticCaptcha();
         *获取本次生成的验证码
         *String text1 = captcha1.text();
         *System.out.println(text1);
         * CaptchaUtil.ver(verCode, request)   //返回 true 或false
         */
    }
}



版权声明:本文为xljx_1原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。