Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
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
youjj
cloud-platform
Commits
19abad6b
Commit
19abad6b
authored
Oct 19, 2020
by
周健威
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master-tiande' into dev-tiande
parents
f6adba71
96084202
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
XCFQPictureParsingImpl.java
...l/service/PictureParsing/impl/XCFQPictureParsingImpl.java
+72
-0
No files found.
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/PictureParsing/impl/XCFQPictureParsingImpl.java
View file @
19abad6b
...
@@ -14,7 +14,13 @@ import org.apache.http.HttpResponse;
...
@@ -14,7 +14,13 @@ import org.apache.http.HttpResponse;
import
org.apache.http.StatusLine
;
import
org.apache.http.StatusLine
;
import
org.apache.http.util.EntityUtils
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
sun.misc.BASE64Encoder
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -127,6 +133,22 @@ public class XCFQPictureParsingImpl implements UserPictureParsing {
...
@@ -127,6 +133,22 @@ public class XCFQPictureParsingImpl implements UserPictureParsing {
return
null
;
return
null
;
}
}
//身份证照片解析
private
String
imageParseBase64
(
String
imageUrl
)
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode2
);
Map
<
String
,
String
>
querys
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
bodys
=
new
HashMap
<
String
,
String
>();
String
imgUrlToBase64
=
getImgUrlToBase64
(
imageUrl
);
bodys
.
put
(
"image"
,
imgUrlToBase64
);
try
{
return
callExternalRequest
(
headers
,
querys
,
bodys
,
1
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
return
null
;
}
private
String
callExternalRequest
(
Map
<
String
,
String
>
headers
,
private
String
callExternalRequest
(
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
,
Map
<
String
,
String
>
querys
,
...
@@ -154,4 +176,54 @@ public class XCFQPictureParsingImpl implements UserPictureParsing {
...
@@ -154,4 +176,54 @@ public class XCFQPictureParsingImpl implements UserPictureParsing {
return
null
;
return
null
;
}
}
/**
* 将网络图片转换成Base64编码字符串
*
* @param imgUrl 网络图片Url
* @return
*/
public
static
String
getImgUrlToBase64
(
String
imgUrl
)
{
InputStream
inputStream
=
null
;
ByteArrayOutputStream
outputStream
=
null
;
byte
[]
buffer
=
null
;
try
{
// 创建URL
URL
url
=
new
URL
(
imgUrl
);
// 创建链接
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setConnectTimeout
(
5000
);
inputStream
=
conn
.
getInputStream
();
outputStream
=
new
ByteArrayOutputStream
();
// 将内容读取内存中
buffer
=
new
byte
[
1024
];
int
len
=
-
1
;
while
((
len
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
len
);
}
buffer
=
outputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
inputStream
!=
null
)
{
try
{
// 关闭inputStream流
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
outputStream
!=
null
)
{
try
{
// 关闭outputStream流
outputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
// 对字节数组Base64编码
return
new
BASE64Encoder
().
encode
(
buffer
);
}
}
}
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