验证码拖动
1.根据路径创建图片文件,调用SlideCircusUtil.createImage 传入生成图片文件flie,将生成的SlideCircus类文件包含(bigWidth大图宽度,bigHeight大图高度,bigImageBase64大图转BASE64字符串,bigImage大图,posY随机坐标Y,posX随机坐标X,smallWidth小图宽度,smallHeight小图高度,smallImageBase64小图转BASE64字符串,smallImage小图)
2.操作人员根据需要选择输出滑块类中的内容;验证posX或者posY坐标
public String ResImage(HoContext hoContext) throws Exception {
//随机查询出一个图片
List<Map<String, Object>> list = sm_md214.randName(new HashMap<>());
String name = "/uploads/20241204/114337722.png";
if (list.size() > 0) {
name = StringUtils.isEmpty(list.get(0).get("name").toString()) ? name : list.get(0).get("name").toString();
}
File file = new File(rootPath + name);
//根据图片文件生成滑块数据
SlideCircus slideCircus = SlideCircusUtil.createImage(new FileInputStream(file));
if (slideCircus == null) {
System.out.println("图片验证码生成失败");
return JSONObject.toJSONString(slideCircus);
}
File file1 = new File(rootPath + "/uploads/png/demo2BigImage.png");
File file2 = new File(rootPath + "/uploads/png/demo2SmallImage.png");
ImageIO.write(slideCircus.getBigImage(), "png", file1);
ImageIO.write(slideCircus.getSmallImage(), "png", file2);
//保存到session中
hoContext.httpRequest.setSession("posX", slideCircus.getPosX());
slideCircus.setBigImage(null);
slideCircus.setSmallImage(null);
slideCircus.setPosX(0);
return JSONObject.toJSONString(slideCircus);
}
扫一扫