jfinal-captcha 生成图形验证码

薛经纶
2023-12-01
maven 引用 ${jfinal-captcha.version}替换为相应的版本如:0.1

<dependency>
  <groupId>cn.dreampie</groupId>
  <artifactId>jfinal-captcha</artifactId>
  <version>${jfinal-captcha.version}</version>
</dependency>
 /**
     * 获取验证码
     */
    @ResponseBody
    @RequestMapping(value = "captcha", produces = arrayOf("image/png"))
    fun getCaptcha(@RequestParam("token") token: String): ByteArray {

        val outImg = ByteArrayOutputStream()
        val captcha = captchaService.getCaptcha()
        val image = captcha.image
        val captchaCode = captcha.challenge
        try {
            ImageIO.write(image, "png", outImg)
            return outImg.toByteArray();
        } catch (e: Exception) {
            logger.error("验证码出错输出", e);
            return ByteArray(0)
        } finally {
            try {
                outImg.close()
            } catch (e: IOException) {
                logger.warn("关闭io时出错", e)
            }
        }
    }
 类似资料: