Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
zhangshaowu
/
pipi-helper
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 27140404
authored
Oct 15, 2022
by
zhaolianjie
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
2 parents
e74b9e39
866ea06c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
6 deletions
src/main/java/com/pipihelper/project/feishu/service/FeiShuApiService.java
src/main/java/com/pipihelper/project/feishu/service/massage/MassageMsgCardSerivce.java
src/main/java/com/pipihelper/project/feishu/service/massage/MassageService.java
src/main/java/com/pipihelper/project/utils/GraphicsGenerationUtil.java
src/main/resources/templates/massage-singel-msg-card.json
src/main/java/com/pipihelper/project/feishu/service/FeiShuApiService.java
View file @
2714040
...
@@ -320,6 +320,27 @@ public class FeiShuApiService {
...
@@ -320,6 +320,27 @@ public class FeiShuApiService {
}
}
}
}
//上传图片
public
String
uploadImage
(
String
image_type
,
byte
[]
file
)
{
String
api
=
"/im/v1/images"
;
RestTemplate
restTemplate
=
new
RestTemplate
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"Authorization"
,
"Bearer "
+
getTenantToken
());
headers
.
setContentType
(
org
.
springframework
.
http
.
MediaType
.
MULTIPART_FORM_DATA
);
MultiValueMap
<
String
,
Object
>
param
=
new
LinkedMultiValueMap
<>();
param
.
add
(
"image_type"
,
image_type
);
param
.
add
(
"image"
,
file
);
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
requestEntity
=
new
HttpEntity
<>(
param
,
headers
);
String
url
=
feiShuConfig
.
getFeiShuOpenApiHost
()
+
api
;
try
{
ResponseEntity
<
JSONObject
>
responseEntity
=
restTemplate
.
postForEntity
(
url
,
requestEntity
,
JSONObject
.
class
);
return
responseEntity
.
getBody
().
getJSONObject
(
"data"
).
getString
(
"image_key"
);
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
"飞书:"
+
api
+
"接口调用失败"
+
"\n"
+
e
);
}
}
//获取应用有权限的所有部门
//获取应用有权限的所有部门
public
JSONObject
getDepartment
()
{
public
JSONObject
getDepartment
()
{
String
api
=
"/contact/v3/departments?fetch_child=true"
;
String
api
=
"/contact/v3/departments?fetch_child=true"
;
...
@@ -451,8 +472,9 @@ public class FeiShuApiService {
...
@@ -451,8 +472,9 @@ public class FeiShuApiService {
headers
.
set
(
"Content-Type"
,
"application/json; charset=utf-8"
);
headers
.
set
(
"Content-Type"
,
"application/json; charset=utf-8"
);
HttpEntity
<
String
>
requestEntity
=
new
HttpEntity
<>(
objectMapper
.
writeValueAsString
(
feiShuMsgDTO
),
headers
);
HttpEntity
<
String
>
requestEntity
=
new
HttpEntity
<>(
objectMapper
.
writeValueAsString
(
feiShuMsgDTO
),
headers
);
String
url
=
feiShuConfig
.
getFeiShuOpenApiHost
()
+
api
;
String
url
=
feiShuConfig
.
getFeiShuOpenApiHost
()
+
api
;
log
.
info
(
requestEntity
.
toString
());
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
,
receiveIdType
);
ResponseEntity
<
JSONObject
>
responseEntity
=
restTemplate
.
postForEntity
(
url
,
requestEntity
,
JSONObject
.
class
,
receiveIdType
);
// ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class, receiveIdType);
log
.
info
(
"单发消息成功, req:{}, resp: {}"
,
feiShuMsgDTO
,
responseEntity
);
log
.
info
(
"单发消息成功, req:{}, resp: {}"
,
feiShuMsgDTO
,
responseEntity
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"单发消息失败"
,
e
);
log
.
error
(
"单发消息失败"
,
e
);
...
...
src/main/java/com/pipihelper/project/feishu/service/massage/MassageMsgCardSerivce.java
View file @
2714040
...
@@ -38,7 +38,7 @@ public class MassageMsgCardSerivce {
...
@@ -38,7 +38,7 @@ public class MassageMsgCardSerivce {
pushUser
.
add
(
0
,
title
);
pushUser
.
add
(
0
,
title
);
byte
[]
bufferedImage
=
GraphicsGenerationUtil
.
bufferedImageToByte
(
pushUser
);
byte
[]
bufferedImage
=
GraphicsGenerationUtil
.
bufferedImageToByte
(
pushUser
);
//将图片上传
//将图片上传
String
imgKey
=
feiShuApiService
.
upload
File
(
"stream"
,
"massageEmployee"
,
null
,
bufferedImage
);
String
imgKey
=
feiShuApiService
.
upload
Image
(
"message"
,
bufferedImage
);
String
fileName
=
String
.
format
(
"/templates/massage-msg-card.json"
);
String
fileName
=
String
.
format
(
"/templates/massage-msg-card.json"
);
String
msgCardContent
=
String
.
format
(
getInteractiveCardStr
(
fileName
),
imgKey
);
String
msgCardContent
=
String
.
format
(
getInteractiveCardStr
(
fileName
),
imgKey
);
return
msgCardContent
;
return
msgCardContent
;
...
...
src/main/java/com/pipihelper/project/feishu/service/massage/MassageService.java
View file @
2714040
...
@@ -45,11 +45,13 @@ public class MassageService {
...
@@ -45,11 +45,13 @@ public class MassageService {
pushUser
.
add
(
user
);
pushUser
.
add
(
user
);
}
}
String
content
=
massageMsgCardSerivce
.
genMassageMsgCardForCompany
(
pushUser
);
String
content
=
massageMsgCardSerivce
.
genMassageMsgCardForCompany
(
pushUser
);
log
.
info
(
"给大群发送按摩消息:{}"
,
content
);
FeiShuMsgDTO
feiShuMsgDTO
=
new
FeiShuMsgDTO
();
FeiShuMsgDTO
feiShuMsgDTO
=
new
FeiShuMsgDTO
();
feiShuMsgDTO
.
setMsgType
(
"interactive"
);
feiShuMsgDTO
.
setMsgType
(
"interactive"
);
feiShuMsgDTO
.
setContent
(
content
);
feiShuMsgDTO
.
setContent
(
content
);
feiShuMsgDTO
.
setReceiveId
(
feiShuConfig
.
getChatId
());
feiShuMsgDTO
.
setReceiveId
(
feiShuConfig
.
getChatId
());
feiShuApiService
.
sendMsg
(
feiShuMsgDTO
,
"open_id"
);
log
.
info
(
feiShuMsgDTO
.
toString
());
feiShuApiService
.
sendMsg
(
feiShuMsgDTO
,
"chat_id"
);
}
}
...
...
src/main/java/com/pipihelper/project/utils/GraphicsGenerationUtil.java
View file @
2714040
...
@@ -59,7 +59,7 @@ public class GraphicsGenerationUtil {
...
@@ -59,7 +59,7 @@ public class GraphicsGenerationUtil {
Font
font
=
new
Font
(
"微软雅黑"
,
Font
.
BOLD
,
fontTitileSize
);
Font
font
=
new
Font
(
"微软雅黑"
,
Font
.
BOLD
,
fontTitileSize
);
graphics
.
setFont
(
font
);
graphics
.
setFont
(
font
);
//写标题
//写标题
String
title
=
"【
指标完成进度
】"
;
String
title
=
"【
按摩名单
】"
;
graphics
.
drawString
(
title
,
startWidth
,
startHeight
+
rowheight
-
10
);
graphics
.
drawString
(
title
,
startWidth
,
startHeight
+
rowheight
-
10
);
//写入内容
//写入内容
for
(
int
n
=
0
;
n
<
data
.
size
();
n
++){
for
(
int
n
=
0
;
n
<
data
.
size
();
n
++){
...
...
src/main/resources/templates/massage-singel-msg-card.json
View file @
2714040
...
@@ -43,7 +43,7 @@
...
@@ -43,7 +43,7 @@
},
},
"type"
:
"default"
,
"type"
:
"default"
,
"value"
:
{
"value"
:
{
"key
2
"
:
"massage-singel.wait"
"key
3
"
:
"massage-singel.wait"
}
}
}
}
],
],
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment