BroadCastService.java
11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package com.glsx.modules.notify.push;
import com.glsx.modules.notify.model.BaseRequest;
import com.glsx.modules.notify.push.android.AndroidCustomizedcast;
import com.glsx.plat.core.web.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class BroadCastService {
@Autowired
private PushClient client;
public R sendAndroidCustomizedcast(BaseRequest baseRequest) throws Exception {
AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(baseRequest.getAppKey(), baseRequest.getAppMasterSecret());
// TODO Set your alias here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification.
//addAlias("你与后台商定的用来区分用户的不能相同的", "可以是写死的别名项目名随意"
customizedcast.setAlias(baseRequest.getAlias(), baseRequest.getAliasType());
//通知栏提示文字
customizedcast.setTicker(baseRequest.getTitle());
//通知标题
customizedcast.setTitle(baseRequest.getTitle());
//通知文字描述
customizedcast.setText(baseRequest.getBody());
//通知跳转,如果activity为空,默认跳转应用,否则跳转指定activity
String activity = baseRequest.getActivity();
if (StringUtils.isEmpty(activity))
customizedcast.goAppAfterOpen();
else{
customizedcast.goActivityAfterOpen(activity);
//todo 厂商通道相关参数
customizedcast.setChannelActivity(activity);
//customizedcast.setChannelProperties("abc");
}
customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
if (baseRequest.getTestMode().equals("DEV"))
customizedcast.setTestMode();
else
customizedcast.setProductionMode();
return client.send(customizedcast);
}
/*public void sendAndroidBroadcast() throws Exception {
AndroidBroadcast broadcast = new AndroidBroadcast(appkey, appMasterSecret);
broadcast.setTicker("Android broadcast ticker");
broadcast.setTitle("中文的title");
broadcast.setText("Android broadcast text");
broadcast.goAppAfterOpen();
broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
broadcast.setProductionMode();
// Set customized fields
broadcast.setExtraField("test", "helloworld");
//厂商通道相关参数
broadcast.setChannelActivity("your channel activity");
broadcast.setChannelProperties("abc");
client.send(broadcast);
}
public void sendAndroidUnicast() throws Exception {
AndroidUnicast unicast = new AndroidUnicast(appkey, appMasterSecret);
// TODO Set your device token
unicast.setDeviceToken("your device_token");
unicast.setTicker("Android unicast ticker");
unicast.setTitle("中文的title");
unicast.setText("Android unicast text");
unicast.goAppAfterOpen();
unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
unicast.setProductionMode();
// Set customized fields
unicast.setExtraField("test", "helloworld");
unicast.setChannelActivity("your channel activity");
unicast.setChannelProperties("abc");
client.send(unicast);
}
public void sendAndroidGroupcast() throws Exception {
AndroidGroupcast groupcast = new AndroidGroupcast(appkey, appMasterSecret);
*//* TODO
* Construct the filter condition:
* "where":
* {
* "and":
* [
* {"tag":"test"},
* {"tag":"Test"}
* ]
* }
*//*
JSONObject filterJson = new JSONObject();
JSONObject whereJson = new JSONObject();
JSONArray tagArray = new JSONArray();
JSONObject testTag = new JSONObject();
JSONObject TestTag = new JSONObject();
testTag.put("tag", "test");
TestTag.put("tag", "Test");
tagArray.add(testTag);
tagArray.add(TestTag);
whereJson.put("and", tagArray);
filterJson.put("where", whereJson);
groupcast.setFilter(filterJson);
groupcast.setTicker("Android groupcast ticker");
groupcast.setTitle("中文的title");
groupcast.setText("Android groupcast text");
groupcast.goAppAfterOpen();
groupcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
groupcast.setChannelActivity("your channel activity");
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
groupcast.setProductionMode();
//厂商通道相关参数
groupcast.setChannelActivity("your channel activity");
groupcast.setChannelProperties("abc");
client.send(groupcast);
}*/
//public void sendAndroidCustomizedcastFile() throws Exception {
// AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret);
// // TODO Set your alias here, and use comma to split them if there are multiple alias.
// // And if you have many alias, you can also upload a file containing these alias, then
// // use file_id to send customized notification.
// String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb"+"\n"+"alias");
// customizedcast.setFileId(fileId, "alias_type");
// customizedcast.setTicker( "Android customizedcast ticker");
// customizedcast.setTitle( "中文的title");
// customizedcast.setText( "Android customizedcast text");
// customizedcast.goAppAfterOpen();
// customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// // TODO Set 'production_mode' to 'false' if it's a test device.
// // For how to register a test device, please see the developer doc.
// customizedcast.setProductionMode();
// //厂商通道相关参数
// customizedcast.setChannelActivity("your channel activity");
// customizedcast.setChannelProperties("abc");
// client.send(customizedcast);
//}
//
//public void sendAndroidFilecast() throws Exception {
// AndroidFilecast filecast = new AndroidFilecast(appkey,appMasterSecret);
// // TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
// String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb");
// filecast.setFileId( fileId);
// filecast.setTicker( "Android filecast ticker");
// filecast.setTitle( "中文的title");
// filecast.setText( "Android filecast text");
// filecast.goAppAfterOpen();
// filecast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// //厂商通道相关参数
// filecast.setChannelActivity("your channel activity");
// filecast.setChannelProperties("abc");
// client.send(filecast);
//}
/*public void sendIOSBroadcast() throws Exception {
IOSBroadcast broadcast = new IOSBroadcast(appkey, appMasterSecret);
//alert值设置为字符串
//broadcast.setAlert("IOS 广播测试");
//alert的值设置为字典
broadcast.setAlert("今日天气", "", "今日可能下雨🌂");
broadcast.setBadge(0);
broadcast.setSound("default");
// TODO set 'production_mode' to 'true' if your app is under production mode
broadcast.setTestMode();
// Set customized fields
broadcast.setCustomizedField("test", "helloworld");
client.send(broadcast);
}
public void sendIOSUnicast() throws Exception {
IOSUnicast unicast = new IOSUnicast(appkey, appMasterSecret);
// TODO Set your device token
unicast.setDeviceToken("your device_token");
//alert值设置为字符串
//unicast.setAlert("IOS 单播测试");
//alert的值设置为字典
unicast.setAlert("今日天气", "", "今日可能下雨🌂");
unicast.setBadge(0);
unicast.setSound("default");
// TODO set 'production_mode' to 'true' if your app is under production mode
unicast.setTestMode();
// Set customized fields
unicast.setCustomizedField("test", "helloworld");
client.send(unicast);
}
public void sendIOSGroupcast() throws Exception {
IOSGroupcast groupcast = new IOSGroupcast(appkey, appMasterSecret);
*//* TODO
* Construct the filter condition:
* "where":
* {
* "and":
* [
* {"tag":"iostest"}
* ]
* }
*//*
JSONObject filterJson = new JSONObject();
JSONObject whereJson = new JSONObject();
JSONArray tagArray = new JSONArray();
JSONObject testTag = new JSONObject();
testTag.put("tag", "iostest");
tagArray.add(testTag);
whereJson.put("and", tagArray);
filterJson.put("where", whereJson);
System.out.println(filterJson.toString());
// Set filter condition into rootJson
groupcast.setFilter(filterJson);
//groupcast.setAlert("IOS 组播测试");
//alert的值设置为字典
groupcast.setAlert("今日天气", "subtitle", "今日可能下雨🌂");
groupcast.setBadge(0);
groupcast.setSound("default");
// TODO set 'production_mode' to 'true' if your app is under production mode
groupcast.setTestMode();
client.send(groupcast);
}
public void sendIOSCustomizedcast() throws Exception {
IOSCustomizedcast customizedcast = new IOSCustomizedcast(appkey, appMasterSecret);
// TODO Set your alias and alias_type here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification.
customizedcast.setAlias("alias", "alias_type");
//customizedcast.setAlert("IOS 个性化测试");
//alert的值设置为字典
customizedcast.setAlert("今日天气", "", "今日可能下雨🌂");
customizedcast.setBadge(0);
customizedcast.setSound("default");
// TODO set 'production_mode' to 'true' if your app is under production mode
customizedcast.setTestMode();
client.send(customizedcast);
}
public void sendIOSFilecast() throws Exception {
IOSFilecast filecast = new IOSFilecast(appkey,appMasterSecret);
// TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb");
filecast.setFileId( fileId);
//filecast.setAlert("IOS 文件播测试");
//alert的值设置为字典
filecast.setAlert("今日天气" , "" , "今日可能下雨🌂");
filecast.setBadge( 0);
filecast.setSound( "default");
// TODO set 'production_mode' to 'true' if your app is under production mode
filecast.setTestMode();
client.send(filecast);
}*/
}