若依框架数字图片验证码实现

您所在的位置:网站首页 图片验证码意义在哪里 若依框架数字图片验证码实现

若依框架数字图片验证码实现

2024-07-13 03:28| 来源: 网络整理| 查看: 265

// 保存验证码信息String uuid = IdUtils.simpleUUID();String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;

String capStr = null, code = null;BufferedImage image = null;

// 生成验证码if ("math".equals(captchaType)){ String capText = captchaProducerMath.createText(); capStr = capText.substring(0, capText.lastIndexOf("@")); code = capText.substring(capText.lastIndexOf("@") + 1); image = captchaProducerMath.createImage(capStr);}else if ("char".equals(captchaType)){ capStr = code = captchaProducer.createText(); image = captchaProducer.createImage(capStr);}

redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);// 转换流信息写出FastByteArrayOutputStream os = new FastByteArrayOutputStream();try{ ImageIO.write(image, "jpg", os);}catch (IOException e){ return AjaxResult.error(e.getMessage());}

ajax.put("uuid", uuid);ajax.put("img", Base64.encode(os.toByteArray()));return ajax;



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3