调用第三方接口、扫描仪授权码

master
hansha 2 years ago
parent 566a31f336
commit fd10f80a54

@ -1,28 +1,10 @@
<p align="center">
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
</p>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi v3.8.7</h1>
<h4 align="center">基于SpringBoot+Vue前后端分离的Java快速开发框架</h4>
<p align="center">
<a href="https://gitee.com/y_project/RuoYi-Vue/stargazers"><img src="https://gitee.com/y_project/RuoYi-Vue/badge/star.svg?theme=dark"></a>
<a href="https://gitee.com/y_project/RuoYi-Vue"><img src="https://img.shields.io/badge/RuoYi-v3.8.7-brightgreen.svg"></a>
<a href="https://gitee.com/y_project/RuoYi-Vue/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
</p>
## 平台简介 ## 平台简介
若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。
* 前端采用Vue、Element UI。 * 前端采用Vue、Element UI。
* 后端采用Spring Boot、Spring Security、Redis & Jwt。 * 后端采用Spring Boot、Spring Security、Redis & Jwt。
* 权限认证使用Jwt支持多终端认证系统。 * 权限认证使用Jwt支持多终端认证系统。
* 支持加载动态权限菜单,多方式轻松权限控制。 * 支持加载动态权限菜单,多方式轻松权限控制。
* 高效率开发,使用代码生成器可以一键生成前后端代码。 * 高效率开发,使用代码生成器可以一键生成前后端代码。
* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Vue3](https://github.com/yangzongzhuan/RuoYi-Vue3),保持同步更新。
* 提供了单应用版本[RuoYi-Vue-fast](https://github.com/yangzongzhuan/RuoYi-Vue-fast)Oracle版本[RuoYi-Vue-Oracle](https://github.com/yangzongzhuan/RuoYi-Vue-Oracle),保持同步更新。
* 不分离版本,请移步[RuoYi](https://gitee.com/y_project/RuoYi),微服务版本,请移步[RuoYi-Cloud](https://gitee.com/y_project/RuoYi-Cloud)
* 阿里云折扣场:[点我进入](http://aly.ruoyi.vip),腾讯云秒杀场:[点我进入](http://txy.ruoyi.vip)&nbsp;&nbsp;
* 阿里云优惠券:[点我领取](https://www.aliyun.com/minisite/goods?userCode=brki8iof&share_source=copy_link),腾讯云优惠券:[点我领取](https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=198c8df2ed259157187173bc7f4f32fd&from=console)&nbsp;&nbsp;
## 内置功能 ## 内置功能
@ -49,4 +31,6 @@
- admin/admin123 - admin/admin123
#影源扫描仪 授权码ND8NSUzCysU1gCr78aj57g== #影源扫描仪 授权码V4tMKPYgFtW8vQr4C0s4/g==
测试临时码D+1WT4eWDqLseG5433yq9w==
#系统中扫描上传 连接打印机的电脑需要安装两个扫描仪驱动M3230.zip、webscan.exe插件 (已上传到项目)

@ -127,3 +127,7 @@ xss:
excludes: /system/notice excludes: /system/notice
# 匹配链接 # 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/* urlPatterns: /system/*,/monitor/*,/tool/*
ocr:
#第三方访问地址
url: http://123.57.142.195:443/upload_api

@ -8,8 +8,10 @@ import com.da.common.utils.file.FileUtils;
import com.da.dangan.domain.DaPicturesRecard; import com.da.dangan.domain.DaPicturesRecard;
import com.da.dangan.service.IDaCzrkdjService; import com.da.dangan.service.IDaCzrkdjService;
import com.da.dangan.service.IDaPicturesRecardService; import com.da.dangan.service.IDaPicturesRecardService;
import com.da.dangan.util.CallThirdInterface;
import com.da.framework.config.ServerConfig; import com.da.framework.config.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -38,14 +40,15 @@ public class DangAnCollectController extends BaseController {
private IDaCzrkdjService daCzrkdjService; private IDaCzrkdjService daCzrkdjService;
private static final String FILE_DELIMETER = ","; private static final String FILE_DELIMETER = ",";
@Value("${ocr.url}")
private String url;
/** /**
* *
*/ */
@PostMapping("/save") @PostMapping("/save")
public AjaxResult save(@RequestPart("file")MultipartFile file, @RequestPart("picRecard")DaPicturesRecard picRecard) public AjaxResult save(@RequestPart("file") MultipartFile file, @RequestPart("picRecard") DaPicturesRecard picRecard) {
{ try {
try
{
// 上传文件路径 // 上传文件路径
String filePath = RuoYiConfig.getUploadPath(); String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称 // 上传并返回新文件名称
@ -57,15 +60,13 @@ public class DangAnCollectController extends BaseController {
picRecard.setCreateBy(getUsername()); picRecard.setCreateBy(getUsername());
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
daPicturesRecardService.insertDaPicturesRecard(picRecard); daPicturesRecardService.insertDaPicturesRecard(picRecard);
ajax.put("data",picRecard); ajax.put("data", picRecard);
/*ajax.put("url", url); /*ajax.put("url", url);
ajax.put("fileName", fileName); ajax.put("fileName", fileName);
ajax.put("newFileName", FileUtils.getName(fileName)); ajax.put("newFileName", FileUtils.getName(fileName));
ajax.put("originalFilename", file.getOriginalFilename());*/ ajax.put("originalFilename", file.getOriginalFilename());*/
return ajax; return ajax;
} } catch (Exception e) {
catch (Exception e)
{
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
} }
@ -74,10 +75,8 @@ public class DangAnCollectController extends BaseController {
* / * /
*/ */
@PostMapping("/saves") @PostMapping("/saves")
public AjaxResult saves(@RequestPart("files")MultipartFile[] files,@RequestPart("picRecard") DaPicturesRecard picRecard) throws Exception public AjaxResult saves(@RequestPart("files") MultipartFile[] files, @RequestPart("picRecard") DaPicturesRecard picRecard) throws Exception {
{ try { //数据存储
try
{ //数据存储
List<DaPicturesRecard> picRecards = new ArrayList<>(); List<DaPicturesRecard> picRecards = new ArrayList<>();
// 上传文件路径 // 上传文件路径
String filePath = RuoYiConfig.getUploadPath(); String filePath = RuoYiConfig.getUploadPath();
@ -85,8 +84,7 @@ public class DangAnCollectController extends BaseController {
List<String> fileNames = new ArrayList<String>(); List<String> fileNames = new ArrayList<String>();
List<String> newFileNames = new ArrayList<String>(); List<String> newFileNames = new ArrayList<String>();
List<String> originalFilenames = new ArrayList<String>(); List<String> originalFilenames = new ArrayList<String>();
for (MultipartFile file : files) for (MultipartFile file : files) {
{
// //
DaPicturesRecard newPicRecard = new DaPicturesRecard(); DaPicturesRecard newPicRecard = new DaPicturesRecard();
@ -95,8 +93,8 @@ public class DangAnCollectController extends BaseController {
String url = serverConfig.getUrl() + fileName; String url = serverConfig.getUrl() + fileName;
// 添加水印 // 添加水印
String updatedFilePath = removePathBeforeSecondSlash(fileName); /*String updatedFilePath = removePathBeforeSecondSlash(fileName);
String watermarkFilePath = addWatermark(filePath + updatedFilePath); String watermarkFilePath = addWatermark(filePath + updatedFilePath);*/
urls.add(url); urls.add(url);
fileNames.add(fileName); fileNames.add(fileName);
@ -118,66 +116,36 @@ public class DangAnCollectController extends BaseController {
ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));*/ ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));*/
ajax.put("data",picRecards); ajax.put("data", picRecards);
return ajax; return ajax;
} } catch (Exception e) {
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
/**
*
*/
@PostMapping("/tests")
public AjaxResult tests(MultipartFile[] files) throws Exception
{
try
{ //数据存储
List<DaPicturesRecard> picRecards = new ArrayList<>();
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
for (MultipartFile file : files)
{
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName;
// 添加水印
String updatedFilePath = removePathBeforeSecondSlash(fileName);
String watermarkFilePath = addWatermark(filePath + updatedFilePath);
}
AjaxResult ajax = AjaxResult.success();
return ajax;
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
} }
/** /**
* * ocr
*/ */
@PostMapping("/recongnize") @PostMapping("/recongnize")
public AjaxResult recognize(@RequestBody DaPicturesRecard[] picRecards){ public AjaxResult recognize(@RequestBody DaPicturesRecard[] picRecards) {
try { try {
//获取所有的文件 //获取所有的文件
List<File> files = new ArrayList<>(); List<File> files = new ArrayList<>();
for (DaPicturesRecard picRecard : picRecards) { for (DaPicturesRecard picRecard : picRecards) {
File file = new File(picRecard.getPicUrl()); String path = getPath(picRecard.getPicUrl());
File file = new File(path);
files.add(file); files.add(file);
} }
// TODO 调用第三方接口识别信息 // TODO 调用第三方接口识别信息
//String result= CallThirdInterface.callThirdInterface1(); //String result= CallThirdInterface.callThirdInterface1();
//String result= CallThirdInterface.callThirdInterface("url",files); String result = CallThirdInterface.callThirdInterface(url, files, "option1");
System.out.println(result);
// TODO 根据业务类型存储识别后的信息 // TODO 根据业务类型存储识别后的信息
//daCzrkdjService.insertDaCzrkdj(); //daCzrkdjService.insertDaCzrkdj();
//修改图片信息记录表为已识别 //修改图片信息记录表为已识别
for(DaPicturesRecard picRecard:picRecards){ for (DaPicturesRecard picRecard : picRecards) {
picRecard.setRecognize("1"); picRecard.setRecognize("1");
daPicturesRecardService.updateDaPicturesRecard(picRecard); daPicturesRecardService.updateDaPicturesRecard(picRecard);
} }
@ -185,17 +153,69 @@ public class DangAnCollectController extends BaseController {
e.printStackTrace(); e.printStackTrace();
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
return AjaxResult.success(); return AjaxResult.success();
} }
/**
*
*/
@PostMapping("/test")
public String test(@RequestParam("files[]") MultipartFile[] files, @RequestParam("fileType") String fileType) throws Exception {
List<File> fileList = new ArrayList<>();
for (MultipartFile multipartFile : files) {
// 使用multipartFile的transferTo方法保存到临时文件
File file = new File(multipartFile.getOriginalFilename());
multipartFile.transferTo(file);
fileList.add(file);
}
String result = CallThirdInterface.callThirdInterface(url, fileList, fileType);
return result;
}
/**
* 访
*
* @param url
* @return
* @throws Exception
*/
@PostMapping("/test2")
public String test(String url) throws Exception {
return CallThirdInterface.callThirdInterface1(url);
}
/**
*
*/
@PostMapping("/test_water")
public AjaxResult tests(MultipartFile[] files) throws Exception {
try { //数据存储
List<DaPicturesRecard> picRecards = new ArrayList<>();
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
for (MultipartFile file : files) {
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName;
// 添加水印
String updatedFilePath = removePathBeforeSecondSlash(fileName);
String watermarkFilePath = addWatermark(filePath + updatedFilePath);
}
AjaxResult ajax = AjaxResult.success();
return ajax;
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
}
/** /**
* *
*
* @param filePath * @param filePath
* @return * @return
*/ */
private String removePathBeforeSecondSlash(String filePath) private String removePathBeforeSecondSlash(String filePath) {
{
int count = 0; int count = 0;
int index = -1; int index = -1;
for (int i = 0; i < filePath.length(); i++) { for (int i = 0; i < filePath.length(); i++) {
@ -212,16 +232,17 @@ public class DangAnCollectController extends BaseController {
} }
return filePath; return filePath;
} }
/** /**
* *
*
* @param filePath * @param filePath
* @return * @return
* @throws IOException * @throws IOException
*/ */
private String addWatermark(String filePath) throws IOException private String addWatermark(String filePath) throws IOException { //获取文件后缀
{ //获取文件后缀
int indexNum = filePath.lastIndexOf("."); int indexNum = filePath.lastIndexOf(".");
String fileExtension = filePath.substring(indexNum+1); String fileExtension = filePath.substring(indexNum + 1);
BufferedImage image = ImageIO.read(new File(filePath)); BufferedImage image = ImageIO.read(new File(filePath));
/*int h = bufferedImage.getHeight(); /*int h = bufferedImage.getHeight();
@ -247,8 +268,8 @@ public class DangAnCollectController extends BaseController {
g2d.rotate(-Math.toRadians(myDegree), (double) image.getWidth() / 2, (double) image.getHeight() / 2); g2d.rotate(-Math.toRadians(myDegree), (double) image.getWidth() / 2, (double) image.getHeight() / 2);
//设置水印位置 //设置水印位置
int x = (image.getWidth() - g2d.getFontMetrics().stringWidth(watermark)) /2; int x = (image.getWidth() - g2d.getFontMetrics().stringWidth(watermark)) / 2;
int y = image.getHeight()/2; int y = image.getHeight() / 2;
g2d.drawString(watermark, x, y); g2d.drawString(watermark, x, y);
// 保存添加水印后的图片,覆盖原始图片 // 保存添加水印后的图片,覆盖原始图片
@ -258,5 +279,11 @@ public class DangAnCollectController extends BaseController {
return filePath; return filePath;
} }
public String getPath(String path) {
String profile = RuoYiConfig.getUploadPath();
int i = path.indexOf("upload");
String filePath = profile + path.substring(i + 6);
return filePath;
}
} }

@ -1,56 +1,71 @@
package com.da.dangan.util; package com.da.dangan.util;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method; import cn.hutool.http.Method;
import java.io.File; import java.io.File;
import java.net.HttpCookie; import java.net.HttpCookie;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* *
*/ */
public class CallThirdInterface { public class CallThirdInterface {
public static String callThirdInterface1(){ public static String callThirdInterface1(String url){
// 1. 创建HttpRequest对象 - 指定好 url 地址 // 定义上传的URL
HttpRequest httpRequest = new HttpRequest("http://localhost/register"); //String url = "http://yourserver.com:8080/upload";
// 2. 设置请求方式默认是GET请求 //添加json
httpRequest.setMethod(Method.POST); /*JSONObject json = new JSONObject();
// 3. 设置请求参数 可通过 form表单方法 设置 可以是文件类型 json.put("username", "1332788xxxxxx");
// form方法有很多重载方法,可以一个一个参数设置也可以将参数封装进一个map集合然后一块儿 json.put("password", "123456.");*/
// File file = new File("C:\\Users\\hssym\\Downloads\\UBQ.png"); //添加请求头,可多个
// httpRequest.form("image",files); HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
// 4. 设置请求头 headers.put("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjA2NjhmYTM5LTE5OWEtNDAyYy1iYjJlLTk1MjI0OWExMTlhOSJ9.S5-6MC6xKHx1bGjuE0g_QR0vGTsAG1E6rmQCqm2GSMIgNNZkYCnZckegYI8UCCxuGkTV_GOFwmcGagG0IccNEw");
// 请求头同样可以逐一设置也可以封装到map中再统一设置 // 定义要上传的文件
// 设置的请求头是否可以覆盖等信息具体请看源码关于重载方法的说明 // File file = new File("/path/to/your/file.txt");
// httpRequest.header("x-c-authorization","yourToken");
// 5. 执行请求得到http响应类
HttpResponse execute = httpRequest.execute();
// 6. 解析这个http响应类可以获取到响应主体、cookie、是否请求成功等信息 // 定义其他要上传的表单参数
boolean ok = execute.isOk(); // 是否请求成功 判断依据为状态码范围在200~299内 Map<String, Object> map = new HashMap<>();//存放参数
System.out.println(ok); map.put("keyword", "王");
List<HttpCookie> cookies = execute.getCookies();// 获取所有cookie map.put("ywTypes", 0);
cookies.forEach(System.out::println); // 如果为空不会遍历的 // 使用Hutool的HttpUtil上传文件
String body = execute.body(); // 获取响应主体
System.out.println(body); String result = HttpUtil.createGet(url)
return body; .addHeaders(headers)
.charset(CharsetUtil.CHARSET_UTF_8)
//.form("file", file) // 文件名称为"file"
.form(map)// 添加其他表单参数
.execute().body() ;
// 输出结果
System.out.println(result);
return result;
} }
public static String callThirdInterface(String url,List<File> files){
public static String callThirdInterface(String url,List<File> files,String fileType){
// 1. 创建HttpRequest对象 - 指定好 url 地址 // 1. 创建HttpRequest对象 - 指定好 url 地址
HttpRequest httpRequest = new HttpRequest(url); HttpRequest httpRequest = new HttpRequest(url);
// 2. 设置请求方式默认是GET请求 // 2. 设置请求方式默认是GET请求
httpRequest.setMethod(Method.POST); httpRequest.setMethod(Method.POST);
// 3. 设置请求参数 可通过 form表单方法 设置 可以是文件类型 // 3. 设置请求参数 可通过 form表单方法 设置 可以是文件类型
// form方法有很多重载方法,可以一个一个参数设置也可以将参数封装进一个map集合然后一块儿 // form方法有很多重载方法,可以一个一个参数设置也可以将参数封装进一个map集合然后一块儿
// File file = new File("C:\\Users\\hssym\\Downloads\\UBQ.png"); // File file = new File("C:\\Users\\hssym\\Downloads\\UBQ.png");
httpRequest.form("image",files);
httpRequest.charset(CharsetUtil.CHARSET_UTF_8);
httpRequest.form("files[]",files.toArray(new File[0]));
httpRequest.form("fileType",fileType);
// 4. 设置请求头 // 4. 设置请求头
// 请求头同样可以逐一设置也可以封装到map中再统一设置 // 请求头同样可以逐一设置也可以封装到map中再统一设置
// 设置的请求头是否可以覆盖等信息具体请看源码关于重载方法的说明 // 设置的请求头,可添加多个
httpRequest.header("x-c-authorization","yourToken"); // httpRequest.header("x-c-authorization","yourToken");
// httpRequest.header("Content-Type", "multipart/form-data;charset=UTF-8");
// 5. 执行请求得到http响应类 // 5. 执行请求得到http响应类
HttpResponse execute = httpRequest.execute(); HttpResponse execute = httpRequest.execute();
@ -60,6 +75,10 @@ public class CallThirdInterface {
List<HttpCookie> cookies = execute.getCookies();// 获取所有cookie List<HttpCookie> cookies = execute.getCookies();// 获取所有cookie
cookies.forEach(System.out::println); // 如果为空不会遍历的 cookies.forEach(System.out::println); // 如果为空不会遍历的
String body = execute.body(); // 获取响应主体 String body = execute.body(); // 获取响应主体
/*byte[] bytes = execute.bodyBytes();
String body = new String (bytes,CharsetUtil.UTF_8);*/
// 输出结果
System.out.println(body); System.out.println(body);
return body; return body;
} }
@ -78,5 +97,4 @@ public class CallThirdInterface {
} }
System.out.println(values); System.out.println(values);
} }
} }

@ -234,7 +234,8 @@ export default {
_this.WebScan = new WebScan({ _this.WebScan = new WebScan({
url:'http://localhost:18989/WebScan', url:'http://localhost:18989/WebScan',
wsUrl:'http://localhost:28989/', wsUrl:'http://localhost:28989/',
licence:'D+1WT4eWDqLseG5433yq9w==' /*licence:'D+1WT4eWDqLseG5433yq9w=='*/
licence:'V4tMKPYgFtW8vQr4C0s4/g=='
}); });
_this.WebScan.initSef('',function (result){ _this.WebScan.initSef('',function (result){

@ -111,7 +111,7 @@
<el-table v-loading="loading" :data="pictureRecardList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="pictureRecardList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="id" align="center" prop="id" /> <el-table-column label="上传时间" align="center" prop="createTime" />
<el-table-column label="图片名称" align="center" prop="picName" /> <el-table-column label="图片名称" align="center" prop="picName" />
<el-table-column label="图片路径" align="center" prop="picUrl" /> <el-table-column label="图片路径" align="center" prop="picUrl" />
<el-table-column label="物理书架ID" align="center" prop="wlsjId" /> <el-table-column label="物理书架ID" align="center" prop="wlsjId" />

Loading…
Cancel
Save