|
@@ -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;
|
|
|
+ }
|
|
|
}
|