最近做了一个人事管理的项目,项目中需要一个简历解析,刚开始自己照着boss上的简历模板写了一个解析类,是通过String的截取和分割做的,但是有个弊端,只能解析指定的模板,后来从阿里云上购买了一个解析工具,就是ResumeSDK简历解析,这个工具只需要对接好解析的接口就可以了
// 设置头字段
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");
// 读取简历内容
byte[] bytes = org.apache.commons.io.FileUtils.readFileToByteArray(new File(fname));
String data = new String(Base64.encodeBase64(bytes), Consts.UTF_8);
// 设置内容信息
JSONObject json = new JSONObject();
json.put("file_name", fname); // 文件名
json.put("file_cont", data); // 经base64编码过的文件内容
json.put("need_avatar", 0); // 是否需要解析头像
json.put("ocr_type", 1); // 1为高级ocr
json.put("version", 1); // 不管字段在简历中有无出现,均在json结果中返回,若无出现则该字段取值为空;
StringEntity params = new StringEntity(json.toString(), Consts.UTF_8);
httpPost.setEntity(params);
// 发送请求
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpPost);
// 处理返回结果
String resCont = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
System.out.println(resCont);
JSONObject res = new JSONObject(resCont);
System.out.println(res.toString(4));
JSONObject jsonResult = res.getJSONObject("result");
,接口会返回解析出来的json数据,假如你成功了,你会获得如下的json数据返回结构:
{
"status": {
"message": "success",
"code": 200
},
"result": {
"name": "姚明",
"gender": "男",
"age": "26",
"marital_status": "未婚",
"polit_status": "群众",
"major": "工业设计学",
"surname": "姚",