|
@@ -23,12 +23,11 @@ import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 文件请求处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
@RestController
|
|
|
-public class SysFileController
|
|
|
-{
|
|
|
+public class SysFileController {
|
|
|
private static final Logger log = LoggerFactory.getLogger(SysFileController.class);
|
|
|
|
|
|
@Autowired
|
|
@@ -38,19 +37,15 @@ public class SysFileController
|
|
|
* 文件上传请求
|
|
|
*/
|
|
|
@PostMapping("upload")
|
|
|
- public R<SysFile> upload(MultipartFile file)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
+ public R<SysFile> upload(MultipartFile file) {
|
|
|
+ try {
|
|
|
// 上传并返回访问地址
|
|
|
String url = sysFileService.uploadFile(file);
|
|
|
SysFile sysFile = new SysFile();
|
|
|
sysFile.setName(FileUtils.getName(url));
|
|
|
sysFile.setUrl(url);
|
|
|
return R.ok(sysFile);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("上传文件失败", e);
|
|
|
return R.fail(e.getMessage());
|
|
|
}
|
|
@@ -74,31 +69,35 @@ public class SysFileController
|
|
|
}
|
|
|
|
|
|
@GetMapping("/getConfigPath")
|
|
|
- public String getConfigPath(){
|
|
|
+ public String getConfigPath() {
|
|
|
return sysFileService.getConfigPath();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* ocr身份证识别,微信接口
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/ocrIdCard")
|
|
|
- public String ocrIdCard(MultipartFile file){
|
|
|
+ public AjaxResult 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
|
|
|
+ String result = "";
|
|
|
try {
|
|
|
String url = sysFileService.uploadFile(file);
|
|
|
- String result = HttpClientUtils.doPost("https://api.weixin.qq.com/cv/ocr/idcard?type=photo&img_url="+url + "&access_token=" + accessToken,null);
|
|
|
- System.out.println(result);
|
|
|
+ result = HttpClientUtils.doPost("https://api.weixin.qq.com/cv/ocr/idcard?type=photo&img_url=" + url + "&access_token=" + accessToken, null);
|
|
|
+ System.out.println("解析身份证返回值:"+result);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return null;
|
|
|
+ return AjaxResult.success(result);
|
|
|
}
|
|
|
- private static String getAccessToken(){
|
|
|
+
|
|
|
+ private static String getAccessToken() {
|
|
|
String accessToken = "";
|
|
|
try {
|
|
|
accessToken = HttpClientUtils.doGet1("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxb9b83f3c86545690&secret=95adc6921a24a3c6cff55f2a1290f6f6");
|