importjava.io.*;
importnet.sourceforge.tess4j.ITesseract;
importnet.sourceforge.tess4j.Tesseract;
importjava.text.SimpleDateFormat;
importjava.util.Date;
//设置日期格式,如2022-05-17-12-08-11-548
SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS");
//将验证码保存到本地文件中
StringimgPath="D:/captcha/"+df.format(newDate())+"-captcha.jpg";
byte[]responseBody=prev.getResponseData();
FileimageFile=newFile(imgPath);
OutputStreamout=newFileOutputStream(imageFile);
out.write(responseBody);
out.flush();
out.close();
//读取图片数字
FileimageFile1=newFile(imgPath);
ITesseractinstance=newTesseract();
//Tess4j解压文件里的tessdata目录下
instance.setDatapath("D:/__Download/GoogleDownload/Tess4J/tessdata");
//英文库识别数字比较准确
instance.setLanguage("eng");
captcha=instance.doOCR(imageFile1).replace("\n","");
log.info("thiscaptchais:"+captcha);
vars.put("captcha",captcha);
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |