瀏覽代碼

身份证户口本识别错误异常处理

fllmoyu 5 年之前
父節點
當前提交
85e61a9a6e
共有 1 個文件被更改,包括 23 次插入12 次删除
  1. 23 12
      web/src/main/java/com/jpsoft/campus/modules/mobile/controller/PersonInfoApiController.java

+ 23 - 12
web/src/main/java/com/jpsoft/campus/modules/mobile/controller/PersonInfoApiController.java

@@ -333,12 +333,18 @@ public class PersonInfoApiController {
 
                 JSONObject wordsResult = jsonObject.getJSONObject("words_result");
 
-                dataMap.put("address", wordsResult.getJSONObject("住址").getString("words"));
-                dataMap.put("idCard", wordsResult.getJSONObject("公民身份号码").getString("words"));
-                dataMap.put("birthday",wordsResult.getJSONObject("出生").getString("words"));
-                dataMap.put("name",wordsResult.getJSONObject("姓名").getString("words"));
-                dataMap.put("sex",wordsResult.getJSONObject("性别").getString("words"));
-                dataMap.put("nation",wordsResult.getJSONObject("民族").getString("words"));
+                try{
+                    dataMap.put("address", wordsResult.getJSONObject("住址").getString("words"));
+                    dataMap.put("idCard", wordsResult.getJSONObject("公民身份号码").getString("words"));
+                    dataMap.put("birthday",wordsResult.getJSONObject("出生").getString("words"));
+                    dataMap.put("name",wordsResult.getJSONObject("姓名").getString("words"));
+                    dataMap.put("sex",wordsResult.getJSONObject("性别").getString("words"));
+                    dataMap.put("nation",wordsResult.getJSONObject("民族").getString("words"));
+                }catch (Exception e){
+                    throw new Exception("身份证识别错误");
+                }
+
+
             } else {
                 JSONObject jsonObject = BaiduOCR.householdRegister(accessToken, imageBase64Data);
 
@@ -355,12 +361,17 @@ public class PersonInfoApiController {
 
                 JSONObject wordsResult = jsonObject.getJSONObject("words_result");
 
-                dataMap.put("address", wordsResult.getJSONObject("BirthAddress").getString("words"));
-                dataMap.put("idCard", wordsResult.getJSONObject("CardNo").getString("words"));
-                dataMap.put("birthday",wordsResult.getJSONObject("Birthday").getString("words"));
-                dataMap.put("name",wordsResult.getJSONObject("Name").getString("words"));
-                dataMap.put("sex",wordsResult.getJSONObject("Sex").getString("words"));
-                dataMap.put("nation",wordsResult.getJSONObject("Nation").getString("words"));
+                try{
+                    dataMap.put("address", wordsResult.getJSONObject("BirthAddress").getString("words"));
+                    dataMap.put("idCard", wordsResult.getJSONObject("CardNo").getString("words"));
+                    dataMap.put("birthday",wordsResult.getJSONObject("Birthday").getString("words"));
+                    dataMap.put("name",wordsResult.getJSONObject("Name").getString("words"));
+                    dataMap.put("sex",wordsResult.getJSONObject("Sex").getString("words"));
+                    dataMap.put("nation",wordsResult.getJSONObject("Nation").getString("words"));
+                }catch (Exception e){
+                    throw new Exception("户口本识别错误");
+                }
+
             }
 
             if (dataMap.get("birthday")!=null){