forked from jpush/jpush-api-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJPushClient.java
More file actions
85 lines (70 loc) · 3.07 KB
/
JPushClient.java
File metadata and controls
85 lines (70 loc) · 3.07 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
package cn.jpush.api;
import java.util.Map;
import cn.jpush.api.common.DeviceEnum;
import cn.jpush.api.push.CustomMessageParams;
import cn.jpush.api.push.MessageParams;
import cn.jpush.api.push.MessageResult;
import cn.jpush.api.push.NotificationParams;
import cn.jpush.api.push.PushClient;
import cn.jpush.api.push.ReceiverTypeEnum;
import cn.jpush.api.report.ReceivedsResult;
import cn.jpush.api.report.ReportClient;
/**
* The overall entrance of JPush API library.
*
*/
public class JPushClient {
private PushClient _pushClient;
private ReportClient _reportClient;
/**
* Create a JPush Client.
* Use some defaults - time_to_live:1 day; platform:all platforms; apnsProduction:true.
*
* @param masterSecret API access secret of the app_key.
* @param appKey The app_key of one application on JPush
*/
public JPushClient(String masterSecret, String appKey) {
this(masterSecret, appKey, MessageParams.NO_TIME_TO_LIVE, null, true);
}
/**
* Create a JPush Client.
* With defined sending push params.
*
* @param masterSecret API access secret of the app_key.
* @param appKey The app_key of one application on JPush.
* @param timeToLive The off-line message live time long.
* @param device The target device of the push. If null will send to all platforms.
* @param apnsProduction If iOS push which environment should be use for sending APNs.
*/
public JPushClient(String masterSecret, String appKey, long timeToLive, DeviceEnum device, boolean apnsProduction) {
_pushClient = new PushClient(masterSecret, appKey, timeToLive, device, apnsProduction);
_reportClient = new ReportClient(masterSecret, appKey);
}
public MessageResult sendNotification(String notificationContent, NotificationParams params, Map<String, Object> extras) {
return _pushClient.sendNotification(notificationContent, params, extras);
}
public MessageResult sendCustomMessage(String msgTitle, String msgContent, CustomMessageParams params, Map<String, Object> extras) {
return _pushClient.sendCustomMessage(msgTitle, msgContent, params, extras);
}
public MessageResult sendCustomMessageAll(String msgTitle, String msgContent) {
CustomMessageParams params = new CustomMessageParams();
params.setReceiverType(ReceiverTypeEnum.APP_KEY);
//params.setTimeToLive(MessageParams.DEFAULT_TIME_TO_LIVE);
//params.setSendNo(1);
//params.setOverrideMsgId("");
return _pushClient.sendCustomMessage(msgTitle, msgContent, params, null);
}
public MessageResult sendNotificationAll(String notificationContent) {
NotificationParams params = new NotificationParams();
params.setReceiverType(ReceiverTypeEnum.APP_KEY);
//params.setTimeToLive(MessageParams.DEFAULT_TIME_TO_LIVE);
//params.setSendNo(1);
//params.setAndroidNotificationTitle("");
//params.setAndroidBuilderId(0);
//params.setOverrideMsgId("");
return _pushClient.sendNotification(notificationContent, params, null);
}
public ReceivedsResult getReportReceiveds(String msgIds) {
return _reportClient.getReceiveds(msgIds);
}
}