Commit 0a0245a8 by 王祖波

发送朋友圈图片优化

parent ee3d4f0b
......@@ -3,9 +3,12 @@ package com.gic.haoban.manage.service.service.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.HttpClient;
import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
......@@ -220,17 +223,23 @@ public class MaterialServiceImpl implements MaterialService {
if(url.contains("?")) {
logger.info("url有参数={}",url);
url = url.split("\\?")[0] ;
url+= "?imageView2/2/w/1440/h/1080" ;
}else {
}
String key = "haoban:material:" + url;
String cache = (String)RedisUtil.getCache(key);
Map<String, Object> map = null;
if (StringUtils.isBlank(cache)) {
String imageInfoUrl = url + "?imageInfo";
Map<String, Object> map = HttpClient.getHttpByGet(imageInfoUrl);
String width = (String)map.get("width");
String height = (String)map.get("height");
String size = (String)map.get("size");
//图片宽高超过限制 或 大小大于1m 处理图片
if (Integer.parseInt(size) / 1000 > 1000 || Integer.parseInt(width) > 1440 || Integer.parseInt(height) > 1080) {
url+= "?imageView2/2/w/1440/h/1080" ;
}
map = HttpClient.getHttpByGet(imageInfoUrl);
RedisUtil.setCache(key, TimeUnit.DAYS, 1L);
}else {
map = JSONObject.parseObject(cache, Map.class);
}
String width = (String)map.get("width");
String height = (String)map.get("height");
String size = (String)map.get("size");
//图片宽高超过限制 或 大小大于1m 处理图片
if (Integer.parseInt(size) / 1000 > 1000 || Integer.parseInt(width) > 1440 || Integer.parseInt(height) > 1080) {
url+= "?imageView2/2/w/1440/h/1080" ;
}
logger.info("url={}",url);
}
......
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