破解网站码验证,Java实现,不调用任何平台api接口
package image.images; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
/**
* 负责爬去验证码图片
* @author FMm
*
*/
public class HttpClientImage { public static void main(String[] args) throws ClientProtocolException, IOException, InterruptedException {
// 创建httpClient实例
CloseableHttpClient httpClient = HttpClients.createDefault();
// url
String url = "http://con.monyun.cn:9960/aut_checkCode.hts?iden=1422083454409442236&t=0.06292891333169814";
// 循环爬去20张验证码
for (int i = 0; i < 20; i++) {
// 休眠一下否则图片加载不出来,
Thread.sleep(2000);
// 创建请求
HttpGet httpGet = new HttpGet(url);
// 执行请求
CloseableHttpResponse response = httpClient.execute(httpGet);
// 获取实体对象
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) {
// 打印返回类型保证是图片类型
System.out.println("Content-Type:" + httpEntity.getContentType().getValue());
// 获取InputStream流
InputStream inputStream = httpEntity.getContent();
// 文件复制,common io 包下,需要 引入依赖
FileUtils.copyToFile(inputStream, new File("/Users/mac/Desktop/image/" + i + ".png"));
}
}
httpClient.close();
}
}
package image.images; import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import javax.net.ssl.HttpsURLConnection;
/**
* 图片背景处理,提高识别度
* @author FMm
*
*/
public class ImageConverter { private static List<File> fileList = new ArrayList<File>(); public static void main(String[] args) { // 图片所在的根目录 , 图片去除水印后的存储目录
// 支持批量去除图片水印,第一个参数为图片存在目录,第二为新建图片目录
convertAllImages("/Users/mac/Desktop/image/", "/Users/mac/Desktop/images/");
} private static void convertAllImages(String dir, String saveDir) {
File dirFile = new File(dir);
File saveDirFile = new File(saveDir);
dir = dirFile.getAbsolutePath();
saveDir = saveDirFile.getAbsolutePath();
loadImages(new File(dir));
for (File file : fileList) {
String filePath = file.getAbsolutePath(); String dstPath = saveDir + filePath.substring(filePath.indexOf(dir) + dir.length(), filePath.length());
System.out.println("converting: " + filePath);
replaceColor(file.getAbsolutePath(), dstPath);
}
} public static void loadImages(File f) {
if (f != null) {
if (f.isDirectory()) {
File[] fileArray = f.listFiles();
if (fileArray != null) {
for (int i = 0; i < fileArray.length; i++) {
loadImages(fileArray[i]);
}
}
} else {
String name = f.getName();
if (name.endsWith("png") || name.endsWith("jpg")) {
fileList.add(f);
}
}
}
} @SuppressWarnings("unused")
private static void replaceFolderImages(String dir) {
File dirFile = new File(dir);
File[] files = dirFile.listFiles(new FileFilter() {
public boolean accept(File file) {
String name = file.getName();
if (name.endsWith("png") || name.endsWith("jpg")) {
return true;
}
return false;
}
});
for (File img : files) {
replaceColor(img.getAbsolutePath(), img.getAbsolutePath());
}
} private static void replaceColor(String srcFile, String dstFile) {
try {
Color color = new Color(255, 195, 195);
replaceImageColor(srcFile, dstFile, color, Color.WHITE);
} catch (IOException e) {
e.printStackTrace();
}
} public static void replaceImageColor(String file, String dstFile, Color srcColor, Color targetColor)
throws IOException {
URL http;
if (file.trim().startsWith("https")) {
http = new URL(file);
HttpsURLConnection conn = (HttpsURLConnection) http.openConnection();
conn.setRequestMethod("GET");
} else if (file.trim().startsWith("http")) {
http = new URL(file);
HttpURLConnection conn = (HttpURLConnection) http.openConnection();
conn.setRequestMethod("GET");
} else {
http = new File(file).toURI().toURL();
}
BufferedImage bi = ImageIO.read(http.openStream());
if (bi == null) {
return;
} Color wColor = new Color(255, 255, 255);// 白色 for (int i = 0; i < bi.getWidth(); i++) {
for (int j = 0; j < bi.getHeight(); j++) {
System.out.println(i + "---" + j);
int color = bi.getRGB(i, j);
Color oriColor = new Color(color);
int red = oriColor.getRed();
int greed = oriColor.getGreen();
int blue = oriColor.getBlue();
// 以下if处是则改变图片颜色 将图片背景改变成纯白色,提高识别度
if (i < 4 | i > 100) {
bi.setRGB(i, j, wColor.getRGB());
//bi.setRGB()方法是把对应的xy坐标的颜色改变成纯白色Color wColor = new Color(255, 255, 255);// 白色
} if (j < 4 | j > 35) {
bi.setRGB(i, j, wColor.getRGB());
} if (red < 107 && greed < 107 && blue < 107) {
bi.setRGB(i, j, wColor.getRGB()); }
if ((red <= 255 && red > 200) & (greed <= 255 && greed >= 200) & blue <= 255 && blue >= 200) {
bi.setRGB(i, j, wColor.getRGB());
}
}
}
String type = file.substring(file.lastIndexOf(".") + 1, file.length());
Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName(type);
ImageWriter writer = it.next();
File f = new File(dstFile);
f.getParentFile().mkdirs();
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
writer.setOutput(ios);
writer.write(bi);
bi.flush();
ios.flush();
ios.close();
}
}
package image.images; import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
/**
* 读取验证码并返回结构
* @author FMm
*
*/
public class ReadImage { public static void main(String[] args) throws TesseractException {
ITesseract instance = new Tesseract();
//如果未将tessdata放在根目录下需要指定绝对路径,tessdata包下是tess4j训练语言包
instance.setDatapath("/Users/mac/Desktop/tessdata");
//如果需要识别英文之外的语种,需要指定识别语种,并且需要将对应的语言包放进项目中
instance.setLanguage("eng");
// 指定识别图片路径
File imgDir = new File("/Users/mac/Desktop/images/8.png");
long startTime = System.currentTimeMillis();
String ocrResult = instance.doOCR(imgDir);
System.out.println(ocrResult);
if(isStartWithNumber(ocrResult)) {
String start = ocrResult.substring(0,1);
String meg = ocrResult.substring(1,2);
String end = ocrResult.substring(2,3);
// 输出识别结果
System.out.println("OCR Result: \n" + ocrResult + "\n 耗时:" + (System.currentTimeMillis() - startTime) + "ms");
// 得出结果
System.out.println(start+meg+end+"="+(Integer.parseInt(start)+Integer.parseInt(end)));
} else {
System.out.println("仅支持数字");
return;
} } public static boolean isStartWithNumber(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str.charAt(0)+"");
if (!isNum.matches()) {
return false;
}
return true;
}
}
maven文件
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>image</groupId>
<artifactId>images</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>images</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.8</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.12.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>4.4.1</version>
</dependency>
</dependencies>
</project>
不是maven项目所需jar
p.p1 { margin: 0; font: 12px Menlo; color: rgba(66, 66, 66, 1) }
org/apache/httpcomponents/httpclient/4.5.8/httpclient-4.5.8.jar
org/apache/httpcomponents/httpcore/4.4.11/httpcore-4.4.11.jar
commons-logging/commons-logging/1.2/commons-logging-1.2.jar
commons-codec/commons-codec/1.11/commons-codec-1.11.jar
org/jsoup/jsoup/1.12.1/jsoup-1.12.1.jar
commons-io/commons-io/2.5/commons-io-2.5.jar
com/alibaba/fastjson/1.2.47/fastjson-1.2.47.jar
junit/junit/3.8.1/junit-3.8.1.jar
net/sourceforge/tess4j/tess4j/4.4.1/tess4j-4.4.1.jar
net/java/dev/jna/jna/5.4.0/jna-5.4.0.jar
com/github/jai-imageio/jai-imageio-core/1.4.0/jai-imageio-core-1.4.0.jar
org/ghost4j/ghost4j/1.0.1/ghost4j-1.0.1.jar
log4j/log4j/1.2.17/log4j-1.2.17.jar
commons-beanutils/commons-beanutils/1.9.2/commons-beanutils-1.9.2.jar
commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
org/apache/xmlgraphics/xmlgraphics-commons/1.4/xmlgraphics-commons-1.4.jar
com/lowagie/itext/2.1.7/itext-2.1.7.jar
org/apache/pdfbox/pdfbox/2.0.17/pdfbox-2.0.17.jar
org/apache/pdfbox/fontbox/2.0.17/fontbox-2.0.17.jar
org/apache/pdfbox/pdfbox-tools/2.0.17/pdfbox-tools-2.0.17.jar
org/apache/pdfbox/pdfbox-debugger/2.0.17/pdfbox-debugger-2.0.17.jar
org/apache/pdfbox/jbig2-imageio/3.0.2/jbig2-imageio-3.0.2.jar
net/sourceforge/lept4j/lept4j/1.12.3/lept4j-1.12.3.jar
org/jboss/jboss-vfs/3.2.14.Final/jboss-vfs-3.2.14.Final.jar
org/jboss/logging/jboss-logging/3.1.4.GA/jboss-logging-3.1.4.GA.jar
ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar
org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar
org/slf4j/jul-to-slf4j/1.7.28/jul-to-slf4j-1.7.28.jar
org/slf4j/jcl-over-slf4j/1.7.28/jcl-over-slf4j-1.7.28.jar
org/slf4j/log4j-over-slf4j/1.7.28/log4j-over-slf4j-1.7.28.jar
所需的tess4j文件,文件名称:tessdata/,这个文件你可以放在项目中,也可以放在其他位置但是路径不能写错
tessdata/
chi_sim.traineddata // 中文识别
eng.traineddata //数字识别 下载地址https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/eng.traineddata
osd.traineddata
pdf.ttf
pdf.ttx
readme
tess4j官网文件下载:https://sourceforge.net/projects/tess4j/
破解网站码验证,Java实现,不调用任何平台api接口的更多相关文章
- 破解网站二维码验证,Java实现,不调用任何平台api接口
package image.images; import java.io.File; import java.io.IOException; import java.io.InputStream; i ...
- Java对接拼多多开放平台API(加密上云等全流程)
前言 本文为[小小赫下士 blog]原创,搬运请保留本段,或请在醒目位置设置原文地址和原作者. 作者:小小赫下士 原文地址:Java对接拼多多开放平台API(加密上云等全流程) 本文章为企业ERP(I ...
- Java生鲜电商平台-API接口设计之token、timestamp、sign 具体架构与实现(APP/小程序,传输安全)
Java生鲜电商平台-API接口设计之token.timestamp.sign 具体设计与实现 说明:在实际的业务中,难免会跟第三方系统进行数据的交互与传递,那么如何保证数据在传输过程中的安全呢(防窃 ...
- json-lib-2.4-jdk15.jar所需全部JAR包.rar java jsoup解析开彩网api接口json数据实例
json-lib-2.4-jdk15.jar所需全部JAR包.rar java jsoup解析开彩网api接口json数据实例 json-lib-2.4-jdk15.jar所需全部JAR包.rar ...
- 用Python调用华为云API接口发短信
[摘要] 用Python调用华为云API接口实现发短信,当然能给调用发短信接口前提条件是通过企业实名认证,而且有一个通过审核的短信签名,话不多说,showcode #!/usr/bin/python3 ...
- Angular 调用百度地图API接口
Angular 调用百度地图API接口 参考原文:https://blog.csdn.net/yuyinghua0302/article/details/80624274 下面简单介绍一下如何在Ang ...
- java EE技术体系——CLF平台API开发注意事项(4)——API生命周期治理简单说明
文档说明 截止日期:20170905,作者:何红霞,联系方式:QQ1028335395.邮箱:hehongxia626@163.com 综述 有幸加入到javaEE技术体系的研究与开发,也得益于大家的 ...
- Python如何调用新浪api接口的问题
前言:这些天在研究如何调用新浪开放平台的api分析新浪微博用户的数据 成果:成功调用了新浪api获取了用户的一些个人信息和无数条公共微博 不足:新浪开放平台访问有限制,返回的数据着实有限,不足以分析问 ...
- Java生鲜电商平台-API接口设计之token、timestamp、sign 具体设计与实现
转载:https://www.cnblogs.com/jurendage/p/12653865.html 说明:在实际的业务中,难免会跟第三方系统进行数据的交互与传递,那么如何保证数据在传输过程中的安 ...
随机推荐
- 消失之物(背包DP)(容斥或分治)
容斥做法: 首先n^2搞出f[i][j]第i个物品,j体积的方案数. 去除每个物品贡献: 设个g[i][j]表示当i不选,j体积方案数(注意不是此时的范围相对于全局,而不是1---i) 那么我们用到一 ...
- Python 机器学习实战 —— 监督学习(下)
前言 近年来AI人工智能成为社会发展趋势,在IT行业引起一波热潮,有关机器学习.深度学习.神经网络等文章多不胜数.从智能家居.自动驾驶.无人机.智能机器人到人造卫星.安防军备,无论是国家级军事设备还是 ...
- Golang编写Windows动态链接库(DLL)及C调用范例
一.准备. 1.GoLang在1.10版本之后开始支持编译windows动态链接库,可以打开命令行工具使用go version 查看自己的go版本. 2.你的电脑上需要gcc,如果没有的话[点击这里] ...
- DNS 解析过程
DNS 是应用层协议,用于将域名转换成 IP 地址. 1. 解析过程 DNS 的核心系统是一个三层的树状.分布式服务,基本对应域名的结构. 根域名服务器:管理顶级域名服务器,返回 com.net.cn ...
- Layui 关闭自己刷新父页面
var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); window.parent.locati ...
- angularjs的一点总结
一,错误小结 1.出现类似于下面的错误,就是说明 $sessionStorage 这个服务未找到 Error: [$injector:unpr] Unknown provider: $sessionS ...
- 1.3.2、通过Cookie匹配
server: port: 8080 spring: application: name: gateway cloud: gateway: routes: - id: guo-system4 uri: ...
- Python调用shell命令常用方法
Python调用shell指令 方法一.使用os模块的system方法:os.system(cmd),其返回值是shell指令运行后返回的状态码,int类型,0表示shell指令成功执行,256表示未 ...
- pixel的Edxposed刷机过程
1.先解开bl锁 这里的步骤,因为我机子本来就是解过的了,所以简单记录一下过程好了 第一步:确保你的环境变量是否设置好了,判断的标准就是打开终端(我是mac),usb连接上,然后输入 adb devi ...
- 羊城杯wp babyre
肝了好久,没爆破出来,就很难受,就差这题没写了,其他三题感觉挺简单的,这题其实也不是很难,我感觉是在考算法. 在输入之前有个smc的函数,先动调,attach上去,ida打开那个关键函数. 代码逻辑还 ...