feat: 二维码文件上传
This commit is contained in:
@@ -119,6 +119,11 @@
|
|||||||
<artifactId>javax.persistence-api</artifactId>
|
<artifactId>javax.persistence-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -35,11 +35,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.wfc.common.core.domain.R;
|
import org.wfc.common.core.domain.R;
|
||||||
import org.wfc.payment.domain.FileBean;
|
import org.wfc.payment.domain.FileBean;
|
||||||
import org.wfc.payment.domain.H5SceneInfo;
|
import org.wfc.payment.domain.H5SceneInfo;
|
||||||
import org.wfc.payment.domain.WxPayBean;
|
import org.wfc.payment.domain.WxPayBean;
|
||||||
import org.wfc.payment.domain.vo.AjaxResult;
|
import org.wfc.payment.domain.vo.AjaxResult;
|
||||||
|
import org.wfc.payment.utils.MultipartFileUtil;
|
||||||
|
import org.wfc.system.api.RemoteFileService;
|
||||||
|
import org.wfc.system.api.domain.SysFile;
|
||||||
import org.wfc.user.api.RemoteUUserService;
|
import org.wfc.user.api.RemoteUUserService;
|
||||||
import org.wfc.user.api.domain.vo.UOrderVo;
|
import org.wfc.user.api.domain.vo.UOrderVo;
|
||||||
|
|
||||||
@@ -73,6 +77,9 @@ public class WxPayController extends AbstractWxPayApiController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RemoteUUserService remoteUUserService;
|
private RemoteUUserService remoteUUserService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteFileService remoteFileService;
|
||||||
|
|
||||||
private String notifyUrl;
|
private String notifyUrl;
|
||||||
private String refundNotifyUrl;
|
private String refundNotifyUrl;
|
||||||
private static final String USER_PAYING = "USERPAYING";
|
private static final String USER_PAYING = "USERPAYING";
|
||||||
@@ -424,12 +431,19 @@ public class WxPayController extends AbstractWxPayApiController {
|
|||||||
String qrCodeUrl = result.get("code_url");
|
String qrCodeUrl = result.get("code_url");
|
||||||
String name = "payQRCode2.png";
|
String name = "payQRCode2.png";
|
||||||
|
|
||||||
String basePath = fileBean.getPath() + File.separator + orderId;
|
String basePath = System.getProperty("user.dir") + File.separator + name;
|
||||||
String url = fileBean.getDomain() + fileBean.getPrefix() + File.separator + orderId + File.separator + name;
|
// String url = fileBean.getDomain() + fileBean.getPrefix() + File.separator + orderId + File.separator + name;
|
||||||
FileUtil.mkdir(basePath);
|
FileUtil.mkdir(basePath);
|
||||||
|
|
||||||
boolean encode = QrCodeKit.encode(qrCodeUrl, BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, "png", 200, 200,
|
boolean encode = QrCodeKit.encode(qrCodeUrl, BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, "png", 200, 200,
|
||||||
basePath + File.separator + name);
|
basePath);
|
||||||
|
File uploadFile = new File(basePath);
|
||||||
|
MultipartFile multipartFile = MultipartFileUtil.getMultipartFile(uploadFile);
|
||||||
|
R<SysFile> fileResult = remoteFileService.upload(multipartFile);
|
||||||
|
String url = fileResult.getData().getLocalUrl();
|
||||||
|
log.info("qr code file: {}", basePath);
|
||||||
|
FileUtil.del(uploadFile);
|
||||||
|
|
||||||
if (encode) {
|
if (encode) {
|
||||||
//在页面上显示
|
//在页面上显示
|
||||||
return new AjaxResult().success(url);
|
return new AjaxResult().success(url);
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package org.wfc.payment.utils;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpResponse;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MultipartFile和File互转工具类
|
||||||
|
*/
|
||||||
|
public class MultipartFileUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输入流转MultipartFile
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* @param inputStream
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static MultipartFile getMultipartFile(String fileName, InputStream inputStream) {
|
||||||
|
MultipartFile multipartFile = null;
|
||||||
|
try {
|
||||||
|
multipartFile = new MockMultipartFile(fileName, fileName,
|
||||||
|
ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return multipartFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取网络文件
|
||||||
|
*
|
||||||
|
* @param url 文件地址
|
||||||
|
* @param fileName 文件名称(需带文件名后缀)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static MultipartFile getMultipartFile(String url, String fileName) {
|
||||||
|
HttpResponse response = HttpRequest.get(url).execute();
|
||||||
|
InputStream inputStream = response.bodyStream();
|
||||||
|
return MultipartFileUtil.getMultipartFile(fileName, inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File 转MultipartFile
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static MultipartFile getMultipartFile(File file) {
|
||||||
|
FileInputStream fileInputStream = null;
|
||||||
|
MultipartFile multipartFile = null;
|
||||||
|
try {
|
||||||
|
fileInputStream = new FileInputStream(file);
|
||||||
|
multipartFile = new MockMultipartFile(file.getName(), file.getName(),
|
||||||
|
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return multipartFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MultipartFileUtil 转File
|
||||||
|
*
|
||||||
|
* @param multipartFile
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static File getFile(MultipartFile multipartFile) {
|
||||||
|
String fileName = multipartFile.getOriginalFilename();
|
||||||
|
File file = new File(fileName);
|
||||||
|
OutputStream out = null;
|
||||||
|
try {
|
||||||
|
out = new FileOutputStream(file);
|
||||||
|
byte[] ss = multipartFile.getBytes();
|
||||||
|
for (byte s : ss) {
|
||||||
|
out.write(s);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (out != null) {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// File f = new File(file.toURI());
|
||||||
|
// if (f.delete()) {
|
||||||
|
// System.out.println("删除成功");
|
||||||
|
// } else {
|
||||||
|
// System.out.println("删除失败");
|
||||||
|
// }
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user