Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
909d90d9
Commit
909d90d9
authored
Jan 12, 2022
by
hweeeeeei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化:允许客户端自定义系统推送内容,消息model-push中添加"data"参数为自定义数据,可以为json或字符串
parent
82f96153
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
8 deletions
+27
-8
common/src/main/java/com/wecloud/im/ws/model/request/PushModel.java
+2
-1
common/src/main/java/com/wecloud/im/ws/sender/PushTask.java
+25
-7
No files found.
common/src/main/java/com/wecloud/im/ws/model/request/PushModel.java
View file @
909d90d9
...
...
@@ -3,6 +3,7 @@ package com.wecloud.im.ws.model.request;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.HashMap
;
/**
* @Description 推送model
...
...
@@ -25,7 +26,7 @@ public class PushModel implements Serializable {
/**
* 自定义系统推送内容
*/
private
String
data
;
private
HashMap
data
;
}
common/src/main/java/com/wecloud/im/ws/sender/PushTask.java
View file @
909d90d9
package
com
.
wecloud
.
im
.
ws
.
sender
;
import
cn.hutool.core.codec.Base64
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.json.JsonMapper
;
import
com.turo.pushy.apns.DeliveryPriority
;
import
com.turo.pushy.apns.PushType
;
import
com.wecloud.im.entity.ImApplication
;
...
...
@@ -32,6 +34,7 @@ import java.util.Map;
@Component
@Slf4j
public
class
PushTask
{
private
static
final
JsonMapper
JSON_MAPPER
=
new
JsonMapper
();
@Autowired
private
ImIosApnsService
imIosApnsService
;
...
...
@@ -73,6 +76,7 @@ public class PushTask {
pushModel
=
new
PushModel
();
pushModel
.
setTitle
(
PUSH_TITLE
);
pushModel
.
setSubTitle
(
PUSH_BODY
);
pushModel
.
setData
(
new
HashMap
<>(
1
));
}
// 校验参数
...
...
@@ -105,19 +109,33 @@ public class PushTask {
public
void
push
(
HashMap
<
String
,
String
>
pushMap
,
ImClient
imClientReceiver
,
ImApplication
imApplication
)
{
log
.
info
(
"push:"
+
imClientReceiver
.
getClientId
());
PushModel
pushModel
=
new
PushModel
();
PushModel
pushModel
=
getPushModel
(
pushMap
);
this
.
push
(
pushModel
,
imClientReceiver
,
imApplication
);
}
private
PushModel
getPushModel
(
HashMap
<
String
,
String
>
pushMap
)
{
PushModel
pushModel
=
new
PushModel
();
if
(
pushMap
==
null
||
pushMap
.
isEmpty
())
{
pushModel
.
setTitle
(
PUSH_TITLE
);
pushModel
.
setSubTitle
(
PUSH_BODY
);
pushModel
.
setData
(
new
HashMap
<>(
1
));
}
else
{
pushModel
.
setTitle
(
pushMap
.
get
(
title
));
pushModel
.
setSubTitle
(
pushMap
.
get
(
subTitle
));
pushModel
.
setData
(
pushMap
.
get
(
DATA
));
}
this
.
push
(
pushModel
,
imClientReceiver
,
imApplication
);
// 自定义推送内容
try
{
HashMap
hashMap
=
JSON_MAPPER
.
readValue
(
pushMap
.
get
(
DATA
),
HashMap
.
class
);
pushModel
.
setData
(
hashMap
);
}
catch
(
JsonProcessingException
e
)
{
log
.
error
(
"pushModel.setData(hashMap)"
,
e
);
pushModel
.
setData
(
new
HashMap
<>(
1
));
}
}
return
pushModel
;
}
private
void
android
(
PushModel
pushModel
,
ImClient
imClientReceiver
,
ImApplication
imApplication
)
{
...
...
@@ -221,9 +239,9 @@ public class PushTask {
info
.
put
(
"body"
,
pushModel
.
getSubTitle
());
// 自定义推送字段
Map
<
String
,
String
>
dataMap
=
new
HashMap
<>();
dataMap
.
put
(
"data"
,
pushModel
.
getData
());
json
.
put
(
"data"
,
dataMap
);
//
Map<String, String> dataMap = new HashMap<>();
// dataMap.put("data", JSON_MAPPER.writeValueAsString
());
json
.
put
(
"data"
,
pushModel
.
getData
()
);
//数据消息data 通知消息 notification
json
.
put
(
"notification"
,
info
);
...
...
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