|
@@ -11,6 +11,7 @@ import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import okhttp3.*;
|
|
import okhttp3.*;
|
|
|
|
+
|
|
import javax.crypto.Cipher;
|
|
import javax.crypto.Cipher;
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
@@ -547,6 +548,210 @@ public class IdCardUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 重要提示代码中所需工具类
|
|
|
|
+ * FileUtil,Base64Util,HttpUtil,GsonUtils请从
|
|
|
|
+ * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
|
|
|
|
+ * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
|
|
|
|
+ * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
|
|
|
|
+ * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
|
|
|
|
+ * 下载
|
|
|
|
+ * 车牌识别
|
|
|
|
+ */
|
|
|
|
+ public static AjaxResult licensePlate(String image) {
|
|
|
|
+ // 请求url
|
|
|
|
+ String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate";
|
|
|
|
+ try {
|
|
|
|
+ // 本地文件路径
|
|
|
|
+ byte[] imgData = FileUtil.readFileByBytes(image);
|
|
|
|
+ String imgStr = com.ruoyi.common.utils.Base64Util.encode(imgData);
|
|
|
|
+ String imgParam = URLEncoder.encode(imgStr, "UTF-8");
|
|
|
|
+ String param = "image=" + imgParam;
|
|
|
|
+ // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
|
|
|
|
+ String accessToken = getAccessToken("TvvuZOOh7MgnlDFnw11ln67n", "CY47OI0eKAzYBD2LO55SM3OITzsyq6DK");
|
|
|
|
+ String result = com.ruoyi.common.utils.HttpUtil.post(url, accessToken, param);
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
|
+ String wordsResult = jsonObject.getString("words_result");
|
|
|
|
+ if (StringUtils.isNotEmpty(wordsResult)){
|
|
|
|
+ JSONObject jsonObjectWordsResult = JSON.parseObject(wordsResult);
|
|
|
|
+ String plateNumber = jsonObjectWordsResult.getString("number");
|
|
|
|
+ System.out.println("车牌:"+plateNumber);
|
|
|
|
+ return AjaxResult.success(plateNumber);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ {
|
|
|
|
+ "words_result": [
|
|
|
|
+ {
|
|
|
|
+ "color": "blue",
|
|
|
|
+ "number": "京KBT355",
|
|
|
|
+ "probability": [
|
|
|
|
+ 0.9999992847,
|
|
|
|
+ 0.999999404,
|
|
|
|
+ 0.9999910593,
|
|
|
|
+ 0.9999765158,
|
|
|
|
+ 0.999994874,
|
|
|
|
+ 0.9998959303,
|
|
|
|
+ 0.9999984503
|
|
|
|
+ ],
|
|
|
|
+ "vertexes_location": [
|
|
|
|
+ {
|
|
|
|
+ "x": 495,
|
|
|
|
+ "y": 589
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "x": 800,
|
|
|
|
+ "y": 587
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "x": 800,
|
|
|
|
+ "y": 676
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "x": 496,
|
|
|
|
+ "y": 678
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "log_id": "6845817085824549137"
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ return AjaxResult.error("识别车牌错误返回:"+result);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return AjaxResult.error();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重要提示代码中所需工具类
|
|
|
|
+ * FileUtil,Base64Util,HttpUtil,GsonUtils请从
|
|
|
|
+ * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
|
|
|
|
+ * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
|
|
|
|
+ * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
|
|
|
|
+ * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
|
|
|
|
+ * 下载
|
|
|
|
+ */
|
|
|
|
+ public static AjaxResult realEstateCertificate(String image) {
|
|
|
|
+ // 请求url
|
|
|
|
+ String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/real_estate_certificate";
|
|
|
|
+ try {
|
|
|
|
+ // 本地文件路径
|
|
|
|
+ byte[] imgData = FileUtil.readFileByBytes(image);
|
|
|
|
+ String imgStr = com.ruoyi.common.utils.Base64Util.encode(imgData);
|
|
|
|
+ String imgParam = URLEncoder.encode(imgStr, "UTF-8");
|
|
|
|
+
|
|
|
|
+ String param = "image=" + imgParam;
|
|
|
|
+
|
|
|
|
+ // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
|
|
|
|
+ String accessToken = getAccessToken("TvvuZOOh7MgnlDFnw11ln67n", "CY47OI0eKAzYBD2LO55SM3OITzsyq6DK");
|
|
|
|
+ String result = com.ruoyi.common.utils.HttpUtil.post(url, accessToken, param);
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ {
|
|
|
|
+ "words_result_num": 11,
|
|
|
|
+ "words_result": {
|
|
|
|
+ "权利人": [
|
|
|
|
+ {
|
|
|
|
+ "word": "阮兴武"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "坐落": [
|
|
|
|
+ {
|
|
|
|
+ "word": "吉水县乌江镇前江村丰山组"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "权利类型": [
|
|
|
|
+ {
|
|
|
|
+ "word": "宅基地使用权/房屋(构筑物)所有权"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "面积": [
|
|
|
|
+ {
|
|
|
|
+ "word": "土地使用权面积:115.720㎡/房屋建筑面积:298.520㎡"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "字第号": [
|
|
|
|
+ {
|
|
|
|
+ "word": "0042537"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "不动产单元号": [
|
|
|
|
+ {
|
|
|
|
+ "word": "360822"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "共有情况": [
|
|
|
|
+ {
|
|
|
|
+ "word": "家庭成员共有"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "用途": [
|
|
|
|
+ {
|
|
|
|
+ "word": "农村宅基地/住宅"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "使用期限": [
|
|
|
|
+ {
|
|
|
|
+ "word": ""
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "登记日期": [
|
|
|
|
+ {
|
|
|
|
+ "word": ""
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "共有人": [
|
|
|
|
+ {
|
|
|
|
+ "word": ""
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ "log_id": 1739493844726379007
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
|
+ String wordsResult = jsonObject.getString("words_result");
|
|
|
|
+ Map<String, Object> map = new HashMap<>(11);
|
|
|
|
+ if (StringUtils.isNotEmpty(wordsResult)) {
|
|
|
|
+ JSONObject jsonObjectWordsResult = JSON.parseObject(wordsResult);
|
|
|
|
+ String ownerName = JSON.parseObject(jsonObjectWordsResult.getString("权利人")).getString("words");
|
|
|
|
+ String location = JSON.parseObject(jsonObjectWordsResult.getString("坐落")).getString("words");
|
|
|
|
+ String rightType = JSON.parseObject(jsonObjectWordsResult.getString("权利类型")).getString("words");
|
|
|
|
+ String area = JSON.parseObject(jsonObjectWordsResult.getString("面积")).getString("words");
|
|
|
|
+ String documentNumber = JSON.parseObject(jsonObjectWordsResult.getString("字第号")).getString("words");
|
|
|
|
+ String propertyUnitNumber = JSON.parseObject(jsonObjectWordsResult.getString("不动产单元号")).getString("words");
|
|
|
|
+ String coOwnership = JSON.parseObject(jsonObjectWordsResult.getString("共有情况")).getString("words");
|
|
|
|
+ String usageType = JSON.parseObject(jsonObjectWordsResult.getString("用途")).getString("words");
|
|
|
|
+ String usagePeriod = JSON.parseObject(jsonObjectWordsResult.getString("使用期限")).getString("words");
|
|
|
|
+ String registrationDate = JSON.parseObject(jsonObjectWordsResult.getString("登记日期")).getString("words");
|
|
|
|
+ String coOwner = JSON.parseObject(jsonObjectWordsResult.getString("共有人")).getString("words");
|
|
|
|
+ map.put("ownerName", ownerName);
|
|
|
|
+ map.put("location", location);
|
|
|
|
+ map.put("rightType", rightType);
|
|
|
|
+ map.put("area", area);
|
|
|
|
+ map.put("documentNumber", documentNumber);
|
|
|
|
+ map.put("propertyUnitNumber", propertyUnitNumber);
|
|
|
|
+ map.put("coOwnership", coOwnership);
|
|
|
|
+ map.put("usageType", usageType);
|
|
|
|
+ map.put("usagePeriod", usagePeriod);
|
|
|
|
+ map.put("registrationDate", registrationDate);
|
|
|
|
+ map.put("coOwner", coOwner);
|
|
|
|
+ } else {
|
|
|
|
+ return AjaxResult.error("房产证识别失败,请检查。");
|
|
|
|
+ }
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ return AjaxResult.success(map);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return AjaxResult.error();
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取文件base64编码
|
|
* 获取文件base64编码
|
|
*
|
|
*
|
|
@@ -599,12 +804,5 @@ public class IdCardUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
|
|
static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
|
|
}
|
|
}
|