Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
1e87f977
Commit
1e87f977
authored
Nov 15, 2023
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
发送朋友圈图片优化
parent
0a0245a8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
9 deletions
+22
-9
MaterialServiceImpl.java
...oban/manage/service/service/impl/MaterialServiceImpl.java
+22
-9
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/impl/MaterialServiceImpl.java
View file @
1e87f977
...
...
@@ -6,6 +6,7 @@ import java.util.*;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.gic.commons.util.HttpClient
;
import
com.gic.redis.data.util.RedisUtil
;
...
...
@@ -226,19 +227,24 @@ public class MaterialServiceImpl implements MaterialService {
}
String
key
=
"haoban:material:"
+
url
;
String
cache
=
(
String
)
RedisUtil
.
getCache
(
key
);
Map
<
String
,
Object
>
map
=
null
;
JSONObject
jsonObject
=
null
;
if
(
StringUtils
.
isBlank
(
cache
))
{
String
imageInfoUrl
=
url
+
"?imageInfo"
;
map
=
HttpClient
.
getHttpByGet
(
imageInfoUrl
);
RedisUtil
.
setCache
(
key
,
TimeUnit
.
DAYS
,
1L
);
Map
<
String
,
Object
>
map
=
HttpClient
.
getHttpByGet
(
imageInfoUrl
);
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
{
map
=
JSONObject
.
parseObject
(
cache
,
Map
.
class
);
jsonObject
=
JSONObject
.
parseObject
(
cache
);
}
String
width
=
(
String
)
map
.
get
(
"width"
);
String
height
=
(
String
)
map
.
get
(
"height"
);
String
size
=
(
String
)
map
.
get
(
"size"
);
//图片宽高超过限制 或 大小大于
1
m 处理图片
if
(
Integer
.
parseInt
(
size
)
/
1000
>
1000
||
Integer
.
parseInt
(
width
)
>
1440
||
Integer
.
parseInt
(
height
)
>
1080
)
{
Integer
width
=
jsonObject
.
getInteger
(
"width"
);
Integer
height
=
jsonObject
.
getInteger
(
"height"
);
Integer
size
=
jsonObject
.
getInteger
(
"size"
);
//图片宽高超过限制 或 大小大于
2
m 处理图片
if
(
size
/
1000
>
2000
||
width
>
1440
||
height
>
1080
)
{
url
+=
"?imageView2/2/w/1440/h/1080"
;
}
logger
.
info
(
"url={}"
,
url
);
...
...
@@ -263,6 +269,13 @@ public class MaterialServiceImpl implements MaterialService {
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
)
{
List
<
String
>
materialIdList
=
new
ArrayList
<>();
imageList
.
forEach
(
dto
->
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment