|
@@ -1025,5 +1025,393 @@ public class IdCardUtil {
|
|
|
}
|
|
|
|
|
|
}*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 图片文字识别
|
|
|
+ * @param filePath 本地文件路径
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Map<String,Object> accurateBasicCj(String filePath) {
|
|
|
+ String imgParam = getFileContentAsBase64(filePath, true);
|
|
|
+ String param = "image=" + imgParam+"&detect_direction=true";
|
|
|
+ MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
+ // image 可以通过 getFileContentAsBase64("C:\fakepath\zhizhao.jpg") 方法获取,如果Content-Type是application/x-www-form-urlencoded时,第二个参数传true
|
|
|
+ RequestBody body = RequestBody.create(mediaType, param);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url("https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=" + getAccessToken("TvvuZOOh7MgnlDFnw11ln67n", "CY47OI0eKAzYBD2LO55SM3OITzsyq6DK"))
|
|
|
+ .method("POST", body)
|
|
|
+ .addHeader("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ .addHeader("Accept", "application/json")
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+/* {
|
|
|
+ "words_result": [
|
|
|
+ {
|
|
|
+ "words": "http:/10.0.175.74/ahlm/loan/Sv-2024.07.04/jbview.afx.html.print.printer.html?window页码,2024(w9"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "安徽农金"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借据"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "ARCU"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "贷款单位:安徽潜山农村商业银行股份有限公司塔畈支行"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借款人:潜山和沐物流有限公司"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "客户编号:200101281091"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "证件号码:913408243487083682"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借据编号:860066291011"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借款合同编号:2397591220240003"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借款日期:2024年08月09日"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借款到期日:2025年08月09日"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借款金额(大写):人民币贰佰万元整"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "(小写):¥2,000,000.00"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "担保方式:保证"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借款用途说明:进货"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "利率种类:年利率"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "贷款利率:6.09000000%"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "第一联银行贷款债权凭证"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "还款方式:按月结息、到期一次性还本法"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "还款账号:20010128109166600000032"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "以上款项已转入借款人指定账户"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "贷款单位(签章"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "分书·00010X022"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "借款人(签章或按指印):"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "负责人:"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "法定代表人(负责人)"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "孙慧"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "客户经理"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "或授权代理人(签章)"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": ".证件号码:"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "经办人:"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "网址:www.ahrcu.com"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "words": "客服电话:96669"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "words_result_num": 34,
|
|
|
+ "direction": 0,
|
|
|
+ "log_id": 1824253359437875000
|
|
|
+ }*/
|
|
|
+ Response response = HTTP_CLIENT.newCall(request).execute();
|
|
|
+ String result = response.body().string();
|
|
|
+ if (StringUtils.isNotBlank(result)){
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ JSONArray wordsResult = jsonObject.getJSONArray("words_result");
|
|
|
+ Map<String, Object> bankMap = bankCj(wordsResult);
|
|
|
+ return bankMap;
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * {
|
|
|
+ * "words_result": [
|
|
|
+ * {
|
|
|
+ * "words": "-20230822-287806450001.pdf-Adobe Reader"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "文档(D)"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "工具①"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "窗口(W)"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "帮助H)"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "/1"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "125%"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "查找"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "中国银行"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "贷款放款回单"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "BANK OF CHINA"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "客户号:572904279"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "日期:2023年08月22日"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "收款人账号:178257778412"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "贷款账号:181273443198"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "收款人名称:潜山县永杰竹业有限公司"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "收款人开户行:中国银行潜山支行"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "金额:CNY1,000,000.00"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "人民币壹佰万元整"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "合同金额:CNY1,000,000.00"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "合同编号:15003616890"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "起息日:2023/08/22"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "到期日:2024/08/22"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "借款人名称:潜山县永杰竹业有限公司"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "收款人卡号:"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "附言:"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "中国银行股份有限公司"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "电子回单专用章"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "如您已通过银行网点取得相应纸质回单,请注意核对,勿重复记账!"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "交易机构:08731"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "交易渠道:柜台"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "交易流水号:80114160-996"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "经办:"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "回单编号:2308220801141608"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "回单验证码:24BN8WT36FM2"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "打印时间:"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "打印次数:"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "words": "次"
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * "words_result_num": 38,
|
|
|
+ * "direction": 0,
|
|
|
+ * "log_id": 1825789540967617800
|
|
|
+ * }
|
|
|
+ */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从图片识别中提取数据
|
|
|
+ * @param wordsResult
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Map<String,Object> bankCj(JSONArray wordsResult){
|
|
|
+ Map<String,Object> map = new HashMap<>(2);
|
|
|
+ map.put("dkdw","");
|
|
|
+ map.put("jkr","");
|
|
|
+ map.put("jkje","");
|
|
|
+ map.put("jkytsm","");
|
|
|
+ map.put("hksj","");
|
|
|
+ int hksj = 0;
|
|
|
+ String strTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ for (int i = 0; i < wordsResult.size(); i++) {
|
|
|
+ String o = wordsResult.get(i).toString();
|
|
|
+ if (o.contains("\"words\":\"中国银行\"")){
|
|
|
+ for (int p = 0; p < wordsResult.size(); p++) {
|
|
|
+ String b = wordsResult.get(p).toString();
|
|
|
+ if (b.contains("收款人开户行")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ String cny = split[1];
|
|
|
+ map.put("dkdw",cny);
|
|
|
+ }
|
|
|
+ if (b.contains("借款人名称")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ String cny = split[1];
|
|
|
+ map.put("jkr",cny);
|
|
|
+ }
|
|
|
+ if (b.contains("合同金额")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ String cny = split[1].replace("CNY", "").replace("\"}", "").replace(",","");
|
|
|
+ double actuallyAmount = Double.parseDouble(cny) / 10000;
|
|
|
+ map.put("jkje",actuallyAmount);
|
|
|
+ }
|
|
|
+ if (b.contains("起息日")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ strTime = split[1].replace("\"}", "").replace("/", "-");
|
|
|
+ }
|
|
|
+ if (b.contains("到期日")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ endTime = split[1].replace("\"}", "").replace("/", "-");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }else if (o.contains("\"words\":\"安徽农金\"")){
|
|
|
+
|
|
|
+ for (int p = 0; p < wordsResult.size(); p++) {
|
|
|
+ String b = wordsResult.get(p).toString();
|
|
|
+ if (b.contains("贷款单位")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ String cny = split[1];
|
|
|
+ map.put("dkdw",cny);
|
|
|
+ }
|
|
|
+ if (b.contains("借款人")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ String cny = split[1];
|
|
|
+ map.put("jkr",cny);
|
|
|
+ }
|
|
|
+ if (b.contains("(小写)")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ String cny = split[1].replace("¥", "").replace("\"}", "").replace(",","");
|
|
|
+ double actuallyAmount = Double.parseDouble(cny) / 10000;
|
|
|
+ map.put("jkje",actuallyAmount);
|
|
|
+ }
|
|
|
+ if (b.contains("借款用途说明")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ String cny = split[1];
|
|
|
+ map.put("jkytsm",cny);
|
|
|
+ }
|
|
|
+ //计算还款时间
|
|
|
+ if (b.contains("借款日期")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ strTime = split[1].replace("\"}", "").replace("年", "-").replace("月", "-").replace("日", "");
|
|
|
+ }
|
|
|
+ if (b.contains("借款到日期")){
|
|
|
+ String[] split = b.split(":");
|
|
|
+ endTime = split[1].replace("\"}", "").replace("年", "-").replace("月", "-").replace("日", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }else if (o.contains("\"words\":\"中国建设银行\"")) {
|
|
|
+ //[{"words":"中国建设银行"},{"words":"China Construction Bank"},{"words":"贷款开户放款复核单"},{"words":"交易日期:"},{"words":"20240808"},{"words":"交易流水号:"},{"words":"102015LN21723106881097611"},{"words":"客户编号:"},{"words":"033811000008657356"},{"words":"产品编码:"},{"words":"00000082"},{"words":"客户名称:"},{"words":"潜山县华达实业有限公司"},{"words":"产品名称:"},{"words":"流动资金贷款"},{"words":"币种名称:人民币"},{"words":"币种代码:156"},{"words":"贷款账号:"},{"words":"34050368430800000726"},{"words":"放款金额:"},{"words":"1000000.00"},{"words":"内部账号:"},{"words":"贷转存账号:"},{"words":"中建设银行股份有限公司"},{"words":"34050168480800000976"},{"words":"利率(%):3.750000"},{"words":"贷款放款日期:20240808"},{"words":"到期日期:"},{"words":"潜山支行"},{"words":"20250807"},{"words":"业务专用章"},{"words":"授权:"},{"words":"复核:"},{"words":"经办:"},{"words":"53596089vM"}]
|
|
|
+ map.put("dkdw","中国建设银行");
|
|
|
+ for (int p = 0; p < wordsResult.size(); p++) {
|
|
|
+ String b = wordsResult.get(p).toString();
|
|
|
+ if (b.contains("客户名称")){
|
|
|
+ String result = wordsResult.get(p+1).toString();
|
|
|
+ String[] split = result.split(":");
|
|
|
+ String cny = split[1];
|
|
|
+ map.put("jkr",cny);
|
|
|
+ }
|
|
|
+ if (b.contains("放款金额")) {
|
|
|
+ String result = wordsResult.get(p+1).toString();
|
|
|
+ String[] split = result.split(":");
|
|
|
+ //"20240808"}
|
|
|
+ String cny = split[1].replace("}", "").replace("\"","");
|
|
|
+ double actuallyAmount = Double.parseDouble(cny) / 10000;
|
|
|
+ map.put("jkje", actuallyAmount);
|
|
|
+ }
|
|
|
+ if (b.contains("产品名称")){
|
|
|
+ String result = wordsResult.get(p+1).toString();
|
|
|
+ String[] split = result.split(":");
|
|
|
+ String cny = split[1];
|
|
|
+ map.put("jkytsm",cny);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(strTime) && StringUtils.isNotEmpty(endTime)){
|
|
|
+ hksj = DateUtils.calculateMonths(strTime,endTime);
|
|
|
+ }
|
|
|
+ if(hksj!=0){
|
|
|
+ map.put("hksj",hksj);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
|
|
|
}
|