|
@@ -14,12 +14,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.crypto.Mac;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.DataOutputStream;
|
|
|
-import java.io.InputStreamReader;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
-import java.net.HttpURLConnection;
|
|
|
-import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.security.InvalidKeyException;
|
|
|
import java.security.Key;
|
|
@@ -30,7 +25,7 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class TenResumeServiceImpl implements TenResumeService {
|
|
|
|
|
|
- private final Logger log = LoggerFactory.getLogger(TenResumeServiceImpl.class);
|
|
|
+ private final Logger log = LoggerFactory.getLogger(TenResumeServiceImpl.class);
|
|
|
|
|
|
@Value("${ten.resume.secretid:AKID9zQ0cC08nOPi3R8iWSXHPn4n01HZoawovA0}")
|
|
|
private String tenResumeSecretId;
|
|
@@ -48,32 +43,31 @@ public class TenResumeServiceImpl implements TenResumeService {
|
|
|
try {
|
|
|
TemResumeResVo resume = resume(fileName, fileContent, 1, 1, 1);
|
|
|
return CommonResult.success(resume);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("tenResumeService error:{}",e.getMessage());
|
|
|
- throw new RuntimeException("简历解析异常!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("tenResumeService error:{}", e.getMessage());
|
|
|
+ throw new RuntimeException("简历解析异常!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * @param fileName 简历文件名。请务必带上正确的文件后缀名,否则部分简历可能解析失败。
|
|
|
- * @param fileCount 简历文件内容(以base64编码),其中:
|
|
|
- * 1)图片简历:based64编码后大小不超过8M,最短边至少100px,支持jpg/jpeg/png/bmp/tif/gif格式。
|
|
|
- * 图片越大OCR超时风险越高,建议大小不超过4M、长宽比小于4、分辨率600*800以上;
|
|
|
- * 2)非图片简历:based64编码后大小不超过10M(注:阿里云接口是不超过8M);
|
|
|
- * @param needAvatar 是否需要解析头像,0为不需要,1为需要,默认为0。(注:解析头像会增加1倍左右耗时,如不需头像建议不开启)
|
|
|
+ * @param fileName 简历文件名。请务必带上正确的文件后缀名,否则部分简历可能解析失败。
|
|
|
+ * @param fileCount 简历文件内容(以base64编码),其中:
|
|
|
+ * 1)图片简历:based64编码后大小不超过8M,最短边至少100px,支持jpg/jpeg/png/bmp/tif/gif格式。
|
|
|
+ * 图片越大OCR超时风险越高,建议大小不超过4M、长宽比小于4、分辨率600*800以上;
|
|
|
+ * 2)非图片简历:based64编码后大小不超过10M(注:阿里云接口是不超过8M);
|
|
|
+ * @param needAvatar 是否需要解析头像,0为不需要,1为需要,默认为0。(注:解析头像会增加1倍左右耗时,如不需头像建议不开启)
|
|
|
* @param needSocialExp 是否需要解析实践经历,0为不需要,1为需要,默认为0:
|
|
|
* 1)若需要解析,则对“社会实践”及“在校活动”文本进行解析,解析结果放置在social_exp_objs字段中
|
|
|
- * @param version 接口版本,当前取值为0和1,默认为0:
|
|
|
- * 1)version=0:仅当字段在简历中有出现,才会在json结果中返回;
|
|
|
- * 2)version=1:不管字段在简历中有无出现,均在json结果中返回,若无出现则该字段取值为空;
|
|
|
+ * @param version 接口版本,当前取值为0和1,默认为0:
|
|
|
+ * 1)version=0:仅当字段在简历中有出现,才会在json结果中返回;
|
|
|
+ * 2)version=1:不管字段在简历中有无出现,均在json结果中返回,若无出现则该字段取值为空;
|
|
|
* @return
|
|
|
* @throws NoSuchAlgorithmException
|
|
|
* @throws UnsupportedEncodingException
|
|
|
* @throws InvalidKeyException
|
|
|
*/
|
|
|
- public TemResumeResVo resume(String fileName,String fileCount,Integer needAvatar
|
|
|
- ,Integer needSocialExp,Integer version) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
|
|
|
+ public TemResumeResVo resume(String fileName, String fileCount, Integer needAvatar
|
|
|
+ , Integer needSocialExp, Integer version) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
|
|
|
|
|
|
String url = resumeReqUrl;
|
|
|
String source = "market";
|
|
@@ -84,35 +78,33 @@ public class TenResumeServiceImpl implements TenResumeService {
|
|
|
|
|
|
// body参数
|
|
|
Map<String, String> bodyParams = new HashMap<String, String>();
|
|
|
- bodyParams.put("body","");
|
|
|
- bodyParams.put("file_name",fileName);
|
|
|
- bodyParams.put("file_cont",fileCount);
|
|
|
- bodyParams.put("need_avatar",needAvatar.toString());
|
|
|
- bodyParams.put("need_social_exp",needSocialExp.toString());
|
|
|
- bodyParams.put("version",version.toString());
|
|
|
+ bodyParams.put("body", "");
|
|
|
+ bodyParams.put("file_name", fileName);
|
|
|
+ bodyParams.put("file_cont", fileCount);
|
|
|
+ bodyParams.put("need_avatar", needAvatar.toString());
|
|
|
+ bodyParams.put("need_social_exp", needSocialExp.toString());
|
|
|
+ bodyParams.put("version", version.toString());
|
|
|
|
|
|
HttpRequest post = HttpUtil.createPost(url);
|
|
|
post.header("X-Source", source);
|
|
|
post.header("X-Date", datetime);
|
|
|
// 签名
|
|
|
post.header("Authorization", calcAuthorization(source, this.tenResumeSecretId, this.tenResumeSecretKey, datetime));
|
|
|
- post.header("Content-Type","application/json");
|
|
|
+ post.header("Content-Type", "application/json");
|
|
|
post.body(JSON.toJSONString(bodyParams));
|
|
|
HttpResponse execute = post.execute();
|
|
|
String body = execute.body();
|
|
|
- log.info("parse resume res->{}",body);
|
|
|
+ log.info("parse resume res->{}", body);
|
|
|
System.out.println(body);
|
|
|
TemResumeResVo temResumeResVo = JSON.parseObject(body, TemResumeResVo.class);
|
|
|
- if(temResumeResVo.getStatus().getCode()!=200){
|
|
|
- throw new RuntimeException("简历解析失败");
|
|
|
+ if (temResumeResVo.getStatus().getCode() != 200) {
|
|
|
+ throw new RuntimeException("简历解析失败");
|
|
|
}
|
|
|
- return temResumeResVo;
|
|
|
+ return temResumeResVo;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private String calcAuthorization(String source, String secretId, String secretKey, String datetime)
|
|
|
+ private String calcAuthorization(String source, String secretId, String secretKey, String datetime)
|
|
|
throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
|
|
|
String signStr = "x-date: " + datetime + "\n" + "x-source: " + source;
|
|
|
Mac mac = Mac.getInstance("HmacSHA1");
|
|
@@ -125,7 +117,7 @@ public class TenResumeServiceImpl implements TenResumeService {
|
|
|
return auth;
|
|
|
}
|
|
|
|
|
|
- private String urlencode(Map<?, ?> map) throws UnsupportedEncodingException {
|
|
|
+ private String urlencode(Map<?, ?> map) throws UnsupportedEncodingException {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
|
|
if (sb.length() > 0) {
|
|
@@ -140,5 +132,4 @@ public class TenResumeServiceImpl implements TenResumeService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|