Browse Source

fix 新增ocr接口

Administrator 3 years ago
parent
commit
1a95bc6c2d

+ 0 - 1
boman-modules/boman-file/src/main/java/com/boman/file/controller/SysFileController.java

@@ -71,5 +71,4 @@ public class SysFileController
     public String getConfigPath(){
         return sysFileService.getConfigPath();
     }
-
 }

+ 1 - 1
boman-modules/boman-file/src/main/java/com/boman/file/service/LocalSysFileServiceImpl.java

@@ -18,6 +18,7 @@ import com.boman.file.utils.FileUploadUtils;
 import com.boman.web.core.api.RemoteAttendanceService;
 import com.boman.web.core.api.RemoteObjService;
 import org.apache.commons.lang3.BooleanUtils;
+import org.apache.http.impl.client.HttpClients;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
@@ -25,7 +26,6 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
-
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;

+ 38 - 0
boman-wechat/src/main/java/com/boman/wechat/controller/AppletLoginController.java

@@ -1,16 +1,23 @@
 package com.boman.wechat.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.boman.common.security.service.TokenService;
 import com.boman.domain.AppletLoginForm;
 import com.boman.domain.dto.AppletSessionDTO;
 import com.boman.domain.dto.R;
+import com.boman.wechat.utils.HttpClientUtils;
 import com.boman.wechat.utils.WxCodeSessionUtil;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -32,4 +39,35 @@ public class AppletLoginController {
         return tokenService.appletLogin(dto.getPhoneNumber());
     }
 
+    /**
+     * ocr身份证识别,微信接口
+     * @return
+     */
+    @PostMapping("/ocrIdCard")
+    public String ocrIdCard(MultipartFile file){
+        String accessTokenResult = getAccessToken();
+        JSONObject jsonObject = JSONObject.parseObject(accessTokenResult);
+        String accessToken = jsonObject.getString("access_token");
+        //https://api.weixin.qq.com/cv/ocr/idcard?type=MODE&img_url=ENCODE_URL&access_token=ACCESS_TOCKEN
+        Map<String,String> map = new HashMap<>();
+        try {
+            String encode = URLEncoder.encode("http://118.178.139.79:5002/statics/2021/09/15/1631688213171.jpeg", "utf-8");
+            map.put("img_url",encode);
+            map.put("access_token",accessToken);
+            String s = HttpClientUtils.doPost("https://api.weixin.qq.com/cv/ocr/idcard?type=MODE&", map);
+            System.out.println(s);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+    private String getAccessToken(){
+        String accessToken = "";
+        try {
+            accessToken = HttpClientUtils.doGet1("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxb9b83f3c86545690&secret=95adc6921a24a3c6cff55f2a1290f6f6");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return accessToken;
+    }
 }