Selaa lähdekoodia

手写识别接口更换为百度,人脸对比接口更换为聚合

gaoxinguang 2 vuotta sitten
vanhempi
commit
1e5c1f293c

+ 6 - 0
eladmin-system/pom.xml

@@ -207,6 +207,12 @@
 			<artifactId>openhtmltopdf-pdfbox</artifactId>
 			<version>1.0.6</version>
 		</dependency>
+
+		<dependency>
+			<groupId>commons-httpclient</groupId>
+			<artifactId>commons-httpclient</artifactId>
+			<version>3.1</version>
+		</dependency>
 	</dependencies>
 
 	<!-- 打包 -->

+ 15 - 1
eladmin-system/src/main/java/me/zhengjie/application/bank/controller/BankAuthController.java

@@ -15,6 +15,7 @@ import me.zhengjie.application.bank.service.BankLoginService;
 import me.zhengjie.application.bank.service.FileInfoService;
 import me.zhengjie.base.ResponseDTO;
 import me.zhengjie.base.ResultCode;
+import me.zhengjie.base.util.BaiduServiceUtil;
 import me.zhengjie.base.util.FileUploadUtil;
 import me.zhengjie.base.util.StatusEnum.StepStatusEnum;
 import me.zhengjie.base.util.TencentServiceUtil;
@@ -22,6 +23,8 @@ import me.zhengjie.dao.mybatis.UserAXQInfoRepository;
 import me.zhengjie.dao.mybatis.entity.UserAXQInfoEntity;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -45,6 +48,10 @@ import java.util.List;
 @RequiredArgsConstructor
 @Api(tags = "客户经理APP: 认证模块")
 public class BankAuthController extends BaseController {
+
+    @Autowired
+    private Environment environment;
+
     private final BankLoginService bankLoginService;
     private final FileInfoService fileInfoService;
     private final UserAXQInfoRepository userAXQInfoRepository;
@@ -127,7 +134,14 @@ public class BankAuthController extends BaseController {
         }
 
         if ("4".equals(image.getStep())) {
-            String ocrName = TencentServiceUtil.getHandwritingText(image.getBase64());
+            String ocrName = "";
+            String type = environment.getProperty("fqgz.bank.handwriting");
+            if ("baidu".equals(type)) {
+                ocrName = BaiduServiceUtil.handwriting(image.getBase64());
+            }
+            if ("tencent".equals(type)) {
+                ocrName = TencentServiceUtil.getHandwritingText(image.getBase64());
+            }
             UserAXQInfoEntity entity = userAXQInfoRepository.getUserAXQInfoWithIdcard(image.getIdCard());
             if (!ocrName.equals(entity.getUserName())) {
                 return ResponseDTO.error(ResultCode.HANDWRITING_FAIL);

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 42 - 0
eladmin-system/src/main/java/me/zhengjie/base/util/BaiduServiceUtil.java


+ 118 - 0
eladmin-system/src/main/java/me/zhengjie/base/util/JuheServiceUtil.java

@@ -0,0 +1,118 @@
+package me.zhengjie.base.util;
+
+import com.uinid.util.HttpRequestUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JuheServiceUtil {
+    private static final Logger logger = LoggerFactory.getLogger(HttpRequestUtil.class);
+
+    public static final String UTF8 = "UTF-8";
+    private static final String EMPTY = "";
+    private static final String JuHeURl = "http://apis.juhe.cn/verifyface/verify";
+
+    private static MultiThreadedHttpConnectionManager connectionManager = null;
+
+    private static int connectionTimeOut = 5000;
+
+    private static int socketTimeOut = 5000;
+
+    private static int maxConnectionPerHost = 500;
+
+    private static int maxTotalConnections = 500;
+
+    private static HttpClient client;
+
+    static {
+        connectionManager = new MultiThreadedHttpConnectionManager();
+        connectionManager.getParams().setConnectionTimeout(connectionTimeOut);
+        connectionManager.getParams().setSoTimeout(socketTimeOut);
+        connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnectionPerHost);
+        connectionManager.getParams().setMaxTotalConnections(maxTotalConnections);
+        client = new HttpClient(connectionManager);
+    }
+
+    /**
+     * 聚合人脸比对接口
+     *
+     * @param url    请求地址
+     * @param params 业务参数
+     * @return String response
+     */
+    public static String URLPost(String url, Map<String, Object> params) {
+        String response = EMPTY;
+        PostMethod postMethod = null;
+        try {
+            postMethod = new PostMethod(url);
+            // 将表单的值放入postMethod中
+            if (params != null) {
+                Set<String> keySet = params.keySet();
+                for (String key : keySet) {
+                    Object value = params.get(key);
+                    postMethod.addParameter(key, String.valueOf(value));
+                }
+            }
+            postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, UTF8);
+            // 执行postMethod
+            int statusCode = client.executeMethod(postMethod);
+            if (statusCode == HttpStatus.SC_OK) {
+                response = postMethod.getResponseBodyAsString();
+            } else {
+                logger.error("响应状态码=" + postMethod.getStatusCode());
+            }
+        } catch (HttpException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (postMethod != null) {
+                postMethod.releaseConnection();
+                postMethod = null;
+            }
+        }
+        return response;
+    }
+
+    public static void main(String[] args) throws Exception {
+        String imgFile = "";// 图片地址
+        File file = new File(imgFile);
+        String realName = "xxx";// 姓名
+        String idCard = "xxxxxxxxxxxxxxxx";// 身份证号
+        FileInputStream fin = null;
+        try {
+            fin = new FileInputStream(file);
+            byte[] bytes = new byte[fin.available()];
+            fin.read(bytes);
+            String base64 = Base64.getEncoder().encodeToString(bytes);
+            System.out.println("=====base64" + base64);
+            Map<String, Object> params = new HashMap<>();
+            params.put("idcard", idCard);
+            params.put("realname", realName);
+            params.put("image", base64);
+            params.put("key", "6db21a71bee88af1eac38480c1574e2a");
+            String data = JuheServiceUtil.URLPost(JuHeURl, params);
+            System.out.println(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (fin != null) {
+                fin.close();
+            }
+        }
+    }
+}

+ 3 - 1
eladmin-system/src/main/resources/config/application.yml

@@ -59,6 +59,7 @@ fqgz:
   bank:
     app:
       url-prefix: /api/bank-app
+    handwriting: baidu
   user:
     app:
       url-prefix: /api/user-app
@@ -71,4 +72,5 @@ fqgz:
 html2Pdf:
   simsumPath: font/simsun.ttf
   simfangPath: font/simfang.ttf
-  toolName: OpenPDF
+  toolName: OpenPDF
+