Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
87039117
Commit
87039117
authored
Mar 30, 2022
by
284718418@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
百度简历解析TIC
parent
04499995
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
165 additions
and
0 deletions
+165
-0
src/main/java/cn/timer/api/dto/baidu/BaiduTicResumeDto.java
+41
-0
src/main/java/cn/timer/api/utils/baidu/BaiduTicUtil.java
+63
-0
src/main/java/cn/timer/api/utils/baidu/Base64.java
+51
-0
src/main/resources/application-dev.yml
+5
-0
src/main/resources/application-test.yml
+5
-0
No files found.
src/main/java/cn/timer/api/dto/baidu/BaiduTicResumeDto.java
0 → 100644
View file @
87039117
package
cn
.
timer
.
api
.
dto
.
baidu
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
/**
* 简历相关请求参数,每次一份简历
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/3/29
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
BaiduTicResumeDto
implements
Serializable
{
/**
* 简历文档名称,文件大小不超过10M
*/
private
String
filename
;
/**
* 简历文档类型,目前支持pdf、doc、docx、wps、txt、jpg、jpeg、png、bmp、tif格式
*/
private
String
filetype
;
/**
* 待解析文档内容,必须是二进制读取,base64编码
*/
private
String
filedata
;
/**
* 非必填
* 需要保留的字段,每个元素表示需要保留的字段位置,
* 具体格式参考返回参数中results参数部分,
* 如' ["basic_infos.name", "education_infos[].school", "work_infos"] ';
* 层级按半角圆点“.”分割,list类型用半角方括号“[]”表示。如果不填该参数,默认选择全部字段
*/
private
String
fields
;
}
src/main/java/cn/timer/api/utils/baidu/BaiduTicUtil.java
0 → 100644
View file @
87039117
package
cn
.
timer
.
api
.
utils
.
baidu
;
import
cn.timer.api.dto.baidu.BaiduTicResumeDto
;
import
com.google.gson.Gson
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/3/29
*/
@Component
public
class
BaiduTicUtil
{
@Value
(
"${config-8timer.baidu-tic.appid}"
)
private
static
String
appid
=
"XOATkGqX6LvCW3i3Eqd5rg6h"
;
@Value
(
"${config-8timer.baidu-tic.secret}"
)
private
static
String
secret
=
"UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS"
;
/**
* 获取百度token
* @return
*/
public
static
String
getBaiduAccessToken
(){
StringBuffer
url
=
new
StringBuffer
(
"https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id="
);
url
=
url
.
append
(
appid
).
append
(
"&client_secret="
).
append
(
secret
);
ResponseEntity
<
String
>
response
=
new
RestTemplate
().
exchange
(
url
.
toString
(),
HttpMethod
.
GET
,
null
,
String
.
class
);
return
new
Gson
().
fromJson
(
response
.
getBody
(),
HashMap
.
class
).
get
(
"access_token"
).
toString
();
}
public
static
ResponseEntity
<
String
>
getResumeByCvParser
(
BaiduTicResumeDto
baiduTicResumeDto
){
String
url
=
"https://aip.baidubce.com/rpc/2.0/recruitment/v1/cvparser?access_token="
+
getBaiduAccessToken
();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"resume"
,
baiduTicResumeDto
);
MultiValueMap
<
String
,
String
>
headers
=
new
LinkedMultiValueMap
<>();
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"Content-Type"
);
list
.
add
(
"application/json"
);
headers
.
put
(
"header"
,
list
);
HttpEntity
requestEntity
=
new
HttpEntity
(
param
,
headers
);
return
new
RestTemplate
().
exchange
(
url
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
}
public
static
void
main
(
String
[]
args
)
{
BaiduTicResumeDto
baiduTicResumeDto
=
BaiduTicResumeDto
.
builder
().
filename
(
"邓志鸿.docx"
).
filetype
(
"docx"
).
filedata
(
Base64
.
getStrFromPath
(
"https://test-img.8timer.cn/6b8c7ec7-14b0-45e7-aa21-7acd0d45e612.docx"
)).
build
();
ResponseEntity
<
String
>
responseEntity
=
getResumeByCvParser
(
baiduTicResumeDto
);
System
.
out
.
println
(
responseEntity
.
getBody
());
}
}
src/main/java/cn/timer/api/utils/baidu/Base64.java
0 → 100644
View file @
87039117
package
cn
.
timer
.
api
.
utils
.
baidu
;
import
sun.misc.BASE64Encoder
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/3/29
*/
public
class
Base64
{
private
static
HttpURLConnection
httpUrl
=
null
;
/**
* 转化成Base64字符串
*/
public
static
String
getStrFromPath
(
String
imgPath
)
{
URL
url
=
null
;
InputStream
in
=
null
;
byte
[]
data
=
null
;
try
{
url
=
new
URL
(
imgPath
);
httpUrl
=
(
HttpURLConnection
)
url
.
openConnection
();
httpUrl
.
connect
();
httpUrl
.
getInputStream
();
in
=
httpUrl
.
getInputStream
();
data
=
new
byte
[
in
.
available
()];
in
.
read
(
data
);
in
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// 对字节数组Base64编码
BASE64Encoder
encoder
=
new
BASE64Encoder
();
// 返回Base64编码过再URLEncode的字节数组字符串
return
URLEncoder
.
encode
(
encoder
.
encode
(
data
));
}
}
src/main/resources/application-dev.yml
View file @
87039117
...
...
@@ -234,6 +234,11 @@ config-8timer:
crm-excel
:
realPath
:
'
D:/excel/'
# 百度人才智库(TIC)
baidu-tic
:
appid
:
XOATkGqX6LvCW3i3Eqd5rg6h
secret
:
UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
#导出zip临时地址
zip
:
path
:
'
D:/zip/'
...
...
src/main/resources/application-test.yml
View file @
87039117
...
...
@@ -216,6 +216,11 @@ config-8timer:
crm-excel
:
realPath
:
'
/data/crm-excel/'
# 百度人才智库(TIC)
baidu-tic
:
appid
:
XOATkGqX6LvCW3i3Eqd5rg6h
secret
:
UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
#导出zip临时地址
zip
:
path
:
'
/data/crm-zip/'
...
...
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