|
1 | 1 | package cn.jpush.api; |
2 | 2 |
|
3 | | -import java.util.Map; |
4 | | - |
5 | | -import cn.jpush.api.common.DeviceType; |
6 | | -import cn.jpush.api.push.CustomMessageParams; |
7 | | -import cn.jpush.api.push.MessageParams; |
8 | | -import cn.jpush.api.push.MessageResult; |
9 | | -import cn.jpush.api.push.NotificationParams; |
10 | 3 | import cn.jpush.api.push.PushClient; |
11 | | -import cn.jpush.api.push.model.AudienceType; |
| 4 | +import cn.jpush.api.push.PushResult; |
| 5 | +import cn.jpush.api.push.model.PushPayload; |
12 | 6 | import cn.jpush.api.report.ReceivedsResult; |
13 | 7 | import cn.jpush.api.report.ReportClient; |
14 | 8 |
|
15 | 9 | /** |
16 | 10 | * The overall entrance of JPush API library. |
17 | | - * |
18 | 11 | */ |
19 | 12 | public class JPushClient { |
20 | 13 | private PushClient _pushClient; |
21 | 14 | private ReportClient _reportClient; |
22 | 15 |
|
23 | 16 | /** |
24 | | - * Create a JPush Client. |
25 | | - * Use some defaults - time_to_live:1 day; platform:all platforms; apnsProduction:true. |
| 17 | + * Create a JPush Client. |
26 | 18 | * |
27 | | - * @param masterSecret API access secret of the app_key. |
28 | | - * @param appKey The app_key of one application on JPush |
| 19 | + * @param masterSecret API access secret of the appKey. |
| 20 | + * @param appKey The KEY of one application on JPush. |
29 | 21 | */ |
30 | 22 | public JPushClient(String masterSecret, String appKey) { |
31 | | - this(masterSecret, appKey, MessageParams.NO_TIME_TO_LIVE, null, true); |
| 23 | + _pushClient = new PushClient(masterSecret, appKey); |
| 24 | + _reportClient = new ReportClient(masterSecret, appKey); |
32 | 25 | } |
33 | 26 |
|
34 | 27 | /** |
35 | | - * Create a JPush Client. |
36 | | - * With defined sending push params. |
| 28 | + * Create a JPush Client with overall settings. |
37 | 29 | * |
38 | | - * @param masterSecret API access secret of the app_key. |
39 | | - * @param appKey The app_key of one application on JPush. |
40 | | - * @param timeToLive The off-line message live time long. |
41 | | - * @param device The target device of the push. If null will send to all platforms. |
42 | | - * @param apnsProduction If iOS push which environment should be use for sending APNs. |
| 30 | + * @param masterSecret API access secret of the appKey. |
| 31 | + * @param appKey The KEY of one application on JPush. |
| 32 | + * @param apnsProduction Overall APNs environment setting. It will override PushPayload Optional. |
| 33 | + * @param timeToLive Overall time_to_live setting. It will override PushPayload Optional. |
43 | 34 | */ |
44 | | - public JPushClient(String masterSecret, String appKey, long timeToLive, DeviceType device, boolean apnsProduction) { |
45 | | - _pushClient = new PushClient(masterSecret, appKey, timeToLive, device, apnsProduction); |
46 | | - _reportClient = new ReportClient(masterSecret, appKey); |
47 | | - } |
48 | | - |
49 | | - |
50 | | - public MessageResult sendNotification(String notificationContent, NotificationParams params, Map<String, Object> extras) { |
51 | | - return _pushClient.sendNotification(notificationContent, params, extras); |
52 | | - } |
53 | | - |
54 | | - public MessageResult sendCustomMessage(String msgTitle, String msgContent, CustomMessageParams params, Map<String, Object> extras) { |
55 | | - return _pushClient.sendCustomMessage(msgTitle, msgContent, params, extras); |
| 35 | + public JPushClient(String masterSecret, String appKey, boolean apnsProduction, long timeToLive) { |
| 36 | + _pushClient = new PushClient(masterSecret, appKey, apnsProduction, timeToLive); |
| 37 | + _reportClient = new ReportClient(masterSecret, appKey); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Send a push |
| 42 | + * |
| 43 | + * @param pushPayload payload of a push. |
| 44 | + * @return PushResult. Can be printed to a JSON. |
| 45 | + */ |
| 46 | + public PushResult sendPush(PushPayload pushPayload) { |
| 47 | + return _pushClient.sendPush(pushPayload); |
56 | 48 | } |
57 | 49 |
|
58 | | - |
59 | | - public MessageResult sendCustomMessageAll(String msgTitle, String msgContent) { |
60 | | - CustomMessageParams params = new CustomMessageParams(); |
61 | | - params.setReceiverType(AudienceType.APP_KEY); |
62 | | - //params.setTimeToLive(MessageParams.DEFAULT_TIME_TO_LIVE); |
63 | | - //params.setSendNo(1); |
64 | | - //params.setOverrideMsgId(""); |
65 | | - return _pushClient.sendCustomMessage(msgTitle, msgContent, params, null); |
66 | | - } |
67 | | - |
68 | | - public MessageResult sendNotificationAll(String notificationContent) { |
69 | | - NotificationParams params = new NotificationParams(); |
70 | | - params.setReceiverType(AudienceType.APP_KEY); |
71 | | - //params.setTimeToLive(MessageParams.DEFAULT_TIME_TO_LIVE); |
72 | | - //params.setSendNo(1); |
73 | | - //params.setAndroidNotificationTitle(""); |
74 | | - //params.setAndroidBuilderId(0); |
75 | | - //params.setOverrideMsgId(""); |
76 | | - return _pushClient.sendNotification(notificationContent, params, null); |
77 | | - } |
78 | | - |
79 | | - |
| 50 | + /** |
| 51 | + * Get received report. |
| 52 | + * |
| 53 | + * @param msgIds 100 msgids to batch getting is supported. |
| 54 | + * @return ReceivedResult. Can be printed to JSON. |
| 55 | + */ |
80 | 56 | public ReceivedsResult getReportReceiveds(String msgIds) { |
81 | 57 | return _reportClient.getReceiveds(msgIds); |
82 | 58 | } |
|
0 commit comments