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
54dcbd83
Commit
54dcbd83
authored
Jun 01, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
友盟推送
parent
e3a4b34c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
16 deletions
+90
-16
common/src/main/java/com/wecloud/im/push/PushUtils.java
+53
-15
common/src/main/java/com/wecloud/im/tillo/app_ws/strategy/concrete/ImConcreteReceiveStrategy.java
+37
-1
No files found.
common/src/main/java/com/wecloud/im/push/
Demo
.java
→
common/src/main/java/com/wecloud/im/push/
PushUtils
.java
View file @
54dcbd83
...
@@ -14,14 +14,16 @@ import com.wecloud.im.push.ios.IOSUnicast;
...
@@ -14,14 +14,16 @@ import com.wecloud.im.push.ios.IOSUnicast;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
/**
public
class
Demo
{
* 推送工具类
*/
public
class
PushUtils
{
private
final
String
timestamp
=
null
;
private
final
String
timestamp
=
null
;
private
final
PushClient
client
=
new
PushClient
();
private
final
PushClient
client
=
new
PushClient
();
private
String
appkey
=
null
;
private
String
appkey
=
null
;
private
String
appMasterSecret
=
null
;
private
String
appMasterSecret
=
null
;
public
Demo
(
String
key
,
String
secret
)
{
public
PushUtils
(
String
key
,
String
secret
)
{
try
{
try
{
appkey
=
key
;
appkey
=
key
;
appMasterSecret
=
secret
;
appMasterSecret
=
secret
;
...
@@ -33,10 +35,23 @@ public class Demo {
...
@@ -33,10 +35,23 @@ public class Demo {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
// TODO set your appkey and master secret here
// TODO set your appkey and master secret here
Demo
demo
=
new
Demo
(
"your appkey"
,
"your master secret"
);
PushUtils
demo
=
new
PushUtils
(
"your appkey"
,
"your master secret"
);
try
{
try
{
demo
.
sendAndroidUnicast
();
//demo.sendIOSUnicast();
// 安卓单推
String
deviceToken
=
"your device_token"
;
String
unicastText
=
"Android unicast text"
;
String
unicastTicker
=
"Android unicast ticker"
;
String
title
=
"中文的title"
;
demo
.
sendAndroidUnicast
(
deviceToken
,
unicastText
,
unicastTicker
,
title
);
// ios 单推
String
deviceTokenIOS
=
"your device_token"
;
String
titleIOS
=
"今日天气"
;
String
subtitle
=
""
;
String
body
=
"今日可能下雨🌂"
;
demo
.
sendIOSUnicast
(
deviceTokenIOS
,
titleIOS
,
subtitle
,
body
);
/* TODO these methods are all available, just fill in some fields and do the test
/* TODO these methods are all available, just fill in some fields and do the test
* demo.sendAndroidCustomizedcastFile();
* demo.sendAndroidCustomizedcastFile();
* demo.sendAndroidBroadcast();
* demo.sendAndroidBroadcast();
...
@@ -45,7 +60,6 @@ public class Demo {
...
@@ -45,7 +60,6 @@ public class Demo {
* demo.sendAndroidFilecast();
* demo.sendAndroidFilecast();
*
*
* demo.sendIOSBroadcast();
* demo.sendIOSBroadcast();
* demo.sendIOSUnicast();
* demo.sendIOSGroupcast();
* demo.sendIOSGroupcast();
* demo.sendIOSCustomizedcast();
* demo.sendIOSCustomizedcast();
* demo.sendIOSFilecast();
* demo.sendIOSFilecast();
...
@@ -73,13 +87,25 @@ public class Demo {
...
@@ -73,13 +87,25 @@ public class Demo {
client
.
send
(
broadcast
);
client
.
send
(
broadcast
);
}
}
public
void
sendAndroidUnicast
()
throws
Exception
{
/**
* 安卓单推
*
* @param deviceToken
* @param unicastText
* @param unicastTicker
* @param title
* @throws Exception
*/
public
void
sendAndroidUnicast
(
String
deviceToken
,
String
unicastText
,
String
unicastTicker
,
String
title
)
throws
Exception
{
AndroidUnicast
unicast
=
new
AndroidUnicast
(
appkey
,
appMasterSecret
);
AndroidUnicast
unicast
=
new
AndroidUnicast
(
appkey
,
appMasterSecret
);
// TODO Set your device token
// TODO Set your device token
unicast
.
setDeviceToken
(
"your device_token"
);
unicast
.
setTicker
(
"Android unicast ticker"
);
unicast
.
setTitle
(
"中文的title"
);
unicast
.
setDeviceToken
(
deviceToken
);
unicast
.
setText
(
"Android unicast text"
);
unicast
.
setTicker
(
unicastTicker
);
unicast
.
setTitle
(
title
);
unicast
.
setText
(
unicastText
);
unicast
.
goAppAfterOpen
();
unicast
.
goAppAfterOpen
();
unicast
.
setDisplayType
(
AndroidNotification
.
DisplayType
.
NOTIFICATION
);
unicast
.
setDisplayType
(
AndroidNotification
.
DisplayType
.
NOTIFICATION
);
// TODO Set 'production_mode' to 'false' if it's a test device.
// TODO Set 'production_mode' to 'false' if it's a test device.
...
@@ -205,14 +231,26 @@ public class Demo {
...
@@ -205,14 +231,26 @@ public class Demo {
client
.
send
(
broadcast
);
client
.
send
(
broadcast
);
}
}
public
void
sendIOSUnicast
()
throws
Exception
{
/**
* ios单推
*
* @param deviceToken
* @param title
* @param subtitle
* @param body
* @throws Exception
*/
public
void
sendIOSUnicast
(
String
deviceToken
,
String
title
,
String
subtitle
,
String
body
)
throws
Exception
{
IOSUnicast
unicast
=
new
IOSUnicast
(
appkey
,
appMasterSecret
);
IOSUnicast
unicast
=
new
IOSUnicast
(
appkey
,
appMasterSecret
);
// TODO Set your device token
// TODO Set your device token
unicast
.
setDeviceToken
(
"your device_token"
);
unicast
.
setDeviceToken
(
deviceToken
);
//alert值设置为字符串
//alert值设置为字符串
//unicast.setAlert("IOS 单播测试");
//unicast.setAlert("IOS 单播测试");
//alert的值设置为字典
//alert的值设置为字典
unicast
.
setAlert
(
"今日天气"
,
""
,
"今日可能下雨🌂"
);
unicast
.
setAlert
(
title
,
subtitle
,
body
);
unicast
.
setBadge
(
0
);
unicast
.
setBadge
(
0
);
unicast
.
setSound
(
"default"
);
unicast
.
setSound
(
"default"
);
// TODO set 'production_mode' to 'true' if your app is under production mode
// TODO set 'production_mode' to 'true' if your app is under production mode
...
...
common/src/main/java/com/wecloud/im/tillo/app_ws/strategy/concrete/ImConcreteReceiveStrategy.java
View file @
54dcbd83
package
com
.
wecloud
.
im
.
tillo
.
app_ws
.
strategy
.
concrete
;
package
com
.
wecloud
.
im
.
tillo
.
app_ws
.
strategy
.
concrete
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.json.JsonMapper
;
import
com.fasterxml.jackson.databind.json.JsonMapper
;
...
@@ -8,6 +9,7 @@ import com.wecloud.im.entity.ImConversationMembers;
...
@@ -8,6 +9,7 @@ import com.wecloud.im.entity.ImConversationMembers;
import
com.wecloud.im.entity.ImInbox
;
import
com.wecloud.im.entity.ImInbox
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImMessageOnlineSend
;
import
com.wecloud.im.entity.ImMessageOnlineSend
;
import
com.wecloud.im.push.PushUtils
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.service.ImConversationMembersService
;
...
@@ -128,6 +130,9 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
...
@@ -128,6 +130,9 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
imMessageOnlineSend
.
setContent
(
receiveModel
.
getData
());
imMessageOnlineSend
.
setContent
(
receiveModel
.
getData
());
imMessageOnlineSend
.
setConversationId
(
toConversationId
);
imMessageOnlineSend
.
setConversationId
(
toConversationId
);
// 友盟推送
PushUtils
pushUtils
=
new
PushUtils
(
imApplication
.
getUmengKey
(),
imApplication
.
getUmengSecret
());
// 遍历发送
// 遍历发送
for
(
ImConversationMembers
conversationMembers
:
membersList
)
{
for
(
ImConversationMembers
conversationMembers
:
membersList
)
{
// 排除发送者
// 排除发送者
...
@@ -154,7 +159,6 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
...
@@ -154,7 +159,6 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
return
;
return
;
}
}
// 向接收方推送
// 向接收方推送
ResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
ResponseModel
<>();
ResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
ResponseModel
<>();
responseModel
.
setCmd
(
ResponseModel
.
RES
);
responseModel
.
setCmd
(
ResponseModel
.
RES
);
...
@@ -164,6 +168,38 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
...
@@ -164,6 +168,38 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
responseModel
.
setData
(
imMessageOnlineSend
);
responseModel
.
setData
(
imMessageOnlineSend
);
responseModel
.
setReqId
(
null
);
responseModel
.
setReqId
(
null
);
writeDataService
.
write
(
responseModel
,
appKey
,
imClientReceiver
.
getClientId
());
writeDataService
.
write
(
responseModel
,
appKey
,
imClientReceiver
.
getClientId
());
// 系统推送
// 设备不想收到推送提醒, 1想, 0不想
if
(
imClientReceiver
.
getValid
()
!=
0
&&
imClientReceiver
.
getDeviceToken
()
!=
null
)
{
// 设备类型1:ios; 2:android
if
(
imClientReceiver
.
getDeviceType
()
==
1
)
{
// ios 单推
String
deviceTokenIOS
=
imClientReceiver
.
getDeviceToken
();
String
titleIOS
=
"收到新消息"
;
String
subtitle
=
""
;
String
body
=
"点击查看"
;
try
{
pushUtils
.
sendIOSUnicast
(
deviceTokenIOS
,
titleIOS
,
subtitle
,
body
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
else
{
// 安卓单推
String
deviceToken
=
imClientReceiver
.
getDeviceToken
();
String
unicastText
=
"Android unicast text"
;
String
unicastTicker
=
"点击查看"
;
String
title
=
"收到新消息"
;
try
{
pushUtils
.
sendAndroidUnicast
(
deviceToken
,
unicastText
,
unicastTicker
,
title
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
// 响应发送方消息id等信息
// 响应发送方消息id等信息
...
...
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