Commit 9d6d8d39 by YaoYuHang Committed by Hang

补交缺失文件

1 parent 6cf9a8f4
...@@ -19,6 +19,8 @@ import com.google.zxing.common.BitMatrix; ...@@ -19,6 +19,8 @@ import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.linkwechat.common.constant.Constants; import com.linkwechat.common.constant.Constants;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
public class QREncode { public class QREncode {
...@@ -186,6 +188,15 @@ public class QREncode { ...@@ -186,6 +188,15 @@ public class QREncode {
} }
} }
public static MultipartFile getQRCodeMultipartFile(String content, String logoUrl) throws IOException {
BufferedImage bufferedImage = crateQRCode(content, logoUrl);
//读取图片转换为 BufferedImage
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bufferedImage, "jpg", baos );
//转换为MultipartFile
return new MockMultipartFile("groupQrCode","groupQrCode.jpg","text/plain", baos.toByteArray());
}
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String text = "http://open.weixin.qq.com/qr/code/?username=LinkWeChat2021"; String text = "http://open.weixin.qq.com/qr/code/?username=LinkWeChat2021";
......
package com.linkwechat.common.utils.file; package com.linkwechat.common.utils.file;
import com.linkwechat.common.utils.StringUtils;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -75,6 +79,40 @@ public class FileUtils extends org.apache.commons.io.FileUtils ...@@ -75,6 +79,40 @@ public class FileUtils extends org.apache.commons.io.FileUtils
} }
/** /**
* 批量下载文件,打包为zip。
* @param fileList 文件列表,每个元素应包含fileName、url,前者即为文件名,后者为下载所需链接
* @param os 输出流
*/
public static void batchDownloadFile(List<Map<String, String>> fileList, OutputStream os) {
try {
ZipOutputStream zos = new ZipOutputStream(os);
for (Map<String, String> fileInfo: fileList) {
String fileName = fileInfo.get("fileName");
String url = fileInfo.get("url");
// 跳过不包含指定键位的对象
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(fileName)){
continue;
}
URL _url = new URL(url);
zos.putNextEntry(new ZipEntry(fileName));
InputStream fis = _url.openConnection().getInputStream();
byte[] buffer = new byte[1024];
int r = 0;
while ((r = fis.read(buffer)) != -1) {
zos.write(buffer, 0, r);
}
fis.close();
}
//关闭zip输出流
zos.flush();
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* *
* @param urlPath 下载路径 * @param urlPath 下载路径
* @param os 输出流 * @param os 输出流
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!