|
|
@@ -0,0 +1,69 @@
|
|
|
+package com.ydtech.utils.baidu;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ydtech.modules.order.entity.BusinessLicense;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 营业执照识别
|
|
|
+ * @author: wenks
|
|
|
+ * @date: 2024/2/21 9:46
|
|
|
+ **/
|
|
|
+
|
|
|
+public class BusinessLicenseRecognition {
|
|
|
+
|
|
|
+ private BusinessLicenseRecognition() {
|
|
|
+ throw new IllegalStateException("Utility class");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param imgParam base64影像
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static JSONObject businessLicense(String imgParam) {
|
|
|
+ // 请求url
|
|
|
+ String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license";
|
|
|
+ try {
|
|
|
+ String accessToken = AuthService.getAuth();
|
|
|
+
|
|
|
+ String param = "image=" + imgParam;
|
|
|
+ String result = HttpUtil.post(url, accessToken, param);
|
|
|
+ JSONObject ja = JSON.parseObject(result);
|
|
|
+ String wordsResult = ja.getString("words_result");
|
|
|
+ return JSON.parseObject(wordsResult);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return new JSONObject();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void gettingData(String images, BusinessLicense businessLicense) {
|
|
|
+ if (StringUtils.isEmpty(images)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONObject s = businessLicense(images);
|
|
|
+ businessLicense.setSocialCreditCode(getWords(s, "社会信用代码"));
|
|
|
+ businessLicense.setCompany(getWords(s, "单位名称"));
|
|
|
+ businessLicense.setAddress(getWords(s, "地址"));
|
|
|
+ businessLicense.setLegalRepresentative(getWords(s, "法人"));
|
|
|
+ businessLicense.setEffectiveDate(getWords(s, "有效期"));
|
|
|
+ businessLicense.setRegisterDate(getWords(s, "成立日期"));
|
|
|
+ businessLicense.setTypes(getWords(s, "类型"));
|
|
|
+ businessLicense.setRegisteredCapital(getWords(s, "注册资本"));
|
|
|
+ businessLicense.setRegisteredCapital(getWords(s, "注册资本"));
|
|
|
+ businessLicense.setBusinessScope(getWords(s, "经营范围"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getWords(JSONObject jsonObject, String name) {
|
|
|
+ return JSON.parseObject(jsonObject.getString(name)).getString("words");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|