Commit a573a180 authored by lc@weface.com.cn's avatar lc@weface.com.cn

Initial commit

parents
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ]; then
if [ -f /etc/mavenrc ]; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ]; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false
darwin=false
mingw=false
case "$(uname)" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true ;;
Darwin*)
darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="$(/usr/libexec/java_home)"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ]; then
if [ -r /etc/gentoo-release ]; then
JAVA_HOME=$(java-config --jre-home)
fi
fi
if [ -z "$M2_HOME" ]; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ]; do
ls=$(ls -ld "$PRG")
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '/.*' >/dev/null; then
PRG="$link"
else
PRG="$(dirname "$PRG")/$link"
fi
done
saveddir=$(pwd)
M2_HOME=$(dirname "$PRG")/..
# make it fully qualified
M2_HOME=$(cd "$M2_HOME" && pwd)
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=$(cygpath --unix "$M2_HOME")
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
[ -n "$CLASSPATH" ] &&
CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw; then
[ -n "$M2_HOME" ] &&
M2_HOME="$( (
cd "$M2_HOME"
pwd
))"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="$( (
cd "$JAVA_HOME"
pwd
))"
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="$(which javac)"
if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=$(which readlink)
if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then
if $darwin; then
javaHome="$(dirname \"$javaExecutable\")"
javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac"
else
javaExecutable="$(readlink -f \"$javaExecutable\")"
fi
javaHome="$(dirname \"$javaExecutable\")"
javaHome=$(expr "$javaHome" : '\(.*\)/bin')
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ]; then
if [ -n "$JAVA_HOME" ]; then
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="$(which java)"
fi
fi
if [ ! -x "$JAVACMD" ]; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ]; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]; then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ]; do
if [ -d "$wdir"/.mvn ]; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=$(
cd "$wdir/.."
pwd
)
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' <"$1")"
fi
}
BASE_DIR=$(find_maven_basedir "$(pwd)")
if [ -z "$BASE_DIR" ]; then
exit 1
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
if [ -n "$MVNW_REPOURL" ]; then
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
else
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
fi
while IFS="=" read key value; do
case "$key" in wrapperUrl)
jarUrl="$value"
break
;;
esac
done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if $cygwin; then
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
fi
if command -v wget >/dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget "$jarUrl" -O "$wrapperJarPath"
else
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
fi
elif command -v curl >/dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl -o "$wrapperJarPath" "$jarUrl" -f
else
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
# For Cygwin, switch paths to Windows format before running javac
if $cygwin; then
javaClass=$(cygpath --path --windows "$javaClass")
fi
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=$(cygpath --path --windows "$M2_HOME")
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME")
[ -n "$CLASSPATH" ] &&
CLASSPATH=$(cygpath --path --windows "$CLASSPATH")
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR")
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.thr</groupId>
<artifactId>ocr</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>thr-ocr</name>
<description>idcard ocr</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.6.8</version>
</dependency>
</dependencies>
<build>
<finalName>ocr</finalName>
<plugins>
<!--add this for docker-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<serverId>docker_ops</serverId>
<registryUrl>registry-vpc.cn-shanghai.aliyuncs.com</registryUrl>
<imageName>registry-vpc.cn-shanghai.aliyuncs.com/kankanops/ocr:V1.0</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<skipDockerBuild>false</skipDockerBuild>
<pushImage>true</pushImage>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<!--add this for docker-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
FROM registry.cn-shanghai.aliyuncs.com/kankanops/jdk8:V2.1
ADD ocr.jar /webapps/app.jar
ADD libOCRDLL_THR.so /usr/lib/
ADD linux_option.cfg /usr/lib/
ADD license.dat /usr/lib/data/
ADD trData.mdl /usr/lib/data/
rbGafRvb0wJQVpDotHrx/W7VhZJfi2Dxk2/u8Tvyr3NB3U+FqWCXxsataappYRdEJeXE/P/i98FmhyWrE+xaZ0pgIcxhoy5vgVfZ52vOtFnzZKUVOLUzFeA8Ly4HgyD3MNOBzlFKTdEjwitXDFq9rmj24XSy7vI+9LxKs9RREpWKKXRttJBkTWY+5zzMzJ/qwQUFl2aXgc0nTJfUp8frFbupNg+5+FyfDLJAr5YLMBCG5L+WooveuBRz3ONkBgjYH+v1YBcQosJjJzuOM387mfFQjwK2ZlWf2Dv2MOohtgL+yNXDfz+fp6WUyQcCabCTI9ZWbyaHEUmYIV/OfQDKeTz/00Z8y48+CO5cdjB8Qwl2laZvu/8pPoZg/MKh+LDkX2CP6cgZI1T4dIlqfMLPepuevaSPNSNwVB6n7k5VtpfkQqShAODU/waY+kgdZZOVb2og1Z51hqZ0IHcnbl/ztfAqeva9F3zdAlebY/4SKIgjx+hahjtCIRisDDWrgE4j9IAsxPmVsoFXvpgLUya05yvr+C1b0Yr/zHulLu88BZGtzW8OKwbWK7ahrJBiiW8dh1StfYHb8f3XAJV+7WRkX+HqYFfUkzNEHQk6p3sGBdMjXI8C9t3x71WJ8x1sP72A+cpo0eXMk4o7fVUIdzvI7rNnAGApDjPzulU6kwSiVBzeDT/RiooQyuJZ6t47oEYu3bJC0Cws+y64HvNcvsaAOUtdWjvJCdXh19ivR6SACWSA1e3HHuRiGqucPsqWI9XN
\ No newline at end of file
;/*授权文件路径*/
[TR_CFG_LIC]
LIC_NAME=/usr/lib/data/license.dat
;/*字库路径配置*/
[TR_CFG_MDL]
MDL_NAME=/usr/lib/data/trData.mdl
package com.idcard;
public interface CBInterface {
public void output(int id, String out);
}
package com.idcard;
import com.thr.config.NativeConfig;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
public class Demo {
/* static {
try {
loadLib("OCRDLL_THR_X64");
} catch (Exception e) {
System.out.println("库加载失败");
}
}*/
public static int isBootOK = 0;
/**
* 获取版权信息
*/
public native static byte[] GetCopyrightInfo();
/**
* 获取版本信息
*/
public native static byte[] GetVersion();
/**
* 获取版本试用时间
*/
public native static byte[] GetUseTimeString();
/**
* 获取引擎内置TIMEKEY
*/
public native static byte[] GetEngineTimeKey();
/**
* 引擎初始化 返回值1:正常 -1:未绑定设备 100:时间过期 0:初始化引擎失败
*/
public native static int RECOCRBoot(String TimeKey);
/**
* 设置引擎参数
*/
public native static int SetParam(int param, int val);
/**
* 设置引擎带String参数
*/
public native static int SetParamString(int param, String val);
/**
* 识别入口 路径形式识别
*/
public native static byte[] RECOCROFPATH(int typeid, String path);
/**
* 识别入口 流形式识别
*/
public native static byte[] RECOCROFMEM(int typeid, byte[] pImagebuf, int len);
/**
* 识别入口 base64流形式识别
*/
public native static byte[] RECOCROFBASE64(int typeid, byte[] pImagebuf, int len);
/**
* 释放引擎内存
*/
public native static int TerminateOCRHandle();
public String Byte2String(byte[] info) {
String str = null;
if (info != null) {
try {
str = new String(info, "GBK");
} catch (UnsupportedEncodingException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
return str;
}
public static int Start(String TimeKey) {
if (isBootOK == 0) {
isBootOK = RECOCRBoot(TimeKey);
}
return isBootOK;
}
public static void loadLib(String libName) {
String resourcePath = "/" + libName;
String folderName = System.getProperty("java.io.tmpdir") + "/lib/";
File folder = new File(folderName);
folder.mkdirs();
File libFile = new File(folder, libName);
if (libFile.exists()) {
System.load(libFile.getAbsolutePath());
} else {
try {
InputStream in = NativeConfig.class.getResourceAsStream(resourcePath);
FileUtils.copyInputStreamToFile(in,libFile);
in.close();
System.load(libFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed to load required lib", e);
}
}
}
public static void main(String[] args) {
Demo ocr = new Demo();
String timeKey = "c:/ocr_engine/option.cfg";//cfg配置文件路径
ocr.Start(timeKey);
}
}
package com.idcard;
public class GlobalData {
public static int NAME = 0;
public static int SEX = 1;
public static int FOLK = 2;
public static int BIRTHDAY = 3;
public static int ADDRESS = 4;
public static int NUM = 5;
public static int issue = 6;
public static int period = 7;
public static int isfirst = 0;
public static int x =0;
public static int y =0;
public static int m =0;
public static int n =0;
public static int T_ONLY_CARD_NUM = 0x0001;//设置只识别卡号
public static int T_SET_HEADIMG = 0x0002;//设置是否要截取人头像信息
public static int T_SET_AUTO_FILL = 0x0003;//自动填充功能
public static int T_SET_LOGPATH = 0x0004;// 设置保存g保存文件位置
public static int T_SET_OPENORCLOSE_LOGPATH = 0x0005;// 打开关闭保存log文件功能
public static int T_SET_HEADIMGBUFMODE = 0x0006;// 设置人头像模式 0= 原始形式(便于android ios直接加载) 1=BASE64加密形式(便于sdk网络传输)
public static int T_SET_NDCORRECTION = 0x0007; /* 设置是否进行畸形矫正功能*/
public static int T_SET_PER_CALL_ACCOUNT = 0x0017; /* 设置授权用户名*/
public static int T_SET_PER_CALL_PASSWORD = 0x0018; /* 设置授权密码*/
public static int T_SET_PER_CALL_SERVERURL = 0x0019; /* 设置服务接口*/
public static int T_SET_PER_CALL_TIMEOUT = 0x0020; /* 设置超时时长*/
public static int T_SET_CARDREGIONIMG = 0x0022; /*设置JSON流身份证区域截图是否导出 0 = 不做导出, 1 = 导出 图片流的模式与头像一致*/
public static int T_SET_EVALUE_QUALITY = 0x0023;/* 图像质量估计值*/
public static int TUNCERTAIN = 0x00; /*未知*/
public static int TIDCARD2 = 0x11; /*二代证*/
public static int TIDCARDBACK = 0x14; /* 二代证背面(内部自动判断请使用TIDCARD2)*/
public static int TIDBANK = 0x15; /* 银行卡*/
public static int TIDLPR = 0x16; /* 车牌*/
public static int TIDJSZCARD = 0x17; /*驾照*/
public static int TIDXSZCARD = 0x18; /* 行驶证*/
public static int TIDTICKET = 0x19; /* 火车票*/
public static int TIDJSZBACK = 0x1a; /* 驾驶证副页(内部自动判断请使用TIDJSZCARD)*/
public static int TIDXSZBACK = 0x1b; /* 行驶证副页(内部自动判断请使用TIDXSZCARD)*/
public static int TIDSSCCARD = 0x20; /* 社保卡*/
public static int TIDPASSPORT = 0x21; /* 护照*/
public static int TIDDRILL = 0x22; /* 钻孔柱状图*/
public static int TIDBIZLIC = 0x23; /* 营业执照*/
public static int TIDINVOICE = 0x24; /* 增值税发票*/
public static int TIDDOCUMENT = 0x25; /* 通用文档*/
public static int TIDRMB = 0x26; /* 人民币*/
public static int TIDVINCODE = 0x27; /* 汽车VIN码*/
public static int TIDEEPHK = 0x28; /* 港澳通行证*/
public static int TIDMARRY = 0x29; /* 结婚证*/
public static int TIDRESIDENCE = 0x2a; /* 户口本*/
public static int TIDSTAMP = 0x2b; /* 验讫章*/
public static int TIDOPENACC = 0x2c; /* 开户许可证*/
public static int TIDINDIACARD = 0x2d; /* 印度身份证*/
public static int TIDSCRIDENCE = 0x2e; /* 退票费凭证*/
public static int TIDVP = 0x2f; /* 船舶许可证*/
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
import java.util.Base64;
class OCREngine extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
long s1 = System.currentTimeMillis();
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"
+ "姓名:" + tocr.getData().get(i).getIDC_NAME() + "\r\n"
+ "性别:" + tocr.getData().get(i).getIDC_SEX() + "\r\n"
+ "民族:" + tocr.getData().get(i).getIDC_FOLK() + "\r\n"
+ "出生:" + tocr.getData().get(i).getIDC_BIRTHDAY() + "\r\n"
+ "地址:" + tocr.getData().get(i).getIDC_ADDRESS() + "\r\n"
+ "号码:" + tocr.getData().get(i).getIDC_NUM() + "\r\n"
+ "签发机关:" + tocr.getData().get(i).getIDC_ISSUE() + "\r\n"
+ "有效期限:" + tocr.getData().get(i).getIDC_PERIOD() + "\r\n"
+ "图片质量估计值:" + tocr.getData().get(i).getIMG_QUALITY() + "\r\n");
FileOutputStream fw = null;
try {
fw = new FileOutputStream(new File("H:\\民政照片\\head\\"+tocr.getData().get(i).getIDC_NUM()+".jpg"));
fw.write(Base64.getDecoder().decode(tocr.getData().get(i).getHeadimg()));
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// StringManager.SaveJPGFile("c:/123/001.jpg", tocr.getData().get(i).getHeadimg().getBytes());// 人头像保存
}
} else {
System.out.print("buf == null\n");
}
System.out.println("用时:"+(System.currentTimeMillis()-s1));
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine10 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine10(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"统一社会信用代码:" + tocr.getData().get(i).getBLIC_CODE() + "\r\n"
+ "名称:" + tocr.getData().get(i).getBLIC_NAME() + "\r\n"
+ "类型:" + tocr.getData().get(i).getBLIC_TYPE() + "\r\n"
+ "住所:" + tocr.getData().get(i).getBLIC_ADDR() + "\r\n"
+ "法定代表人:" + tocr.getData().get(i).getBLIC_PERSON() + "\r\n"
+ "注册资本:" + tocr.getData().get(i).getBLIC_CAPTIAL() + "\r\n"
+ "成立日期:" + tocr.getData().get(i).getBLIC_DATE() + "\r\n"
+ "营业期限:" + tocr.getData().get(i).getBLIC_PERIOD() + "\r\n"
+ "发证日期:" + tocr.getData().get(i).getBLIC_ISSUE() + "\r\n"
+ "经营范围:" + tocr.getData().get(i).getBLIC_SCOPE() + "\r\n");
// StringManager.SaveJPGFile("c:/123/001.jpg", tocr.getData().get(i).getHeadimg().getBytes());// 人头像保存
}
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine11 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine11(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"发票代号:" + tocr.getData().get(i).getINV_CODE() + "\r\n"
+ "发票号码:" + tocr.getData().get(i).getINV_NUM() + "\r\n"
+ "开票日期:" + tocr.getData().get(i).getINV_DATE() + "\r\n"
+ "密码区:" + tocr.getData().get(i).getINV_PASSWORD() + "\r\n"
+ "购方企业名称:" + tocr.getData().get(i).getINV_BUY() + "\r\n"
+ "购方纳税号:" + tocr.getData().get(i).getINV_BUYCODE() + "\r\n"
+ "销方企业名称:" + tocr.getData().get(i).getINV_SALE() + "\r\n"
+ "销方纳税号:" + tocr.getData().get(i).getINV_SALECODE() + "\r\n"
+ "货物或应税劳务名称:" + tocr.getData().get(i).getINV_PRODUCT() + "\r\n"
+ "价税合计:" + tocr.getData().get(i).getINV_PRICE_TAX() + "\r\n"
+ "合计金额:" + tocr.getData().get(i).getINV_PRICE() + "\r\n"
+ "合计税额:" + tocr.getData().get(i).getINV_TAX() + "\r\n"
+ "备注:" + tocr.getData().get(i).getINV_MARK() + "\r\n"
+ "税率:" + tocr.getData().get(i).getINV_TAXRATE() + "\r\n");
}
// StringManager.SaveJPGFile("c:/345.jpg", stringManager.headimg.getBytes());// 人头像保存
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine12 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine12(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"持证人:" + tocr.getData().get(i).getMAR_OWNER() + "\r\n"
+ "登记日期:" + tocr.getData().get(i).getMAR_PERIOD() + "\r\n"
+ "结婚证字号:" + tocr.getData().get(i).getMAR_NUM() + "\r\n"
+ "男方姓名:" + tocr.getData().get(i).getMAR_MAN() + "\r\n"
+ "男方生日:" + tocr.getData().get(i).getMAR_MAN_BIRTH() + "\r\n"
+ "男方证件号:" + tocr.getData().get(i).getMAR_MAN_NUM() + "\r\n"
+ "女方姓名:" + tocr.getData().get(i).getMAR_WIFE() + "\r\n"
+ "女方生日:" + tocr.getData().get(i).getMAR_WIFE_BIRTH() + "\r\n"
+ "女方证件号:" + tocr.getData().get(i).getMAR_WIFE_NUM() + "\r\n");
}
// StringManager.SaveJPGFile("c:/345.jpg", stringManager.headimg.getBytes());// 人头像保存
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine2 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine2(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"银行卡号:" + tocr.getData().get(i).getTBANK_NUM() + "\r\n"
+ "行卡开户行:" + tocr.getData().get(i).getTBANK_NAME() + "\r\n"
+ "银行机构代码:" + tocr.getData().get(i).getTBANK_ORGCODE() + "\r\n"
+ "卡种:" + tocr.getData().get(i).getTBANK_CLASS() + "\r\n"
+ "卡名:" + tocr.getData().get(i).getTBANK_CARD_NAME() + "\r\n"
+ "图片质量估计值:" + tocr.getData().get(i).getIMG_QUALITY() + "\r\n");
}
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine3 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine3(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"号码:" + tocr.getData().get(i).getDL_NUM() + "\r\n"
+ "姓名:" + tocr.getData().get(i).getDL_NAME() + "\r\n"
+ "性别:" + tocr.getData().get(i).getDL_SEX() + "\r\n"
+ "国籍:" + tocr.getData().get(i).getDL_COUNTRY() + "\r\n"
+ "地址:" + tocr.getData().get(i).getDL_ADDRESS() + "\r\n"
+ "出生日期:" + tocr.getData().get(i).getDL_BIRTHDAY() + "\r\n"
+ "准驾车型:" + tocr.getData().get(i).getDL_CLASS() + "\r\n"
+ "有效期限:" + tocr.getData().get(i).getDL_VALIDFOR() + "\r\n"
+ "初次领证日期:" + tocr.getData().get(i).getDL_ISSUE_DATE() + "\r\n"
+ "有效起始日期:" + tocr.getData().get(i).getDL_VALIDFROM() + "\r\n"
+ "证号:" + tocr.getData().get(i).getDL_B_IDNUM() + "\r\n"
+ "姓名:" + tocr.getData().get(i).getDL_B_NAME() + "\r\n"
+ "档案编号:" + tocr.getData().get(i).getDL_B_SERIAL() + "\r\n"
+ "记录:" + tocr.getData().get(i).getDL_B_RECODE() + "\r\n"
+ "条形码:" + tocr.getData().get(i).getDL_B_BARNUM() + "\r\n"
+ "图片质量估计值:" + tocr.getData().get(i).getIMG_QUALITY() + "\r\n");}
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine4 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine4(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"号牌号码:" + tocr.getData().get(i).getDP_PLATENO() + "\r\n"
+ "车牌类型:" + tocr.getData().get(i).getDP_TYPE() + "\r\n"
+ "所有人:" + tocr.getData().get(i).getDP_OWNER() + "\r\n"
+ "地址:" + tocr.getData().get(i).getDP_ADDRESS() + "\r\n"
+ "使用性质:" + tocr.getData().get(i).getDP_USECHARACTER() + "\r\n"
+ "品牌号码:" + tocr.getData().get(i).getDP_MODEL() + "\r\n"
+ "车辆识别代号:" + tocr.getData().get(i).getDP_VIN() + "\r\n"
+ "发动机号码:" + tocr.getData().get(i).getDP_ENGINENO() + "\r\n"
+ "注册日期:" + tocr.getData().get(i).getDP_REGISTER_DATE() + "\r\n"
+ "发证日期:" + tocr.getData().get(i).getDP_ISSUE_DATE() + "\r\n"
+ "车牌号码:" + tocr.getData().get(i).getDP_B_PLATENUM() + "\r\n"
+ "证号:" + tocr.getData().get(i).getDP_B_SERIAL() + "\r\n"
+ "核定载人数:" + tocr.getData().get(i).getDP_B_PASSENGER() + "\r\n"
+ "总质量:" + tocr.getData().get(i).getDP_B_GROSSMASS() + "\r\n"
+ "整备质量:" + tocr.getData().get(i).getDP_B_CURBWEIGHT() + "\r\n"
+ "核定载质量:" + tocr.getData().get(i).getDP_B_LOAD() + "\r\n"
+ "外廓尺寸:" + tocr.getData().get(i).getDP_B_GABARITE() + "\r\n"
+ "准牵引总质量:" + tocr.getData().get(i).getDP_B_TRACTIONMASS() + "\r\n"
+ "备注:" + tocr.getData().get(i).getDP_B_REMARK() + "\r\n"
+ "检验记录:" + tocr.getData().get(i).getDP_B_RECODE() + "\r\n"
+ "条形码:" + tocr.getData().get(i).getDP_B_BARNUM() + "\r\n"
+ "图片质量估计值:" + tocr.getData().get(i).getIMG_QUALITY() + "\r\n");
}
// StringManager.SaveJPGFile("c:/345.jpg", stringManager.headimg.getBytes());// 人头像保存
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine5 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine5(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"许可编号:" + tocr.getData().get(i).getVP_LICNUM() + "\r\n"
+ "许可类型:" + tocr.getData().get(i).getVP_TYPE() + "\r\n"
+ "姓名:" + tocr.getData().get(i).getVP_NAME() + "\r\n"
+ "性别:" + tocr.getData().get(i).getVP_SEX() + "\r\n"
+ "证件号码:" + tocr.getData().get(i).getVP_IDNUM() + "\r\n"
+ "单位名称:" + tocr.getData().get(i).getVP_COMPANY() + "\r\n"
+ "登轮事宜:" + tocr.getData().get(i).getVP_REASON() + "\r\n"
+ "登轮范围:" + tocr.getData().get(i).getVP_SCOPE() + "\r\n"
+ "起始日期:" + tocr.getData().get(i).getVP_PERIOD() + "\r\n"
+ "截止日期:" + tocr.getData().get(i).getVP_DUEDATE() + "\r\n"
+ "签发时间:" + tocr.getData().get(i).getVP_ISSUE() + "\r\n");
// StringManager.SaveJPGFile("c:/123/001.jpg", tocr.getData().get(i).getHeadimg().getBytes());// 人头像保存
}
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine6 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine6(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult + "\r\n");
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
// System.out.println("名称:" + tocr.getData());
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine7 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine7(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"起始站:" + tocr.getData().get(i).getTIC_START() + "\r\n"
+ "车次:" + tocr.getData().get(i).getTIC_NUM() + "\r\n"
+ "终点站:" + tocr.getData().get(i).getTIC_END() + "\r\n"
+ "发车时间:" + tocr.getData().get(i).getTIC_TIME() + "\r\n"
+ "座位号:" + tocr.getData().get(i).getTIC_SEAT() + "\r\n"
+ "姓名:" + tocr.getData().get(i).getTIC_NAME() + "\r\n"
+ "价格:" + tocr.getData().get(i).getTIC_PRICE() + "\r\n"
+ "座位类型:" + tocr.getData().get(i).getTIC_SEATCLASS() + "\r\n"
+ "身份证号码:" + tocr.getData().get(i).getTIC_CARDNUM() + "\r\n");}
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine8 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine8(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"护照号:" + tocr.getData().get(i).getPAS_PASNO() + "\r\n"
+ "姓名:" + tocr.getData().get(i).getPAS_NAME() + "\r\n"
+ "性别:" + tocr.getData().get(i).getPAS_SEX() + "\r\n"
+ "身份证号码:" + tocr.getData().get(i).getPAS_IDCARDNUM() + "\r\n"
+ "生日:" + tocr.getData().get(i).getPAS_BIRTH() + "\r\n"
+ "出生地址:" + tocr.getData().get(i).getPAS_PLACE_BIRTH() + "\r\n"
+ "签发日期:" + tocr.getData().get(i).getPAS_DATE_ISSUE() + "\r\n"
+ "有效日期:" + tocr.getData().get(i).getPAS_DATE_EXPIRY() + "\r\n"
+ "签发地址:" + tocr.getData().get(i).getPAS_PLACE_ISSUE() + "\r\n"
+ "国籍和姓名监督码:" + tocr.getData().get(i).getPAS_NATION_NAME() + "\r\n"
+ "护照机读码:" + tocr.getData().get(i).getPAS_MACHINE_RCODE() + "\r\n");}
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
class OCREngine9 extends Thread {
public String pathString;
public Demo engineDemo;
public int id;
public int i = 0;
public int num1 = 0;
private CBInterface callBack = null;
private int tEngineType = GlobalData.TUNCERTAIN;
public OCREngine9(int tEngineType, Demo demo, String paString) {
// TODO Auto-generated constructor stub
this.pathString = paString;
this.engineDemo = demo;
this.tEngineType = tEngineType;
}
public void SetCallBack(CBInterface cbInterface) {
this.callBack = cbInterface;
}
public static byte[] GetImgByte(String path) throws IOException {
byte[] bytes = null;
File file = null;
file = new File(path);
if (file.exists()) {
InputStream is = new FileInputStream(file);
int length = (int) file.length();
if (length > Integer.MAX_VALUE) {
return null;
}
bytes = new byte[length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
return null;
}
is.close();
return bytes;
}
return null;
}
public void run() {
// for (i = 0; i < 10; i++)
{
byte[] pImgBuff = null;
try {
pImgBuff = GetImgByte(pathString);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (pImgBuff == null) {
return;
}
//byte [] buf = engineDemo.RECOCROFPATH(pathString);
byte[] jsonbuf = engineDemo.RECOCROFMEM(this.tEngineType, pImgBuff, pImgBuff.length);
if (jsonbuf != null) {
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.print(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
for (int i = 0; i < tocr.getData().size(); i++) {
System.out.println("\r\n"+"姓名:" + tocr.getData().get(i).getSSC_NAME() + "\r\n"
+ "身份证号:" + tocr.getData().get(i).getSSC_NUM() + "\r\n"
+ "卡号:" + tocr.getData().get(i).getSSC_SHORTNUM() + "\r\n"
+ "有效期限:" + tocr.getData().get(i).getSSC_PERIOD() + "\r\n"
+ "银行卡号:" + tocr.getData().get(i).getSSC_BANKNUM() + "\r\n");
// StringManager.SaveJPGFile("c:/123/001.jpg", tocr.getData().get(i).getHeadimg().getBytes());// 人头像保存
}
} else {
System.out.print("buf == null\n");
}
}
// System.out.println("线程"+ id + "结束\n");
}
}
package com.idcard;
class OCRInter{
public Demo engineDemo = new Demo();
public void TestTHR() {
String timeKey = "c:/ocr_engine/option.cfg";//cfg配置文件路径
String pathString = "H:\\民政照片\\1208\\";//配置样本路径
/**说明:外部可自行设置文件路径值, 也可使用引擎默认的文件路径值*/
int ret = engineDemo.Start(timeKey);
// int ret = engineDemo.Start(engineDemo.Byte2String(engineDemo.GetEngineTimeKey()));
if (ret == 100) {
System.out.println("该版本为试用版本,时间过期,请联系商务替换最新(license.dat)授权文件\n");
return;
}
else if (ret != 1) {
System.out.println("引擎初始化失败,确认C盘路径下有以下文件\n1、ocr_engine路径下有option配置文件\n2、ocr_engine/data路径下有(授权文件、字库)\n3、http://doc.xmheshu.com/013-windowsjavasdk.html");
return;
}
/* System.out.println(engineDemo.Byte2String(engineDemo.GetCopyrightInfo()) + "\n"
+ engineDemo.Byte2String(engineDemo.GetVersion()) +"\n"
+ engineDemo.Byte2String(engineDemo.GetUseTimeString()));*/
engineDemo.SetParam(GlobalData.T_SET_HEADIMG, 1);//设置是否要截取人头像信息
engineDemo.SetParam(GlobalData.T_SET_HEADIMGBUFMODE, 1);//打开身份证保存区域图片的开关
// engineDemo.SetParam(GlobalData.T_SET_CARDREGIONIMG, 1);/*设置JSON流身份证区域截图是否导出 0 = 不做导出, 1 = 导出 图片流的模式与头像一致*/
// engineDemo.SetParam(GlobalData.T_SET_AUTO_FILL, 1);//自动填充功能
engineDemo.SetParam(GlobalData.T_SET_EVALUE_QUALITY, 1);//图像质量判断
OCREngine engine1 = new OCREngine(GlobalData.TIDCARD2,engineDemo, pathString + "1200255749092151307.jpg");//身份证引擎1
engine1.start();//身份证
}
public static void main(String[] args) {
OCRInter inter = new OCRInter();
inter.TestTHR();
}
}
package com.idcard;
public class QualityParse {
private Double QC_FITSIZE;
private Double QC_ISRGB;
private Double QC_INFOCUS;
private Double QC_RIGHTRESULT;
public Double getQC_FITSIZE() {
return QC_FITSIZE;
}
public void setQC_FITSIZE(Double QC_FITSIZE) {
this.QC_FITSIZE = QC_FITSIZE;
}
public Double getQC_ISRGB() {
return QC_ISRGB;
}
public void setQC_ISRGB(Double QC_ISRGB) {
this.QC_ISRGB = QC_ISRGB;
}
public Double getQC_INFOCUS() {
return QC_INFOCUS;
}
public void setQC_INFOCUS(Double QC_INFOCUS) {
this.QC_INFOCUS = QC_INFOCUS;
}
public Double getQC_RIGHTRESULT() {
return QC_RIGHTRESULT;
}
public void setQC_RIGHTRESULT(Double QC_RIGHTRESULT) {
this.QC_RIGHTRESULT = QC_RIGHTRESULT;
}
}
This diff is collapsed.
package com.idcard;
import java.util.List;
public class TOCR {
private int typeID;
private List<StringManager> data;
public int getTypeID() {
return typeID;
}
public void setTypeID(int typeID) {
this.typeID = typeID;
}
public List<StringManager> getData() {
return data;
}
public void setData(List<StringManager> data) {
this.data = data;
}
}
package com.thr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ThrOcrApplication {
public static void main(String[] args) {
SpringApplication.run(ThrOcrApplication.class, args);
}
}
package com.thr.common;
public class CommonResult<T> {
private long code;
private String message;
private T data;
protected CommonResult() {
}
protected CommonResult(long code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public static <T> CommonResult<T> success(T data) {
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
}
public static <T> CommonResult<T> success(T data, String message) {
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
}
public static <T> CommonResult<T> failed(IErrorCode errorCode) {
return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
}
public static <T> CommonResult<T> failed(String message) {
return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
}
public static <T> CommonResult<T> failed() {
return failed(ResultCode.FAILED);
}
public static <T> CommonResult<T> validateFailed() {
return failed(ResultCode.VALIDATE_FAILED);
}
public static <T> CommonResult<T> validateFailed(String message) {
return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
}
public static <T> CommonResult<T> unauthorized(T data) {
return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
}
public static <T> CommonResult<T> forbidden(T data) {
return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
}
public long getCode() {
return code;
}
public void setCode(long code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.thr.common;
/**
* 封装API的错误码
* Created by martin on 2019/7/16.
*/
public interface IErrorCode {
long getCode();
String getMessage();
}
package com.thr.common;
/**
* 枚举了一些常用API操作码
* Created by martin on 2019/7/16.
*/
public enum ResultCode implements IErrorCode {
SUCCESS(200, "操作成功"),
FAILED(500, "操作失败"),
VALIDATE_FAILED(404, "参数检验失败,请检查信息输入是否完整或格式是否正确!"),
UNAUTHORIZED(401, "暂未登录或token已经过期"),
FORBIDDEN(403, "没有相关权限"),
CONTINUE(210,"继续执行");
private long code;
private String message;
ResultCode(long code, String message) {
this.code = code;
this.message = message;
}
@Override
public long getCode() {
return code;
}
@Override
public String getMessage() {
return message;
}
}
package com.thr.compont;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.thr.common.CommonResult;
import com.thr.dto.WebLog;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sun.net.util.IPAddressUtil;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 统一日志处理切面
*/
@Aspect
@Component
@Order(1)
public class WebLogAspect {
private static final Logger logger = LoggerFactory.getLogger(WebLogAspect.class);
@Pointcut("execution(public * com.thr.controller.*.*(..))")
public void webLog() {
}
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
}
@AfterReturning(value = "webLog()", returning = "ret")
public void doAfterReturning(Object ret) throws Throwable {
}
@Around("webLog()")
public Object doAround(ProceedingJoinPoint joinPoint) {
try {
long startTime = System.currentTimeMillis();
//获取当前请求对象
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
Object result = joinPoint.proceed();
//记录请求信息(通过Logstash传入Elasticsearch)
WebLog webLog = new WebLog();
long endTime = System.currentTimeMillis();
webLog.setParameter(getParameter(method, joinPoint.getArgs()));
webLog.setSpendTime((int) (endTime - startTime) / 1000);
webLog.setUrl(request.getRequestURL().toString());
logger.info("请求解析-" + JSONUtil.parse(webLog) + "返回-" + JSONUtil.parse(result));
return result;
} catch (Throwable t) {
logger.error(t.getMessage(), t);
return CommonResult.failed(t.getMessage());
}
}
/**
* 根据方法和传入的参数获取请求参数
*/
private Object getParameter(Method method, Object[] args) {
List<Object> argList = new ArrayList<>();
Parameter[] parameters = method.getParameters();
for (int i = 0; i < parameters.length; i++) {
//将RequestBody注解修饰的参数作为请求参数
RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class);
if (requestBody != null) {
argList.add(args[i]);
}
//将RequestParam注解修饰的参数作为请求参数
RequestParam requestParam = parameters[i].getAnnotation(RequestParam.class);
if (requestParam != null) {
Map<String, Object> map = new HashMap<>();
String key = parameters[i].getName();
if (!StringUtils.isEmpty(requestParam.value())) {
key = requestParam.value();
}
map.put(key, args[i]);
argList.add(map);
}
}
if (argList.size() == 0) {
return null;
} else if (argList.size() == 1) {
return argList.get(0);
} else {
return argList;
}
}
}
package com.thr.config;
import com.idcard.Demo;
import com.idcard.GlobalData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.context.annotation.Configuration;
import java.io.*;
@Configuration
@Slf4j
public class NativeConfig {
public static String key = null;
static {
try {
//**//
//loadLib("OCRDLL_THR_X64");
//设置验证码
//loadConfig("option.cfg");
//**//
//**//
System.loadLibrary("libOCRDLL_THR");
//设置验证码
Demo.RECOCRBoot("/usr/lib/linux_option.cfg");
//**//
//配置
Demo.SetParam(GlobalData.T_SET_HEADIMG, 1);//设置是否要截取人头像信息
Demo.SetParam(GlobalData.T_SET_HEADIMGBUFMODE, 1);//打开身份证保存区域图片的开关
Demo.SetParam(GlobalData.T_SET_EVALUE_QUALITY, 1);//图像质量判断
} catch (Exception e) {
System.out.println("库加载失败");
}
}
public static void loadLib(String libName) {
String resourcePath = "/" + libName;
String folderName = System.getProperty("java.io.tmpdir") + "/lib/";
File folder = new File(folderName);
folder.mkdirs();
File libFile = new File(folder, libName);
if (libFile.exists()) {
System.load(libFile.getAbsolutePath());
} else {
try {
InputStream in = NativeConfig.class.getResourceAsStream(resourcePath);
FileUtils.copyInputStreamToFile(in,libFile);
in.close();
System.load(libFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed to load required lib", e);
}
}
}
public static void loadConfig(String configName) {
String resourcePath = "/" + configName;
String folderName = System.getProperty("java.io.tmpdir") + "/lib/";
File folder = new File(folderName);
folder.mkdirs();
File libFile = new File(folder, configName);
if (libFile.exists()) {
Demo.RECOCRBoot(libFile.getAbsolutePath());
} else {
try {
InputStream in = NativeConfig.class.getResourceAsStream(resourcePath);
FileUtils.copyInputStreamToFile(in,libFile);
in.close();
Demo.RECOCRBoot(libFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed to load required lib", e);
}
}
}
}
package com.thr.controller;
import com.thr.common.CommonResult;
import com.thr.dto.Param;
import com.thr.service.OcrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("ocr")
public class IcardController {
@Autowired
private OcrService ocrService;
@PostMapping(value = "idcard")
private CommonResult idcard(@RequestBody Param param) {
return ocrService.idcard(param);
}
}
package com.thr.dto;
import lombok.Data;
@Data
public class IdcardDto {
private Integer quality;
private String name;
private String sex;
private String nation;
private String birth;
private String idcard;
private String address;
private String headimg;
}
package com.thr.dto;
import lombok.Data;
@Data
public class Param {
private String imgstr;
private String imgurl;
private boolean head;
}
package com.thr.dto;
import lombok.Data;
/**
* Controller层的日志封装类
*/
@Data
public class WebLog {
/**
* 操作描述
*/
private String description;
/**
* 操作用户
*/
private String username;
/**
* 操作时间
*/
private Long startTime;
/**
* 消耗时间
*/
private Integer spendTime;
/**
* 根路径
*/
private String basePath;
/**
* URI
*/
private String uri;
/**
* URL
*/
private String url;
/**
* 请求类型
*/
private String method;
/**
* IP地址
*/
private String ip;
private Object parameter;
private Object result;
}
package com.thr.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.idcard.Demo;
import com.idcard.GlobalData;
import com.idcard.StringManager;
import com.idcard.TOCR;
import com.thr.common.CommonResult;
import com.thr.dto.IdcardDto;
import com.thr.dto.Param;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
@Service
@Slf4j
public class OcrService {
public CommonResult idcard(Param param){
String imgStr = param.getImgstr();
String imgUrl = param.getImgurl();
if(StrUtil.isEmpty(imgStr) && StrUtil.isEmpty(imgUrl)){
return CommonResult.validateFailed();
}
String img = null;
if(!StrUtil.isEmpty(imgStr)){
img = imgStr;
}else {
try {
byte[] bytes = HttpUtil.createGet(imgUrl).execute().bodyBytes();
img = Base64.getEncoder().encodeToString(bytes);
}catch (Exception e){
img = null;
}
}
if(img == null){
return CommonResult.validateFailed();
}
byte[] imgBytes = Base64.getDecoder().decode(img);
if(imgBytes == null || imgBytes.length == 0){
return CommonResult.validateFailed();
}
byte[] jsonbuf = Demo.RECOCROFMEM(GlobalData.TIDCARD2, imgBytes, imgBytes.length);
if (jsonbuf == null){
return CommonResult.failed("识别失败");
}
String strResult = null;
try {
strResult = new String(jsonbuf, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
log.info(strResult);
strResult = strResult.replace("\u0000", "");
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.serializeNulls();
Gson gson = gsonbuilder.create();
TOCR tocr = gson.fromJson(strResult, TOCR.class);
StringManager data = tocr.getData().get(0);
IdcardDto dto = new IdcardDto();
dto.setName(data.getIDC_NAME());
dto.setIdcard(data.getIDC_NUM());
dto.setSex(data.getIDC_SEX());
dto.setBirth(data.getIDC_BIRTHDAY());
dto.setNation(data.getIDC_FOLK());
dto.setQuality(data.getIMG_QUALITY());
dto.setAddress(data.getIDC_ADDRESS());
if(param.isHead()){
dto.setHeadimg(data.getHeadimg());
}
return CommonResult.success(dto);
}
}
server:
port: 1024
servlet:
context-path:
spring:
devtools:
restart:
enabled: true
add-properties: false
logging:
level:
com.thr: debug
rbGafRvb0wJQVpDotHrx/W7VhZJfi2Dxk2/u8Tvyr3NB3U+FqWCXxsataappYRdEJeXE/P/i98FmhyWrE+xaZ0pgIcxhoy5vgVfZ52vOtFnzZKUVOLUzFeA8Ly4HgyD3MNOBzlFKTdEjwitXDFq9rmj24XSy7vI+9LxKs9RREpWKKXRttJBkTWY+5zzMzJ/qwQUFl2aXgc0nTJfUp8frFbupNg+5+FyfDLJAr5YLMBCG5L+WooveuBRz3ONkBgjYH+v1YBcQosJjJzuOM387mfFQjwK2ZlWf2Dv2MOohtgL+yNXDfz+fp6WUyQcCabCTI9ZWbyaHEUmYIV/OfQDKeTz/00Z8y48+CO5cdjB8Qwl2laZvu/8pPoZg/MKh+LDkX2CP6cgZI1T4dIlqfMLPepuevaSPNSNwVB6n7k5VtpfkQqShAODU/waY+kgdZZOVb2og1Z51hqZ0IHcnbl/ztfAqeva9F3zdAlebY/4SKIgjx+hahjtCIRisDDWrgE4j9IAsxPmVsoFXvpgLUya05yvr+C1b0Yr/zHulLu88BZGtzW8OKwbWK7ahrJBiiW8dh1StfYHb8f3XAJV+7WRkX+HqYFfUkzNEHQk6p3sGBdMjXI8C9t3x71WJ8x1sP72A+cpo0eXMk4o7fVUIdzvI7rNnAGApDjPzulU6kwSiVBzeDT/RiooQyuJZ6t47oEYu3bJC0Cws+y64HvNcvsaAOUtdWjvJCdXh19ivR6SACWSA1e3HHuRiGqucPsqWI9XN
\ No newline at end of file
;/*授权文件路径*/
[TR_CFG_LIC]
LIC_NAME=C:\ocr_engine\data\license.dat
;/*字库路径配置*/
[TR_CFG_MDL]
MDL_NAME=C:\ocr_engine\data\trData.mdl
package com.thr;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ThrOcrApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment