Compare commits
No commits in common. "master" and "main" have entirely different histories.
|
|
@ -0,0 +1,13 @@
|
||||||
|
# ---> AL
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
*.app
|
||||||
|
.snapshots/*
|
||||||
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
Attribution Assurance License
|
||||||
|
|
||||||
|
Copyright (c) 2002 by AUTHOR PROFESSIONAL IDENTIFICATION * URL "PROMOTIONAL SLOGAN FOR AUTHOR'S PROFESSIONAL PRACTICE"
|
||||||
|
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
ATTRIBUTION ASSURANCE LICENSE (adapted from the original BSD license)
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the conditions below are met. These conditions require a modest attribution to fangl (the "Author"), who hopes that its promotional value may help justify the thousands of dollars in otherwise billable time invested in writing this and other freely available, open-source software.
|
||||||
|
|
||||||
|
1. Redistributions of source code, in whole or part and with or without modification (the "Code"), must prominently display this GPG-signed text in verifiable form.
|
||||||
|
|
||||||
|
2. Redistributions of the Code in binary form must be accompanied by this GPG-signed text in any documentation and, each time the resulting executable program or a program dependent thereon is launched, a prominent display (e.g., splash screen or banner text) of the Author's attribution information, which includes:
|
||||||
|
|
||||||
|
(a) Name ("AUTHOR"),
|
||||||
|
(b) Professional identification ("PROFESSIONAL IDENTIFICATION"), and
|
||||||
|
(c) URL ("URL").
|
||||||
|
|
||||||
|
3. Neither the name nor any trademark of the Author may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
4. Users are entirely responsible, to the exclusion of the Author and any other persons, for compliance with (1) regulations set by owners or administrators of employed equipment, (2) licensing terms of any other software, and (3) local regulations regarding use, including those regarding import, export, and use of encryption software.
|
||||||
|
|
||||||
|
THIS FREE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR ANY CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, EFFECTS OF UNAUTHORIZED OR MALICIOUS NETWORK ACCESS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
64
pom.xml
64
pom.xml
|
|
@ -1,64 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<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>autoWebForCaiGou</groupId>
|
|
||||||
<artifactId>autoWebForCaiGou</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
<target>8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>3.4</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
|
||||||
<artifactId>selenium-java</artifactId>
|
|
||||||
<version>3.141.59</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
<!--log4j-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging-api</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>1.7.26</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<version>1.7.26</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-all</artifactId>
|
|
||||||
<version>5.8.16</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: com.bonus.autoweb.TestMain
|
|
||||||
|
|
||||||
|
|
@ -1,261 +0,0 @@
|
||||||
package com.bonus.autoweb;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.openqa.selenium.*;
|
|
||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
|
||||||
import org.openqa.selenium.chrome.ChromeOptions;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动化操作
|
|
||||||
*
|
|
||||||
* @author 吕继龙
|
|
||||||
*/
|
|
||||||
public class AutoMain {
|
|
||||||
//登录的次数
|
|
||||||
private int loginNum = 20;
|
|
||||||
//浏览器驱动对象
|
|
||||||
private WebDriver webDriver;
|
|
||||||
/**
|
|
||||||
* 初始化驱动
|
|
||||||
*/
|
|
||||||
public void initDrive() {
|
|
||||||
System.out.println("自动评价开始------------");
|
|
||||||
// chromedriver服务地址
|
|
||||||
System.setProperty(DataConfig.DRIVE_NAME, DataConfig.drivePath);
|
|
||||||
ChromeOptions option = new ChromeOptions();
|
|
||||||
option.addArguments("disable-infobars");
|
|
||||||
option.setBinary("D:\\auto_handle\\Chrome-bin\\chrome.exe");
|
|
||||||
// option.addArguments("--headless"); //隐藏页面
|
|
||||||
webDriver = new ChromeDriver(option);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开始工作
|
|
||||||
*/
|
|
||||||
public void startAuto() throws Exception {
|
|
||||||
login();
|
|
||||||
if (loginNum <= 0) {
|
|
||||||
closeDrive();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
autoHandle();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
startAuto();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模拟评价
|
|
||||||
*/
|
|
||||||
private void autoHandle() throws Exception {
|
|
||||||
Thread.sleep(45*1000);
|
|
||||||
openMyAppraise();
|
|
||||||
startAppraise();
|
|
||||||
closeDrive();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打开网站
|
|
||||||
*/
|
|
||||||
public void openWeb() throws InterruptedException {
|
|
||||||
//第一步打开指定网站
|
|
||||||
webDriver.get(DataConfig.URL); // 打开指定的网站
|
|
||||||
System.out.println("打开订单评价网站------------");
|
|
||||||
Thread.sleep(2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打开网站并登录系统
|
|
||||||
*/
|
|
||||||
private void login() throws InterruptedException {
|
|
||||||
//******************************************************************
|
|
||||||
/**
|
|
||||||
* 第二步 用户登录
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
//角色选择
|
|
||||||
webDriver.findElement(By.id("userType")).click();
|
|
||||||
Thread.sleep(600);
|
|
||||||
webDriver.findElement(By.xpath("//*[@id=\"form_submit\"]/ul/li[1]/div/div/ul/li[1]")).click();
|
|
||||||
System.out.println("选择角色------------");
|
|
||||||
Thread.sleep(300);
|
|
||||||
|
|
||||||
//输入用户名
|
|
||||||
webDriver.findElement(By.id("username")).sendKeys(DataConfig.USER_NAME);
|
|
||||||
System.out.println("输入用户名------------");
|
|
||||||
Thread.sleep(300);
|
|
||||||
|
|
||||||
//输入密码
|
|
||||||
webDriver.findElement(By.id("password")).sendKeys(DataConfig.PASS);
|
|
||||||
System.out.println("输入密码------------");
|
|
||||||
Thread.sleep(300);
|
|
||||||
loginNum--;
|
|
||||||
}catch(NoSuchWindowException e){
|
|
||||||
System.out.println(e);
|
|
||||||
closeDrive();
|
|
||||||
}
|
|
||||||
//***********验证码识别start*****************
|
|
||||||
|
|
||||||
// verCodeHandler();
|
|
||||||
// Thread.sleep(30000);
|
|
||||||
// webDriver.findElement(By.className("login-btn")).click();
|
|
||||||
}
|
|
||||||
|
|
||||||
//结束进程
|
|
||||||
public void endProcess() {
|
|
||||||
// try{
|
|
||||||
// String[] cmd = { "自动操作助手.exe"};
|
|
||||||
// Process proc = Runtime.getRuntime().exec(cmd);//开启文本
|
|
||||||
// BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
|
|
||||||
// String string_Temp = in.readLine();
|
|
||||||
// while (string_Temp != null)
|
|
||||||
// {
|
|
||||||
// System.out.println(string_Temp);
|
|
||||||
// if(string_Temp.contains("自动操作助手.exe"))
|
|
||||||
// Runtime.getRuntime().exec("Taskkill /IM 自动操作助手.exe");
|
|
||||||
// string_Temp = in.readLine();
|
|
||||||
// }
|
|
||||||
// }catch (Exception e){
|
|
||||||
// //结束进程
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码操作
|
|
||||||
*/
|
|
||||||
private void verCodeHandler() throws Exception {
|
|
||||||
System.out.println("验证码验证开始------------");
|
|
||||||
loginNum--;
|
|
||||||
/**
|
|
||||||
* 循环十次成功退出
|
|
||||||
*/
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 10; i++) {
|
|
||||||
String imageUrl = webDriver.findElement(By.id("personSecurityCode")).getAttribute("src");
|
|
||||||
Thread.sleep(500);
|
|
||||||
String verCode = VerCode.verCodeHandler(imageUrl);
|
|
||||||
System.out.println("验证码识别结果:" + verCode);
|
|
||||||
if (StringUtils.isEmpty(verCode)) {
|
|
||||||
System.out.println("第" + (i + 1) + "次验证失败!");
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
System.out.println("第" + (i + 1) + "次验证成功!");
|
|
||||||
Thread.sleep(300);
|
|
||||||
webDriver.findElement(By.id("person_reg_security")).sendKeys(verCode);
|
|
||||||
Thread.sleep(300);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i < 10) {
|
|
||||||
//点击登录
|
|
||||||
System.out.println("登录系统------------");
|
|
||||||
webDriver.findElement(By.className("login-btn")).click();
|
|
||||||
Thread.sleep(3000);
|
|
||||||
|
|
||||||
try {
|
|
||||||
webDriver.findElement(By.id("to_seach_id")).sendKeys("你好");
|
|
||||||
Thread.sleep(300);
|
|
||||||
} catch (Exception e) {
|
|
||||||
verCodeHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
verCodeHandler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 第三步 打开我的评价页面
|
|
||||||
*
|
|
||||||
* @throws InterruptedException
|
|
||||||
*/
|
|
||||||
private void openMyAppraise() throws InterruptedException {
|
|
||||||
|
|
||||||
webDriver.get("http://buser.esgcc.com.cn/order/list"); // 打开指定的网站
|
|
||||||
System.out.println("打开订单页面------------");
|
|
||||||
webDriver.navigate().refresh();
|
|
||||||
Thread.sleep(300);
|
|
||||||
|
|
||||||
//打开我的评价
|
|
||||||
webDriver.findElement(By.id("ctl_menu_viewhis")).click();
|
|
||||||
System.out.println("点击我的评价------------");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
try {
|
|
||||||
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
// webDriver.quit();
|
|
||||||
}
|
|
||||||
Thread.sleep(3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开始评价工作
|
|
||||||
*/
|
|
||||||
private void startAppraise() throws InterruptedException {
|
|
||||||
/**
|
|
||||||
* 第四步 获取所有未评价数据,并进行评价
|
|
||||||
*/
|
|
||||||
//获取所有的评价标签
|
|
||||||
List<WebElement> list = webDriver.findElements(By.className("btn-sm-one"));
|
|
||||||
System.out.println("开始获取未评价的列表------------数量为:"+(list.size()-1));
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
WebElement element = list.get(i);
|
|
||||||
String path = element.getAttribute("href");
|
|
||||||
System.out.println(path);
|
|
||||||
if (StringUtils.isEmpty(path)) {
|
|
||||||
list.remove(i);
|
|
||||||
i--;
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
//打开订单评价的页面
|
|
||||||
//属性重新赋值
|
|
||||||
JavascriptExecutor jss = (JavascriptExecutor) webDriver;
|
|
||||||
jss.executeScript("arguments[0].setAttribute(arguments[1],arguments[2])", element, "target", "");
|
|
||||||
element.click();
|
|
||||||
Thread.sleep(300);
|
|
||||||
//评价
|
|
||||||
Random random = new Random(5);
|
|
||||||
int m = random.nextInt(5);
|
|
||||||
webDriver.findElement(By.id("evaluate_content1")).sendKeys(DataConfig.handleContent[m]);
|
|
||||||
Thread.sleep(300);
|
|
||||||
|
|
||||||
//提交评价
|
|
||||||
webDriver.findElement(By.className("submit_btn")).click();
|
|
||||||
Thread.sleep(300);
|
|
||||||
|
|
||||||
webDriver.navigate().back();
|
|
||||||
Thread.sleep(300);
|
|
||||||
webDriver.navigate().refresh();
|
|
||||||
Thread.sleep(300);
|
|
||||||
|
|
||||||
list = webDriver.findElements(By.className("btn-sm-one"));
|
|
||||||
Thread.sleep(300);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关闭浏览器驱动
|
|
||||||
*/
|
|
||||||
private void closeDrive() {
|
|
||||||
System.out.println("工作完成,退出浏览器");
|
|
||||||
webDriver.quit();
|
|
||||||
endProcess();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
package com.bonus.autoweb;
|
|
||||||
|
|
||||||
public class DataConfig {
|
|
||||||
/**
|
|
||||||
* url 网站地址
|
|
||||||
*/
|
|
||||||
protected static final String URL = "http://b.esgcc.com.cn/";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 驱动名称
|
|
||||||
*/
|
|
||||||
protected static final String DRIVE_NAME = "webdriver.chrome.driver";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户名
|
|
||||||
*/
|
|
||||||
protected static final String USER_NAME = "18255755085";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 密码
|
|
||||||
*/
|
|
||||||
protected static final String PASS = "zk@3073825";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 浏览器驱动地址
|
|
||||||
*/
|
|
||||||
protected static final String drivePath = "D:\\auto_handle\\chromedriver.exe";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码识别接口地址
|
|
||||||
*/
|
|
||||||
protected static final String OCR_URL="http://localhost:7011/ocr";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码图片下载地址
|
|
||||||
*/
|
|
||||||
protected static final String verCodePath = "E:\\vercodeTest\\";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 评价内容
|
|
||||||
*/
|
|
||||||
protected static final String[] handleContent = {"产品还可以。","供应商服务态度好。","能够按时发货。服务好",
|
|
||||||
"外观无破损,服务、质量较好。","质量很好,有需要下次还会回购!"};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
package com.bonus.autoweb;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
|
|
||||||
public class TestMain {
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
AutoMain autoMain=new AutoMain();
|
|
||||||
|
|
||||||
autoMain.initDrive();
|
|
||||||
|
|
||||||
autoMain.openWeb();
|
|
||||||
|
|
||||||
autoMain.startAuto();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,112 +0,0 @@
|
||||||
package com.bonus.autoweb;
|
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
|
||||||
import cn.hutool.http.HttpUtil;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码识别
|
|
||||||
*/
|
|
||||||
public class VerCode {
|
|
||||||
/**
|
|
||||||
* 验证码识别
|
|
||||||
*
|
|
||||||
* @param imageUrl
|
|
||||||
*/
|
|
||||||
public static String verCodeHandler(String imageUrl) throws Exception {
|
|
||||||
//下载验证码
|
|
||||||
String filePath = downLoadVerCodeImage(imageUrl);
|
|
||||||
if (StringUtils.isEmpty(filePath)) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
String result = vercodeDesc(filePath);
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(result) || result.length() != 4) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码识别
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String vercodeDesc(String filePath) {
|
|
||||||
File f=new File(filePath);
|
|
||||||
byte[] bytes = FileUtil.readBytes(f);
|
|
||||||
String result = HttpUtil.createPost(DataConfig.OCR_URL).body(bytes).execute().body();
|
|
||||||
if("-1".equals(result)){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载验证码图片
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String downLoadVerCodeImage(String imagePath) throws Exception {
|
|
||||||
//定义一个URL对象,就是你想下载的图片的URL地址
|
|
||||||
URL url = new URL(imagePath);
|
|
||||||
//打开连接
|
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
||||||
//设置请求方式为"GET"
|
|
||||||
conn.setRequestMethod("GET");
|
|
||||||
//超时响应时间为10秒
|
|
||||||
conn.setConnectTimeout(10 * 1000);
|
|
||||||
//通过输入流获取图片数据
|
|
||||||
InputStream is = conn.getInputStream();
|
|
||||||
//得到图片的二进制数据,以二进制封装得到数据,具有通用性
|
|
||||||
byte[] data = readInputStream(is);
|
|
||||||
//创建一个文件对象用来保存图片,默认保存当前工程根目录,起名叫Copy.jpg
|
|
||||||
|
|
||||||
String filePath = DataConfig.verCodePath + "verCode.jpg";
|
|
||||||
File imageFile = new File(filePath);
|
|
||||||
//创建输出流
|
|
||||||
FileOutputStream outStream = new FileOutputStream(imageFile);
|
|
||||||
//写入数据
|
|
||||||
outStream.write(data);
|
|
||||||
//关闭输出流,释放资源
|
|
||||||
outStream.close();
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static byte[] readInputStream(InputStream inStream) throws Exception {
|
|
||||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
|
||||||
//创建一个Buffer字符串
|
|
||||||
byte[] buffer = new byte[6024];
|
|
||||||
//每次读取的字符串长度,如果为-1,代表全部读取完毕
|
|
||||||
int len;
|
|
||||||
//使用一个输入流从buffer里把数据读取出来
|
|
||||||
while ((len = inStream.read(buffer)) != -1) {
|
|
||||||
//用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度
|
|
||||||
outStream.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
//关闭输入流
|
|
||||||
inStream.close();
|
|
||||||
//把outStream里的数据写入内存
|
|
||||||
return outStream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main( String[] args ) {
|
|
||||||
File dir = new File("E:\\vercodeTest");
|
|
||||||
for(File f:dir.listFiles()) {
|
|
||||||
byte[] bytes = FileUtil.readBytes(f);
|
|
||||||
String result = HttpUtil.createPost("http://localhost:7011/ocr").body(bytes).execute().body();
|
|
||||||
FileUtil.copy(f, new File("E:\\vercodeTest\\vercodeTest4\\"+result+".jpg"), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
### 设置###
|
|
||||||
log4j.rootLogger = debug,stdout,D,E
|
|
||||||
|
|
||||||
### 输出信息到控制抬 ###
|
|
||||||
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.stdout.Target = System.out
|
|
||||||
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
|
|
||||||
|
|
||||||
### 输出DEBUG 级别以上的日志到=E://logs/error.log ###
|
|
||||||
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
|
|
||||||
log4j.appender.D.File = logs/log.log
|
|
||||||
log4j.appender.D.Append = true
|
|
||||||
log4j.appender.D.Threshold = DEBUG
|
|
||||||
log4j.appender.D.layout = org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
|
||||||
|
|
||||||
### 输出ERROR 级别以上的日志到=E://logs/error.log ###
|
|
||||||
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
|
|
||||||
log4j.appender.E.File =logs/error.log
|
|
||||||
log4j.appender.E.Append = true
|
|
||||||
log4j.appender.E.Threshold = ERROR
|
|
||||||
log4j.appender.E.layout = org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
|
||||||
Loading…
Reference in New Issue