|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ydtech.core.page.HttpResult;
|
|
import com.ydtech.core.page.HttpResult;
|
|
|
import com.ydtech.modules.ins.model.CustomerInfoVO;
|
|
import com.ydtech.modules.ins.model.CustomerInfoVO;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
@@ -14,8 +15,13 @@ import java.util.Map;
|
|
|
/**
|
|
/**
|
|
|
* 身份证识别
|
|
* 身份证识别
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
public class Idcard {
|
|
public class Idcard {
|
|
|
|
|
|
|
|
|
|
+ private Idcard() {
|
|
|
|
|
+ throw new IllegalStateException("Idcard class");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 重要提示代码中所需工具类
|
|
* 重要提示代码中所需工具类
|
|
|
* FileUtil,Base64Util,HttpUtil,GsonUtils请从
|
|
* FileUtil,Base64Util,HttpUtil,GsonUtils请从
|
|
@@ -25,7 +31,7 @@ public class Idcard {
|
|
|
* https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
|
|
* https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
|
|
|
* 下载
|
|
* 下载
|
|
|
*/
|
|
*/
|
|
|
- public static HttpResult getIdCard(String imgs) {
|
|
|
|
|
|
|
+ public static HttpResult<Map<String, Object>> getIdCard(String imgs) {
|
|
|
|
|
|
|
|
//// 从redis中获取信息,redis保存时间是20天。
|
|
//// 从redis中获取信息,redis保存时间是20天。
|
|
|
String accessToken = AuthService.getAuth();
|
|
String accessToken = AuthService.getAuth();
|
|
@@ -35,20 +41,18 @@ public class Idcard {
|
|
|
try {
|
|
try {
|
|
|
String imgParam = URLEncoder.encode(imgs, "UTF-8");
|
|
String imgParam = URLEncoder.encode(imgs, "UTF-8");
|
|
|
String param = "id_card_side=" + "front" + "&image=" + imgParam + "&detect_photo=true";
|
|
String param = "id_card_side=" + "front" + "&image=" + imgParam + "&detect_photo=true";
|
|
|
- ;
|
|
|
|
|
|
|
|
|
|
String result = HttpUtil.post(url, accessToken, param);
|
|
String result = HttpUtil.post(url, accessToken, param);
|
|
|
JSONObject ja = JSON.parseObject(result);
|
|
JSONObject ja = JSON.parseObject(result);
|
|
|
- System.out.println(ja);
|
|
|
|
|
-
|
|
|
|
|
- String words_result = ja.getString("words_result");
|
|
|
|
|
|
|
+ log.info(ja.toString());
|
|
|
|
|
|
|
|
|
|
+ String wordsResult = ja.getString("wordsResult");
|
|
|
|
|
|
|
|
CustomerInfoVO customerInfo = new CustomerInfoVO();
|
|
CustomerInfoVO customerInfo = new CustomerInfoVO();
|
|
|
- JSONObject jb = JSON.parseObject(words_result);
|
|
|
|
|
- customerInfo.setName(JSON.parseObject(jb.getString("姓名")).getString("words").toString());
|
|
|
|
|
- customerInfo.setIdentifyNumber(JSON.parseObject(jb.getString("公民身份号码")).getString("words").toString());
|
|
|
|
|
- customerInfo.setAddr(JSON.parseObject(jb.getString("住址")).getString("words").toString());
|
|
|
|
|
|
|
+ JSONObject jb = JSON.parseObject(wordsResult);
|
|
|
|
|
+ customerInfo.setName(JSON.parseObject(jb.getString("姓名")).getString("words"));
|
|
|
|
|
+ customerInfo.setIdentifyNumber(JSON.parseObject(jb.getString("公民身份号码")).getString("words"));
|
|
|
|
|
+ customerInfo.setAddr(JSON.parseObject(jb.getString("住址")).getString("words"));
|
|
|
customerInfo.setIdentifyType("01");
|
|
customerInfo.setIdentifyType("01");
|
|
|
customerInfo.setIdentifyValidDate(JSON.parseObject(jb.getString("出生")).getString("words"));
|
|
customerInfo.setIdentifyValidDate(JSON.parseObject(jb.getString("出生")).getString("words"));
|
|
|
customerInfo.setIdentifyIssuedCom(JSON.parseObject(jb.getString("性别")).getString("words"));
|
|
customerInfo.setIdentifyIssuedCom(JSON.parseObject(jb.getString("性别")).getString("words"));
|
|
@@ -60,21 +64,19 @@ public class Idcard {
|
|
|
return HttpResult.ok("201", ma);
|
|
return HttpResult.ok("201", ma);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static JSONObject request(String image, String id_card_side) {
|
|
|
|
|
|
|
+ public static JSONObject request(String image, String idCardSide) {
|
|
|
//// 从redis中获取信息,redis保存时间是20天。
|
|
//// 从redis中获取信息,redis保存时间是20天。
|
|
|
String accessToken = AuthService.getAuth();
|
|
String accessToken = AuthService.getAuth();
|
|
|
- Map<String, Object> ma = new HashMap<>();
|
|
|
|
|
// 请求url
|
|
// 请求url
|
|
|
String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard";
|
|
String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard";
|
|
|
try {
|
|
try {
|
|
|
String imgParam = URLEncoder.encode(image, "UTF-8");
|
|
String imgParam = URLEncoder.encode(image, "UTF-8");
|
|
|
- String param = "id_card_side=" + id_card_side + "&image=" + imgParam + "&detect_photo=true";
|
|
|
|
|
|
|
+ String param = "idCardSide=" + idCardSide + "&image=" + imgParam + "&detect_photo=true";
|
|
|
String result = HttpUtil.post(url, accessToken, param);
|
|
String result = HttpUtil.post(url, accessToken, param);
|
|
|
- JSONObject ja = JSONObject.parseObject(result);
|
|
|
|
|
- System.out.println(ja);
|
|
|
|
|
- String words_result = ja.getString("words_result");
|
|
|
|
|
- JSONObject jb = JSONObject.parseObject(words_result);
|
|
|
|
|
- return jb;
|
|
|
|
|
|
|
+ JSONObject ja = JSON.parseObject(result);
|
|
|
|
|
+ log.info(ja.toString());
|
|
|
|
|
+ String wordsResult = ja.getString("words_result");
|
|
|
|
|
+ return JSON.parseObject(wordsResult);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|