|
@@ -1,8 +1,11 @@
|
|
|
-package com.citu.module.menduner.system.util;
|
|
|
+package com.citu.module.menduner.system.service.resume;
|
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
+import com.citu.framework.common.pojo.CommonResult;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.crypto.Mac;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
@@ -19,44 +22,35 @@ import java.security.NoSuchAlgorithmException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
-public class TenUtil {
|
|
|
+@Service
|
|
|
+public class TenResumeServiceImpl implements TenResumeService {
|
|
|
|
|
|
- private static final Logger log = LoggerFactory.getLogger(TenUtil.class);
|
|
|
+ private final Logger log = LoggerFactory.getLogger(TenResumeServiceImpl.class);
|
|
|
|
|
|
- public static 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");
|
|
|
- Key sKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), mac.getAlgorithm());
|
|
|
- mac.init(sKey);
|
|
|
- byte[] hash = mac.doFinal(signStr.getBytes("UTF-8"));
|
|
|
- String sig = new Base64().encode(hash);
|
|
|
+ @Value("${ten.resume.secretid:AKID9zQ0cC08nOPi3R8iWSXHPn4n01HZoawovA0}")
|
|
|
+ private String tenResumeSecretId;
|
|
|
|
|
|
- String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"" + sig + "\"";
|
|
|
- return auth;
|
|
|
- }
|
|
|
|
|
|
- public static String urlencode(Map<?, ?> map) throws UnsupportedEncodingException {
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- for (Map.Entry<?, ?> entry : map.entrySet()) {
|
|
|
- if (sb.length() > 0) {
|
|
|
- sb.append("&");
|
|
|
- }
|
|
|
- sb.append(String.format("%s=%s",
|
|
|
- URLEncoder.encode(entry.getKey().toString(), "UTF-8"),
|
|
|
- URLEncoder.encode(entry.getValue().toString(), "UTF-8")
|
|
|
- ));
|
|
|
+ @Value("${ten.resume.secretkey:HlKf8e7sDtBbm1Am05r0628y2SUYC5LxEz57odxY}")
|
|
|
+ private String tenResumeSecretKey;
|
|
|
+
|
|
|
+ @Value("${ten.resume.url:https://service-9wsy8usn-1302482110.bj.apigw.tencentcs.com/release/ResumeParser}")
|
|
|
+ private String resumeReqUrl;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult tenResumeService(String fileName, String fileContent) {
|
|
|
+ try {
|
|
|
+ String resume = resume(fileName, fileContent, 1, 1, 1);
|
|
|
+ return CommonResult.success(resume);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("tenResumeService error:{}",e.getMessage());
|
|
|
+ throw new RuntimeException("简历解析异常!");
|
|
|
}
|
|
|
- return sb.toString();
|
|
|
}
|
|
|
|
|
|
- // url参数拼接
|
|
|
- private static final String url = "https://service-9wsy8usn-1302482110.bj.apigw.tencentcs.com/release/ResumeParser";
|
|
|
-
|
|
|
/**
|
|
|
*
|
|
|
- * @param secretId 云市场分配的密钥Id
|
|
|
- * @param secretKey 云市场分配的密钥Key
|
|
|
* @param fileName 简历文件名。请务必带上正确的文件后缀名,否则部分简历可能解析失败。
|
|
|
* @param fileCount 简历文件内容(以base64编码),其中:
|
|
|
* 1)图片简历:based64编码后大小不超过8M,最短边至少100px,支持jpg/jpeg/png/bmp/tif/gif格式。
|
|
@@ -73,9 +67,10 @@ public class TenUtil {
|
|
|
* @throws UnsupportedEncodingException
|
|
|
* @throws InvalidKeyException
|
|
|
*/
|
|
|
- public static String resume(String secretId,String secretKey,String fileName,String fileCount,Integer needAvatar
|
|
|
+ public String resume(String fileName,String fileCount,Integer needAvatar
|
|
|
,Integer needSocialExp,Integer version) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
|
|
|
|
|
|
+ String url = resumeReqUrl;
|
|
|
String source = "market";
|
|
|
Calendar cd = Calendar.getInstance();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
|
|
@@ -89,7 +84,7 @@ public class TenUtil {
|
|
|
headers.put("X-Source", source);
|
|
|
headers.put("X-Date", datetime);
|
|
|
// 签名
|
|
|
- headers.put("Authorization", calcAuthorization(source, secretId, secretKey, datetime));
|
|
|
+ headers.put("Authorization", calcAuthorization(source, this.tenResumeSecretId, this.tenResumeSecretKey, datetime));
|
|
|
headers.put("Content-Type","application/json");
|
|
|
// 查询参数
|
|
|
Map<String, String> queryParams = new HashMap<String, String>();
|
|
@@ -161,4 +156,33 @@ public class TenUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ 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");
|
|
|
+ Key sKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), mac.getAlgorithm());
|
|
|
+ mac.init(sKey);
|
|
|
+ byte[] hash = mac.doFinal(signStr.getBytes("UTF-8"));
|
|
|
+ String sig = new Base64().encode(hash);
|
|
|
+
|
|
|
+ String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"" + sig + "\"";
|
|
|
+ return auth;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String urlencode(Map<?, ?> map) throws UnsupportedEncodingException {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (Map.Entry<?, ?> entry : map.entrySet()) {
|
|
|
+ if (sb.length() > 0) {
|
|
|
+ sb.append("&");
|
|
|
+ }
|
|
|
+ sb.append(String.format("%s=%s",
|
|
|
+ URLEncoder.encode(entry.getKey().toString(), "UTF-8"),
|
|
|
+ URLEncoder.encode(entry.getValue().toString(), "UTF-8")
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|