Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BYLAppRobot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuyang
BYLAppRobot
Commits
b31b21f7
Commit
b31b21f7
authored
Jan 02, 2019
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
APK图片抓取识别及轮播流地址抓取, 客户端增加电话号码识别
#BYLSERVER-1438
parent
41174c60
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
128 additions
and
8 deletions
+128
-8
build.gradle
app/build.gradle
+1
-1
aip-java-sdk-4.8.0.jar
app/libs/aip-java-sdk-4.8.0.jar
+0
-0
proguard-rules.pro
app/proguard-rules.pro
+3
-0
Task.kt
app/src/main/java/com/duolebo/blyrobot/data/Task.kt
+21
-0
BylRobotService.kt
...main/java/com/duolebo/blyrobot/service/BylRobotService.kt
+2
-0
OcrManager.kt
app/src/main/java/com/duolebo/blyrobot/tools/OcrManager.kt
+84
-0
AppUtil.kt
app/src/main/java/com/duolebo/blyrobot/util/AppUtil.kt
+17
-7
No files found.
app/build.gradle
View file @
b31b21f7
...
@@ -46,7 +46,7 @@ dependencies {
...
@@ -46,7 +46,7 @@ dependencies {
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation
(
name:
'appbase-release'
,
ext:
'aar'
)
implementation
(
name:
'appbase-release'
,
ext:
'aar'
)
implementation
'com.android.volley:volley:1.1.
0
'
implementation
'com.android.volley:volley:1.1.
1
'
implementation
'com.android.support:appcompat-v7:27.1.1'
implementation
'com.android.support:appcompat-v7:27.1.1'
implementation
'org.nanohttpd:nanohttpd:2.2.0'
implementation
'org.nanohttpd:nanohttpd:2.2.0'
implementation
(
name:
'vpnadaptercore-release'
,
ext:
'aar'
)
implementation
(
name:
'vpnadaptercore-release'
,
ext:
'aar'
)
...
...
app/libs/aip-java-sdk-4.8.0.jar
0 → 100644
View file @
b31b21f7
File added
app/proguard-rules.pro
View file @
b31b21f7
...
@@ -19,3 +19,6 @@
...
@@ -19,3 +19,6 @@
# If you keep the line number information, uncomment this to
# If you keep the line number information, uncomment this to
# hide the original source file name.
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
-
keep
class
com
.
baidu
.
ocr
.
sdk
.
**
{
*
;}
-
dontwarn
com
.
baidu
.
ocr
.
**
app/src/main/java/com/duolebo/blyrobot/data/Task.kt
View file @
b31b21f7
...
@@ -10,6 +10,7 @@ import com.duolebo.appbase.IAppBaseCallback
...
@@ -10,6 +10,7 @@ import com.duolebo.appbase.IAppBaseCallback
import
com.duolebo.appbase.IProtocol
import
com.duolebo.appbase.IProtocol
import
com.duolebo.blyrobot.protocol.ApkReportProtocol
import
com.duolebo.blyrobot.protocol.ApkReportProtocol
import
com.duolebo.blyrobot.tools.FtpManager
import
com.duolebo.blyrobot.tools.FtpManager
import
com.duolebo.blyrobot.tools.OcrManager
import
com.duolebo.blyrobot.util.AdbUtil
import
com.duolebo.blyrobot.util.AdbUtil
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.Config
import
com.duolebo.blyrobot.util.Config
...
@@ -20,6 +21,7 @@ import java.text.SimpleDateFormat
...
@@ -20,6 +21,7 @@ import java.text.SimpleDateFormat
import
java.util.*
import
java.util.*
import
kotlin.collections.ArrayList
import
kotlin.collections.ArrayList
/**
/**
* 任务类
* 任务类
*/
*/
...
@@ -137,6 +139,7 @@ class Task : Thread, IAppBaseCallback {
...
@@ -137,6 +139,7 @@ class Task : Thread, IAppBaseCallback {
// 退出应用
// 退出应用
AdbUtil
.
stopApp
(
this
.
apkInfo
.
packageName
)
AdbUtil
.
stopApp
(
this
.
apkInfo
.
packageName
)
imageOcrToNumber
();
// 上报数据,上传图片在后台进行
// 上报数据,上传图片在后台进行
report
()
report
()
}
}
...
@@ -427,6 +430,24 @@ class Task : Thread, IAppBaseCallback {
...
@@ -427,6 +430,24 @@ class Task : Thread, IAppBaseCallback {
this
.
uploadTask
=
uploadTask
this
.
uploadTask
=
uploadTask
}
}
private
fun
imageOcrToNumber
()
{
val
channelArr
=
this
.
reportJson
.
optJSONArray
(
"channels"
)
for
(
i
in
0
..
channelArr
.
length
())
{
try
{
val
channelJson
=
channelArr
.
optJSONObject
(
i
)
val
imagePath
=
this
.
taskPath
+
"/"
+
channelJson
.
optString
(
"channelImage"
)
val
newImagePath
=
AppUtil
.
cropImage
(
imagePath
)
val
phoneNumber
=
OcrManager
.
instance
.
imageOcr
(
newImagePath
)
channelJson
.
putOpt
(
"phoneNumber"
,
phoneNumber
)
}
catch
(
e
:
java
.
lang
.
Exception
)
{
e
.
printStackTrace
()
}
}
}
/**
/**
* 先上报数据,截图上传继续在后台进行
* 先上报数据,截图上传继续在后台进行
*/
*/
...
...
app/src/main/java/com/duolebo/blyrobot/service/BylRobotService.kt
View file @
b31b21f7
...
@@ -17,6 +17,7 @@ import com.duolebo.blyrobot.data.AppInfoData
...
@@ -17,6 +17,7 @@ import com.duolebo.blyrobot.data.AppInfoData
import
com.duolebo.blyrobot.data.Task
import
com.duolebo.blyrobot.data.Task
import
com.duolebo.blyrobot.protocol.GetAppInfoProtocol
import
com.duolebo.blyrobot.protocol.GetAppInfoProtocol
import
com.duolebo.blyrobot.tools.FtpManager
import
com.duolebo.blyrobot.tools.FtpManager
import
com.duolebo.blyrobot.tools.OcrManager
import
com.duolebo.blyrobot.tools.TaskManager
import
com.duolebo.blyrobot.tools.TaskManager
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.Config
import
com.duolebo.blyrobot.util.Config
...
@@ -46,6 +47,7 @@ class BylRobotService: Service(), IAppBaseCallback {
...
@@ -46,6 +47,7 @@ class BylRobotService: Service(), IAppBaseCallback {
override
fun
onCreate
()
{
override
fun
onCreate
()
{
super
.
onCreate
()
super
.
onCreate
()
OcrManager
.
instance
.
init
(
this
)
FtpManager
.
instance
.
start
()
FtpManager
.
instance
.
start
()
initBroadcast
()
initBroadcast
()
// requestAppList()
// requestAppList()
...
...
app/src/main/java/com/duolebo/blyrobot/tools/OcrManager.kt
0 → 100644
View file @
b31b21f7
package
com.duolebo.blyrobot.tools
import
android.annotation.SuppressLint
import
android.content.Context
import
android.text.TextUtils
import
com.baidu.aip.ocr.AipOcr
import
java.io.File
class
OcrManager
{
companion
object
{
@SuppressLint
(
"StaticFieldLeak"
)
val
instance
=
OcrManager
()
val
TAG
=
"RobotOcrManager"
const
val
AK
=
"zy4gq9vvYa0UF133COi2ITHI"
const
val
SK
=
"cGG1wblcyMfpKjo8bG68lZYeysrEVOFq"
const
val
APP_ID
=
"11067709"
const
val
API_KEY
=
"APMf6m40GKnZK74ArXYmdMCf"
const
val
SECRET_KEY
=
"KfiA2R9BTWo5xN4R9gHeztMQ6h3seyZL"
const
val
CONN_TIMEOUT
=
2000
const
val
SOCKET_TIMEOUT
=
60000
}
private
lateinit
var
context
:
Context
private
lateinit
var
aipOcr
:
AipOcr
fun
init
(
context
:
Context
)
{
this
.
context
=
context
initOcr
()
}
// 初始化百度ocr调用
private
fun
initOcr
()
{
this
.
aipOcr
=
AipOcr
(
APP_ID
,
API_KEY
,
SECRET_KEY
)
aipOcr
.
setConnectionTimeoutInMillis
(
CONN_TIMEOUT
);
aipOcr
.
setSocketTimeoutInMillis
(
SOCKET_TIMEOUT
);
}
fun
imageOcr
(
filePath
:
String
)
:
String
{
var
res
=
""
try
{
val
options
=
HashMap
<
String
,
String
>()
options
[
"recognize_granularity"
]
=
"big"
options
[
"detect_direction"
]
=
"true"
// 先用简单识别,每天有5w次免费额度
var
result
=
aipOcr
.
basicGeneral
(
filePath
,
options
)
res
=
getOcrWords
(
result
)
// 如果无法识别,调用高精度识别,每天500次额度
if
(!
TextUtils
.
isDigitsOnly
(
res
))
{
result
=
aipOcr
.
basicAccurateGeneral
(
filePath
,
options
)
res
=
getOcrWords
(
result
)
}
val
imageFile
=
File
(
filePath
)
imageFile
.
delete
()
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
res
}
private
fun
getOcrWords
(
result
:
org
.
json
.
JSONObject
):
String
{
var
words
=
""
val
wordsResult
=
result
.
getJSONArray
(
"words_result"
)
val
num
=
result
.
getInt
(
"words_result_num"
)
if
(
wordsResult
!=
null
&&
num
>
0
)
{
val
wordsObject
=
wordsResult
.
getJSONObject
(
0
)
words
=
wordsObject
.
getString
(
"words"
)
words
=
words
.
replace
(
"-"
,
""
)
}
return
words
}
interface
OcrListener
{
fun
onResult
(
result
:
String
)
}
}
\ No newline at end of file
app/src/main/java/com/duolebo/blyrobot/util/AppUtil.kt
View file @
b31b21f7
...
@@ -96,20 +96,30 @@ object AppUtil {
...
@@ -96,20 +96,30 @@ object AppUtil {
}
}
}
}
fun
pngToJpg2
(
pngFilePath
:
String
,
jpgFilePath
:
String
)
{
fun
cropImage
(
imagePath
:
String
)
:
String
{
val
bitmap
:
Bitmap
?
=
BitmapFactory
.
decodeFile
(
pngFilePath
)
val
bitmap
=
BitmapFactory
.
decodeFile
(
imagePath
)
val
cropBitmap
=
Bitmap
.
createBitmap
(
bitmap
,
0
,
905
,
1024
,
100
)
val
index
=
imagePath
.
lastIndexOf
(
'.'
)
val
partName
=
imagePath
.
substring
(
0
,
index
)
val
newPath
=
partName
+
"_ocr.jpg"
val
file
=
File
(
newPath
)
try
{
try
{
val
bos
=
BufferedOutputStream
(
FileOutputStream
(
jpgFilePath
)
)
val
fos
=
FileOutputStream
(
file
)
bitmap
?.
run
{
BufferedOutputStream
(
fos
).
use
{
bos
->
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
bos
)
if
(
cropBitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
bos
))
{
bos
.
flush
()
bos
.
flush
()
}
}
bos
.
close
()
bos
.
close
()
}
fos
.
close
()
}
catch
(
e
:
IOException
)
{
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
e
.
printStackTrace
()
}
finally
{
}
finally
{
bitmap
!!
.
recycle
()
bitmap
!!
.
recycle
()
cropBitmap
!!
.
recycle
()
}
}
return
newPath
}
}
fun
readFromLocal
(
file
:
File
):
String
{
fun
readFromLocal
(
file
:
File
):
String
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment