Commit b4dcec11 by 284718418@qq.com

ResumeSDK 本地测试

parent dfa76a5c
......@@ -268,11 +268,17 @@ public class ZpglServiceImpl implements ZpglService {
public Result<Object> addResumeImportCandidate(UserBean userBean, MultipartFile file, ImportCandidateDto importCandidateDto) {
/*BaiduTicResumeDto baiduTicResumeDto = BaiduTicResumeDto.builder().filename(file.getOriginalFilename()).filetype(importCandidateDto.getSuffix()).filedata(Base64.getStrFromPath(file)).build();
ResponseEntity<String> resumeString = baiduTicUtil.getResumeByCvParser(baiduTicResumeDto);*/
ResumeSdkDto resumeSdkDto = ResumeSdkDto.builder().ocr_type(1).need_avatar(0).file_name(file.getOriginalFilename()).file_cont(Base64.getStrFromPath(file)).filetype(importCandidateDto.getSuffix()).build();
ResponseEntity<String> resumeString = resumeSDKUtil.getResumeByCvParser(resumeSdkDto, RESUMESDK_APPCODE);
ResumeSdkDto resumeSdkDto = ResumeSdkDto.builder().ocr_type(1).need_avatar(0).file_name(file.getOriginalFilename()).file_cont(Base64.getStrFromPath(file)).build();
String resumeString = "";
try {
resumeString = resumeSDKUtil.getResumeByCvParser(resumeSdkDto, RESUMESDK_APPCODE);
}catch (Exception e){
e.printStackTrace();
}
JSONObject json = (JSONObject) JSONObject.parse(resumeString.getBody());
log.info("招聘-导入候选人简历{}", resumeString.getBody());
JSONObject json = (JSONObject) JSONObject.parse(resumeString);
log.info("招聘-导入候选人简历{}", resumeString);
return ResultUtil.success();
/*ResumeExtract resumeExtract = null;
if ("success".equals(json.get("error_msg"))) {
......
......@@ -24,10 +24,6 @@ public class ResumeSdkDto implements Serializable {
*/
private String file_name;
/**
* 简历文档类型,目前支持pdf、doc、docx、wps、txt、jpg、jpeg、png、bmp、tif格式
*/
private String filetype;
/**
* 必填字段 简历文件内容(以base64编码),其中:
* 1)图片简历:经based64编码后大小建议不超过1M,最短边至少50px,最长边最大4096px,
* 支持jpg/jpeg/png/bmp/tif/gif格式;
......
package cn.timer.api.utils.resumesdk;
import cn.timer.api.dto.resumesdk.ResumeSdkDto;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.Consts;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
......@@ -10,7 +18,11 @@ 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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author wuqingjun
......@@ -20,18 +32,46 @@ import java.util.List;
@Component
public class ResumeSDKUtil {
public ResponseEntity<String> getResumeByCvParser(ResumeSdkDto resumeSdkDto, String appCode){
public String getResumeByCvParser(ResumeSdkDto resumeSdkDto, String appCode) throws Exception {
String url = "http://resumesdk.market.alicloudapi.com/ResumeParser";
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
List<String> list = new ArrayList<>();
list.add("Authorization");
list.add("APPCODE " + appCode);
list.add("Content-Type");
list.add("application/json; charset=UTF-8");
list.add("Content-Type");
list.add("application/json");
headers.put("header", list);
HttpEntity requestEntity = new HttpEntity(resumeSdkDto, headers);
return new RestTemplate().exchange(url, HttpMethod.POST,requestEntity, String.class);
// 设置头字段
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization", "APPCODE " + appCode);
httpPost.addHeader("Content-Type", "application/json; charset=UTF-8");
httpPost.addHeader("Content-Type", "application/json");
// 设置内容信息
JSONObject json = new JSONObject();
json.put("file_name", resumeSdkDto.getFile_name()); // 文件名
json.put("file_cont", resumeSdkDto.getFile_cont()); // 经base64编码过的文件内容
json.put("need_avatar", 0); // 是否需要解析头像
json.put("ocr_type", 1); // 1为高级ocr
StringEntity params = new StringEntity(json.toString(), Consts.UTF_8);
httpPost.setEntity(params);
// 发送请求
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpPost);
// 处理返回结果
return unicodeToCN(EntityUtils.toString(response.getEntity(), Consts.UTF_8));
}
/**
* Unicode转 汉字字符串
*
* @param str
* @return
*/
private static String unicodeToCN(String str) {
Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
Matcher matcher = pattern.matcher(str);
char ch;
while (matcher.find()) {
ch = (char) Integer.parseInt(matcher.group(2), 16);
str = str.replace(matcher.group(1), ch + "");
}
return str;
}
}
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