Commit 6ec47483 by 孙喜旺

修复群活码生成二维码失败问题

1 parent 719831b9
package com.linkwechat.common.utils.file;
import com.alibaba.fastjson.JSONObject;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.utils.OsUtils;
import com.linkwechat.common.utils.spring.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
/**
* 文件服务
*/
@Slf4j
public class FileUtil {
private static RuoYiConfig ruoYiConfig = SpringUtils.getBean(RuoYiConfig.class);
private static final String WINDOWSFILEPATH="D:/linkWeChat/uploadPath";
private static final String LINUXFILEPATH="/linkWeChat/uploadPath";
/**
* 文件上传
* @param file
* @return
* @throws IOException
*/
public static JSONObject upload(MultipartFile file) throws Exception {
try {
FileUploadUtils.assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
String fileName="";
String imgUrlPrefix="";
if(ruoYiConfig.getFile().isStartCosUpload()){//开启云上传
//开启云上传开关则云上传,不然上传本地
fileName = FileUploadUtils.upload2Cos(file, ruoYiConfig.getFile().getCos());
imgUrlPrefix = ruoYiConfig.getFile().getCos().getCosImgUrlPrefix();
}else {//本地上传
File osFile=OsUtils.isWindows()?new File(WINDOWSFILEPATH):new File(LINUXFILEPATH);
if(!osFile.exists()){
osFile.mkdirs();
}
fileName = FileUploadUtils.upload(osFile.getPath(), file);
imgUrlPrefix = ruoYiConfig.getFile().getImgUrlPrefix();
}
JSONObject reust = new JSONObject();
reust.put("fileName",fileName);
reust.put("imgUrlPrefix",imgUrlPrefix);
return reust;
}catch (Exception e){
throw e;
}
}
/**
* 获取图片(本地,或者网络图片)
* @param fileName
* @param rp
*/
public void findImage(String fileName, HttpServletResponse rp){
try {
String fileDownUrl="";
rp.setContentType("image/png");
if(ruoYiConfig.getFile().isStartCosUpload()) {//开启云上传
fileDownUrl= ruoYiConfig.getFile().getCos().getCosImgUrlPrefix();
FileUtils.downloadFile(fileDownUrl+fileName,rp.getOutputStream());
}else{
fileDownUrl=OsUtils.isWindows()?WINDOWSFILEPATH+"/"+fileName:LINUXFILEPATH+"/"+fileName;
FileUtils.writeBytes(fileDownUrl,rp.getOutputStream());
}
}catch (Exception e){
log.error("图片获取异常:"+e.getMessage());
}
}
}
...@@ -16,6 +16,7 @@ import com.linkwechat.common.utils.QREncode; ...@@ -16,6 +16,7 @@ import com.linkwechat.common.utils.QREncode;
import com.linkwechat.common.utils.SecurityUtils; import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils; import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.common.utils.file.FileUtil;
import com.linkwechat.common.utils.img.NetFileUtils; import com.linkwechat.common.utils.img.NetFileUtils;
import com.linkwechat.wecom.client.WeExternalContactClient; import com.linkwechat.wecom.client.WeExternalContactClient;
import com.linkwechat.wecom.domain.*; import com.linkwechat.wecom.domain.*;
...@@ -65,24 +66,18 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W ...@@ -65,24 +66,18 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
@Autowired @Autowired
private IWeTaskFissionRecordService weTaskFissionRecordService; private IWeTaskFissionRecordService weTaskFissionRecordService;
@Autowired @Autowired
private IWeUserService weUserService;
@Autowired
private WeExternalContactClient weExternalContactClient; private WeExternalContactClient weExternalContactClient;
@Autowired @Autowired
private IWePosterService wePosterService; private IWePosterService wePosterService;
@Autowired @Autowired
private IWeGroupCodeService weGroupCodeService; private IWeGroupCodeService weGroupCodeService;
@Autowired @Autowired
private IWeMaterialService weMaterialService;
@Autowired
private IWeCustomerService weCustomerService; private IWeCustomerService weCustomerService;
@Autowired @Autowired
private IWeFlowerCustomerRelService weFlowerCustomerRelService; private IWeFlowerCustomerRelService weFlowerCustomerRelService;
@Autowired @Autowired
private IWeTaskFissionCompleteRecordService weTaskFissionCompleteRecordService; private IWeTaskFissionCompleteRecordService weTaskFissionCompleteRecordService;
@Autowired
private CosConfig cosConfig;
@Value("${H5.fissionUrl}") @Value("${H5.fissionUrl}")
private String pageUrl; private String pageUrl;
@Value("${H5.fissionGroupUrl}") @Value("${H5.fissionGroupUrl}")
...@@ -442,7 +437,6 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W ...@@ -442,7 +437,6 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
} }
private String getGroupFissionQrcode(Long taskFissionId, WeTaskFissionRecord record, WeCustomer weCustomer) { private String getGroupFissionQrcode(Long taskFissionId, WeTaskFissionRecord record, WeCustomer weCustomer) {
String qrCode = null;
if (weCustomer != null) { if (weCustomer != null) {
String avatarUrl = weCustomer.getAvatar(); String avatarUrl = weCustomer.getAvatar();
StringBuilder contentBuilder = new StringBuilder(pageGroupUrl); StringBuilder contentBuilder = new StringBuilder(pageGroupUrl);
...@@ -456,13 +450,14 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W ...@@ -456,13 +450,14 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
ImageIO.write(bufferedImage, "png", byteArrayOutputStream); ImageIO.write(bufferedImage, "png", byteArrayOutputStream);
NetFileUtils.StreamMultipartFile streamMultipartFile = new NetFileUtils.StreamMultipartFile(System.currentTimeMillis() + ".jpg", byteArrayOutputStream.toByteArray()); NetFileUtils.StreamMultipartFile streamMultipartFile = new NetFileUtils.StreamMultipartFile(System.currentTimeMillis() + ".jpg", byteArrayOutputStream.toByteArray());
qrCode = FileUploadUtils.upload2Cos(streamMultipartFile, cosConfig); JSONObject fileInfo = FileUtil.upload(streamMultipartFile);
return fileInfo.getString("imgUrlPrefix");
} catch (Exception e) { } catch (Exception e) {
log.warn("生成海报二维码异常, record={}, customer={}, exception={}", record, weCustomer, ExceptionUtils.getStackTrace(e)); log.warn("生成海报二维码异常, record={}, customer={}, exception={}", JSONObject.toJSONString(record), JSONObject.toJSONString(weCustomer), ExceptionUtils.getStackTrace(e));
throw new WeComException("生成二维码异常"); throw new WeComException("生成二维码异常");
} }
} }
return cosConfig.getCosImgUrlPrefix() + qrCode; throw new WeComException("生成二维码异常");
} else { } else {
throw new WeComException("生成二维码异常,用户信息不存在"); throw new WeComException("生成二维码异常,用户信息不存在");
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!