Commit 0f5ed36a by 王祖波

合成图片并生成mediaId

parent 5446b449
......@@ -72,7 +72,7 @@ public class ImageCombined {
}
BufferedImage combinedImage = generateImage(largeImage, qrCodeImage, showStyle, lineOne, lineTwo);
ImageIO.write(combinedImage, "jpg", new File(OUTPUT_PATH));
// ImageIO.write(combinedImage, "jpg", new File(OUTPUT_PATH));
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(combinedImage, "jpg", baos);
// 返回字节数组
......@@ -96,6 +96,8 @@ public class ImageCombined {
}
private static BufferedImage generateImage(BufferedImage image, BufferedImage qrCode, int showStyle,String lineOne,String lineTwo) throws Exception {
logger.info("合成图片开始");
int width = image.getWidth();
int height = image.getHeight();
......@@ -134,6 +136,7 @@ public class ImageCombined {
}
g.dispose();
logger.info("合成图片结束");
return combinedImage;
}
......
......@@ -359,6 +359,7 @@ public class MaterialServiceImpl implements MaterialService {
//合成图片
byte[] combinedImageData = ImageCombined.getCombinedImage(combinedQDTO);
if (combinedImageData == null) {
logger.info("合成图片的数据为空");
return jsonResponse;
}
if(imageUrl.contains("?")) {
......
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.JSONResponse;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import com.gic.haoban.manage.service.context.combined.ImageCombined;
import com.gic.haoban.manage.service.service.MaterialService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -20,6 +24,8 @@ public class QWmediaTest {
private QywxSuiteApiService qywxSuiteApiService ;
@Autowired
private WxEnterpriseService wxEnterpriseService;
@Autowired
private MaterialService materialService;
private static final String LARGE_IMAGE_URL = "https://jhdm-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4582434f589b494aa4f27df6e3aa3770.png?imageView2/2/w/1080/h/10800/format/jpg";
private static final String QR_CODE_URL = "https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4ffc77073ca1476fb264bf1be9f11383.png";
......@@ -28,23 +34,14 @@ public class QWmediaTest {
@Test
public void test() throws Exception{
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo("b18ffdc9d0644912865a248859914d80") ;
CombinedQDTO combinedQDTO = new CombinedQDTO();
combinedQDTO.setImageUrl(LARGE_IMAGE_URL);
combinedQDTO.setQrCodeUrl(QR_CODE_URL);
combinedQDTO.setShowStyle(1);
combinedQDTO.setLineOne(STORE_NAME);
combinedQDTO.setLineTwo(GUIDE_NAME);
String[] arr = null ;
byte[] combinedImageData = ImageCombined.getCombinedImage(combinedQDTO);
// 将 BufferedImage 写入 ByteArrayOutputStream
if(LARGE_IMAGE_URL.contains("?")) {
arr = LARGE_IMAGE_URL.split("\\?")[0].split("/") ;
}else {
arr = LARGE_IMAGE_URL.split("/");
}
// JSONResponse test = qywxSuiteApiService.uploadAttachment(qwDTO.getThirdCorpid(), qwDTO.getSelf3thSecret(), combinedImageData, arr[arr.length - 1], QywxMediaTypeEnum.IMAGE.getCode(), qwDTO.isSelf(), qwDTO.getUrlHost());
// System.out.println(JSON.toJSONString(test));
JSONResponse json = materialService.getMaterialIdByCombined("b18ffdc9d0644912865a248859914d80", combinedQDTO);
System.out.println(JSON.toJSONString(json));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment