Commit 1e87f977 by 王祖波

发送朋友圈图片优化

parent 0a0245a8
...@@ -6,6 +6,7 @@ import java.util.*; ...@@ -6,6 +6,7 @@ import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.HttpClient; import com.gic.commons.util.HttpClient;
import com.gic.redis.data.util.RedisUtil; import com.gic.redis.data.util.RedisUtil;
...@@ -226,19 +227,24 @@ public class MaterialServiceImpl implements MaterialService { ...@@ -226,19 +227,24 @@ public class MaterialServiceImpl implements MaterialService {
} }
String key = "haoban:material:" + url; String key = "haoban:material:" + url;
String cache = (String)RedisUtil.getCache(key); String cache = (String)RedisUtil.getCache(key);
Map<String, Object> map = null; JSONObject jsonObject = null;
if (StringUtils.isBlank(cache)) { if (StringUtils.isBlank(cache)) {
String imageInfoUrl = url + "?imageInfo"; String imageInfoUrl = url + "?imageInfo";
map = HttpClient.getHttpByGet(imageInfoUrl); Map<String, Object> map = HttpClient.getHttpByGet(imageInfoUrl);
RedisUtil.setCache(key, TimeUnit.DAYS, 1L); String response = (String) map.get("response");
if (StringUtils.isBlank(response)) {
throw new RuntimeException();
}
jsonObject = JSONObject.parseObject(response);
RedisUtil.setCache(key, response, 1L, TimeUnit.DAYS);
}else { }else {
map = JSONObject.parseObject(cache, Map.class); jsonObject = JSONObject.parseObject(cache);
} }
String width = (String)map.get("width"); Integer width = jsonObject.getInteger("width");
String height = (String)map.get("height"); Integer height = jsonObject.getInteger("height");
String size = (String)map.get("size"); Integer size = jsonObject.getInteger("size");
//图片宽高超过限制 或 大小大于1m 处理图片 //图片宽高超过限制 或 大小大于2m 处理图片
if (Integer.parseInt(size) / 1000 > 1000 || Integer.parseInt(width) > 1440 || Integer.parseInt(height) > 1080) { if (size / 1000 > 2000 || width > 1440 || height > 1080) {
url+= "?imageView2/2/w/1440/h/1080" ; url+= "?imageView2/2/w/1440/h/1080" ;
} }
logger.info("url={}",url); logger.info("url={}",url);
...@@ -263,6 +269,13 @@ public class MaterialServiceImpl implements MaterialService { ...@@ -263,6 +269,13 @@ public class MaterialServiceImpl implements MaterialService {
return jp; return jp;
} }
public static void main(String[] args) {
String imageInfoUrl = "https://platform-1251519181.cos.ap-shanghai.myqcloud.com/image/jhdm/common-fbcae3533d414bf8baac917df600b20e.png?imageInfo";
Map<String, Object> httpByGet = HttpClient.getHttpByGet(imageInfoUrl);
Object response = httpByGet.get("response");
System.out.println(JSON.toJSONString(httpByGet));
}
public List<String> getImageMediaId(String wxEnterpriseId, List<ContentMaterialDTO> imageList, int mediaType) { public List<String> getImageMediaId(String wxEnterpriseId, List<ContentMaterialDTO> imageList, int mediaType) {
List<String> materialIdList = new ArrayList<>(); List<String> materialIdList = new ArrayList<>();
imageList.forEach(dto -> { imageList.forEach(dto -> {
......
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