|
@@ -27,6 +27,7 @@ import com.ruoyi.common.core.domain.SysUserIdcardVo;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import okhttp3.*;
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
@@ -793,24 +794,142 @@ public class IdCardUtil {
|
|
|
* @param filePath 本地文件路径
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String accurateBasic(String filePath) {
|
|
|
- // 请求url
|
|
|
- String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic";
|
|
|
+ public static JSONObject accurateBasic(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 {
|
|
|
- byte[] imgData = FileUtil.readFileByBytes(filePath);
|
|
|
- String imgStr = Base64Util.encodeBase64(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);
|
|
|
- System.out.println(result);
|
|
|
- return result;
|
|
|
- } catch (Exception e) {
|
|
|
+ //{
|
|
|
+ // "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);
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+ System.out.println(response.body().string());
|
|
|
+ return null;
|
|
|
+ } catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
|
|
|
}
|