Commit 3b46bc9e by 284718418@qq.com

百度简历解析TIC

parent 08acf2df
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;
}
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());
}
}
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));
}
}
...@@ -234,6 +234,11 @@ config-8timer: ...@@ -234,6 +234,11 @@ config-8timer:
crm-excel: crm-excel:
realPath: 'D:/excel/' realPath: 'D:/excel/'
# 百度人才智库(TIC)
baidu-tic:
appid: XOATkGqX6LvCW3i3Eqd5rg6h
secret: UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
#导出zip临时地址 #导出zip临时地址
zip: zip:
path: 'D:/zip/' path: 'D:/zip/'
......
...@@ -207,6 +207,11 @@ config-8timer: ...@@ -207,6 +207,11 @@ config-8timer:
crm-excel: crm-excel:
realPath: '/data/crm-excel/' realPath: '/data/crm-excel/'
# 百度人才智库(TIC)
baidu-tic:
appid: XOATkGqX6LvCW3i3Eqd5rg6h
secret: UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
#导出zip临时地址 #导出zip临时地址
zip: zip:
path: '/data/crm-zip/' path: '/data/crm-zip/'
......
...@@ -207,6 +207,11 @@ config-8timer: ...@@ -207,6 +207,11 @@ config-8timer:
crm-excel: crm-excel:
realPath: '/data/crm-excel/' realPath: '/data/crm-excel/'
# 百度人才智库(TIC)
baidu-tic:
appid: XOATkGqX6LvCW3i3Eqd5rg6h
secret: UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
#导出zip临时地址 #导出zip临时地址
zip: zip:
path: '/data/crm-zip/' path: '/data/crm-zip/'
......
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