diff --git a/pom.xml b/pom.xml index 015b96ac..79beaa61 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ cn.jpush.api jpush-client - 3.6.6 + 3.6.8 jar https://github.com/jpush/jpush-api-java-client JPush API Java Client diff --git a/src/main/java/cn/jpush/api/JPushClient.java b/src/main/java/cn/jpush/api/JPushClient.java index ea4a7dd3..e0b132b7 100644 --- a/src/main/java/cn/jpush/api/JPushClient.java +++ b/src/main/java/cn/jpush/api/JPushClient.java @@ -7,6 +7,7 @@ import cn.jiguang.common.resp.*; import cn.jpush.api.push.CIDResult; import cn.jpush.api.push.model.*; +import cn.jpush.api.push.model.live_activity.LiveActivity; import cn.jpush.api.report.*; import cn.jpush.api.report.model.CheckMessagePayload; import com.google.gson.JsonObject; @@ -38,30 +39,30 @@ */ public class JPushClient { private final PushClient _pushClient; - private final ReportClient _reportClient; - private final DeviceClient _deviceClient; + private final ReportClient _reportClient; + private final DeviceClient _deviceClient; private final ScheduleClient _scheduleClient; - - /** - * Create a JPush Client. - * - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. - */ - public JPushClient(String masterSecret, String appKey) { - _pushClient = new PushClient(masterSecret, appKey); - _reportClient = new ReportClient(masterSecret, appKey); - _deviceClient = new DeviceClient(masterSecret, appKey); + + /** + * Create a JPush Client. + * + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. + */ + public JPushClient(String masterSecret, String appKey) { + _pushClient = new PushClient(masterSecret, appKey); + _reportClient = new ReportClient(masterSecret, appKey); + _deviceClient = new DeviceClient(masterSecret, appKey); _scheduleClient = new ScheduleClient(masterSecret, appKey); - } + } /** * Create a JPush Client by custom Client configuration. * * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. - * @param proxy The proxy, if there is no proxy, should be null. - * @param conf The client configuration. Can use ClientConfig.getInstance() as default. + * @param appKey The KEY of one application on JPush. + * @param proxy The proxy, if there is no proxy, should be null. + * @param conf The client configuration. Can use ClientConfig.getInstance() as default. */ public JPushClient(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) { _pushClient = new PushClient(masterSecret, appKey, proxy, conf); @@ -72,24 +73,26 @@ public JPushClient(String masterSecret, String appKey, HttpProxy proxy, ClientCo /** * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setMaxRetryTimes} instead of this constructor. - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. + * + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. * @param maxRetryTimes The max retry times. */ @Deprecated - public JPushClient(String masterSecret, String appKey, int maxRetryTimes) { + public JPushClient(String masterSecret, String appKey, int maxRetryTimes) { _pushClient = new PushClient(masterSecret, appKey, maxRetryTimes); _reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes); _deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes); _scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes); - } + } /** * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setMaxRetryTimes} instead of this constructor. - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. + * + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. * @param maxRetryTimes The max retry times. - * @param proxy The proxy, if there is no proxy, should be null. + * @param proxy The proxy, if there is no proxy, should be null. */ @Deprecated public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy) { @@ -98,18 +101,18 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr _deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes, proxy); _scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes, proxy); } - + /** * Create a JPush Client by custom Client configuration. - * + *

* If you are using JPush privacy cloud, maybe this constructor is what you needed. * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setMaxRetryTimes} instead of this constructor. * - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. * @param maxRetryTimes Client request retry times. - * @param proxy The proxy, if there is no proxy, should be null. - * @param conf The client configuration. Can use ClientConfig.getInstance() as default. + * @param proxy The proxy, if there is no proxy, should be null. + * @param conf The client configuration. Can use ClientConfig.getInstance() as default. */ @Deprecated public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf) { @@ -124,18 +127,18 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr /** * Create a JPush Client by custom Client configuration with global settings. - * + *

* If you are using JPush privacy cloud, and you want different settings from default globally, * maybe this constructor is what you needed. * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setGlobalPushSetting} instead of this constructor. * - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. - * @param maxRetryTimes Client request retry times. - * @param proxy The proxy, if there is no proxy, should be null. - * @param conf The client configuration. Can use ClientConfig.getInstance() as default. + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. + * @param maxRetryTimes Client request retry times. + * @param proxy The proxy, if there is no proxy, should be null. + * @param conf The client configuration. Can use ClientConfig.getInstance() as default. * @param apnsProduction Global APNs environment setting. It will override PushPayload Options. - * @param timeToLive Global time_to_live setting. It will override PushPayload Options. + * @param timeToLive Global time_to_live setting. It will override PushPayload Options. */ @Deprecated public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf, @@ -148,18 +151,18 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr _deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf); _scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf); } - - /** - * Create a JPush Client with global settings. - * - * If you want different settings from default globally, this constructor is what you needed. - * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setGlobalPushSetting} instead of this constructor. + + /** + * Create a JPush Client with global settings. + *

+ * If you want different settings from default globally, this constructor is what you needed. + * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setGlobalPushSetting} instead of this constructor. * - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. - * @param apnsProduction Global APNs environment setting. It will override PushPayload Options. - * @param timeToLive Global time_to_live setting. It will override PushPayload Options. - */ + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. + * @param apnsProduction Global APNs environment setting. It will override PushPayload Options. + * @param timeToLive Global time_to_live setting. It will override PushPayload Options. + */ @Deprecated public JPushClient(String masterSecret, String appKey, boolean apnsProduction, long timeToLive) { ClientConfig conf = ClientConfig.getInstance(); @@ -179,28 +182,28 @@ public PushClient getPushClient() { /** * Send a push with PushPayload object. - * - * @param pushPayload payload object of a push. + * + * @param pushPayload payload object of a push. * @return PushResult The result object of a Push. Can be printed to a JSON. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ - public PushResult sendPush(PushPayload pushPayload) throws APIConnectionException, APIRequestException { - return _pushClient.sendPush(pushPayload); - } - - /** - * Send a push with JSON string. - * - * You can send a push JSON string directly with this method. - * - * Attention: globally settings cannot be affect this type of Push. - * - * @param payloadString payload of a push. + public PushResult sendPush(PushPayload pushPayload) throws APIConnectionException, APIRequestException { + return _pushClient.sendPush(pushPayload); + } + + /** + * Send a push with JSON string. + *

+ * You can send a push JSON string directly with this method. + *

+ * Attention: globally settings cannot be affect this type of Push. + * + * @param payloadString payload of a push. * @return PushResult. Can be printed to a JSON. - * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. - */ + * @throws APIConnectionException if a remote or network exception occurs. + * @throws APIRequestException if a request exception occurs. + */ public PushResult sendPush(String payloadString) throws APIConnectionException, APIRequestException { return _pushClient.sendPush(payloadString); } @@ -211,26 +214,26 @@ public PushResult sendPush(String payloadString) throws APIConnectionException, * @param pushPayload payload object of a push. * @return PushResult The result object of a Push. Can be printed to a JSON. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendFilePush(PushPayload pushPayload) throws APIConnectionException, APIRequestException { return _pushClient.sendFilePush(pushPayload); } - + /** * Validate a push action, but do NOT send it actually. - * + * * @param payload payload of a push. * @return PushResult. Can be printed to a JSON. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendPushValidate(PushPayload payload) throws APIConnectionException, APIRequestException { - return _pushClient.sendPushValidate(payload); + return _pushClient.sendPushValidate(payload); } public PushResult sendPushValidate(String payloadString) throws APIConnectionException, APIRequestException { - return _pushClient.sendPushValidate(payloadString); + return _pushClient.sendPushValidate(payloadString); } public BatchPushResult batchSendPushByRegId(List pushPayloadList) throws APIConnectionException, APIRequestException { @@ -243,35 +246,36 @@ public BatchPushResult batchSendPushByAlias(List pushPayloadList) t /** * Get cid list, the data form of cid is appKey-uuid. + * * @param count the count of cid list, from 1 to 1000. default is 1. - * @param type default is push, option: schedule + * @param type default is push, option: schedule * @return CIDResult, an array of cid * @throws APIConnectionException connect exception - * @throws APIRequestException request exception + * @throws APIRequestException request exception */ public CIDResult getCidList(int count, String type) throws APIConnectionException, APIRequestException { return _pushClient.getCidList(count, type); } - + // ------------------------------- Report API /** - * Get received report. - * + * Get received report. + * * @param msgIds 100 msgids to batch getting is supported. * @return ReceivedResult. Can be printed to JSON. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ReceivedsResult getReportReceiveds(String msgIds) throws APIConnectionException, APIRequestException { - return _reportClient.getReceiveds(msgIds); - } - + return _reportClient.getReceiveds(msgIds); + } + public UsersResult getReportUsers(TimeUnit timeUnit, String start, int duration) throws APIConnectionException, APIRequestException { return _reportClient.getUsers(timeUnit, start, duration); } - + public MessagesResult getReportMessages(String msgIds) throws APIConnectionException, APIRequestException { return _reportClient.getMessages(msgIds); } @@ -300,7 +304,7 @@ public GroupUsersResult getGroupReportUsers(TimeUnit timeUnit, String start, int APIRequestException { return _reportClient.getGroupUsers(timeUnit, start, duration); } - + // ------------------------------ Shortcuts - notification public PushResult sendNotificationAll(String alert) throws APIConnectionException, APIRequestException { @@ -313,18 +317,18 @@ public PushResult sendNotificationAll(String alert) throws APIConnectionExceptio * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @return push result * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendNotificationAll(String alert, SMS sms) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.alertAll(alert, sms); return _pushClient.sendPush(payload); } - public PushResult sendAndroidNotificationWithAlias(String title, String alert, - Map extras, String... alias) + public PushResult sendAndroidNotificationWithAlias(String title, String alert, + Map extras, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android()) @@ -338,14 +342,14 @@ public PushResult sendAndroidNotificationWithAlias(String title, String alert, * Send a notification to Android with alias. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The notification title. - * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param title The notification title. + * @param alert The notification content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param extras The extra parameter. - * @param alias The users' alias. + * @param alias The users' alias. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendAndroidNotificationWithAlias(String title, String alert, SMS sms, Map extras, String... alias) @@ -359,8 +363,8 @@ public PushResult sendAndroidNotificationWithAlias(String title, String alert, S return _pushClient.sendPush(payload); } - public PushResult sendAndroidNotificationWithRegistrationID(String title, String alert, - Map extras, String... registrationID) + public PushResult sendAndroidNotificationWithRegistrationID(String title, String alert, + Map extras, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android()) @@ -374,14 +378,14 @@ public PushResult sendAndroidNotificationWithRegistrationID(String title, String * Send a notification to Android with RegistrationID. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The notification title. - * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param extras The extra parameter. + * @param title The notification title. + * @param alert The notification content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param extras The extra parameter. * @param registrationID The registration id generated by JPush. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendAndroidNotificationWithRegistrationID(String title, String alert, SMS sms, Map extras, String... registrationID) @@ -396,7 +400,7 @@ public PushResult sendAndroidNotificationWithRegistrationID(String title, String } public PushResult sendIosNotificationWithAlias(String alert, - Map extras, String... alias) + Map extras, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) @@ -409,13 +413,14 @@ public PushResult sendIosNotificationWithAlias(String alert, /** * Send a notification to iOS with alias. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. - * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * + * @param alert The notification content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param extras The extra parameter. - * @param alias The users' alias. + * @param alias The users' alias. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(String alert, SMS sms, Map extras, String... alias) @@ -433,12 +438,12 @@ public PushResult sendIosNotificationWithAlias(String alert, SMS sms, * Send an iOS notification with alias. * If you want to send alert as a Json object, maybe this method is what you needed. * - * @param alert The wrapper of APNs alert. + * @param alert The wrapper of APNs alert. * @param extras The extra params. - * @param alias The alias list. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(IosAlert alert, Map extras, String... alias) @@ -456,13 +461,13 @@ public PushResult sendIosNotificationWithAlias(IosAlert alert, * If you want to send alert as a Json object, maybe this method is what you needed. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The wrapper of APNs alert. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param alert The wrapper of APNs alert. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param extras The extra params. - * @param alias The alias list. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(IosAlert alert, SMS sms, Map extras, String... alias) @@ -480,12 +485,12 @@ public PushResult sendIosNotificationWithAlias(IosAlert alert, SMS sms, * Send an iOS notification with alias. * If you want to send alert as a Json object, maybe this method is what you needed. * - * @param alert The JSON object of APNs alert. + * @param alert The JSON object of APNs alert. * @param extras The extra params. - * @param alias The alias list. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(JsonObject alert, Map extras, String... alias) @@ -503,13 +508,13 @@ public PushResult sendIosNotificationWithAlias(JsonObject alert, * If you want to send alert as a Json object, maybe this method is what you needed. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The JSON object of APNs alert. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param alert The JSON object of APNs alert. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param extras The extra params. - * @param alias The alias list. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(JsonObject alert, SMS sms, Map extras, String... alias) @@ -523,8 +528,8 @@ public PushResult sendIosNotificationWithAlias(JsonObject alert, SMS sms, return _pushClient.sendPush(payload); } - public PushResult sendIosNotificationWithRegistrationID(String alert, - Map extras, String... registrationID) + public PushResult sendIosNotificationWithRegistrationID(String alert, + Map extras, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) @@ -538,13 +543,13 @@ public PushResult sendIosNotificationWithRegistrationID(String alert, * Send an iOS notification with registrationIds. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param extras The extra params. + * @param alert The notification content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param extras The extra params. * @param registrationID The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(String alert, SMS sms, Map extras, String... registrationID) @@ -562,12 +567,12 @@ public PushResult sendIosNotificationWithRegistrationID(String alert, SMS sms, * Send an iOS notification with registrationIds. * If you want to send alert as a Json object, maybe this method is what you needed. * - * @param alert The wrapper of APNs alert. - * @param extras The extra params. + * @param alert The wrapper of APNs alert. + * @param extras The extra params. * @param registrationID The registration ids. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, Map extras, String... registrationID) @@ -585,13 +590,13 @@ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, * If you want to send alert as a Json object, maybe this method is what you needed. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The wrapper of APNs alert. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param extras The extra params. + * @param alert The wrapper of APNs alert. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param extras The extra params. * @param registrationID The registration ids. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, SMS sms, Map extras, String... registrationID) @@ -609,12 +614,12 @@ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, SMS sms, * Send an iOS notification with registrationIds. * If you want to send alert as a Json object, maybe this method is what you needed. * - * @param alert The wrapper of APNs alert. - * @param extras The extra params. + * @param alert The wrapper of APNs alert. + * @param extras The extra params. * @param registrationID The registration ids. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, Map extras, String... registrationID) @@ -632,13 +637,13 @@ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, * If you want to send alert as a Json object, maybe this method is what you needed. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The JSON object of APNs alert. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param extras The extra params. + * @param alert The JSON object of APNs alert. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param extras The extra params. * @param registrationID The registration ids. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, SMS sms, Map extras, String... registrationID) @@ -652,7 +657,7 @@ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, SMS sm return _pushClient.sendPush(payload); } - + // ---------------------- shortcuts - message public PushResult sendMessageAll(String msgContent) throws APIConnectionException, APIRequestException { @@ -665,17 +670,17 @@ public PushResult sendMessageAll(String msgContent) throws APIConnectionExceptio * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendMessageAll(String msgContent, SMS sms) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.messageAll(msgContent, sms); return _pushClient.sendPush(payload); } - public PushResult sendAndroidMessageWithAlias(String title, String msgContent, String... alias) + public PushResult sendAndroidMessageWithAlias(String title, String msgContent, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android()) @@ -692,13 +697,13 @@ public PushResult sendAndroidMessageWithAlias(String title, String msgContent, S * Send an Android message with alias. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. + * @param title The message title. * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param alias The alias list. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendAndroidMessageWithAlias(String title, String msgContent, SMS sms, String... alias) throws APIConnectionException, APIRequestException { @@ -714,7 +719,7 @@ public PushResult sendAndroidMessageWithAlias(String title, String msgContent, S return _pushClient.sendPush(payload); } - public PushResult sendAndroidMessageWithRegistrationID(String title, String msgContent, String... registrationID) + public PushResult sendAndroidMessageWithRegistrationID(String title, String msgContent, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android()) @@ -731,13 +736,13 @@ public PushResult sendAndroidMessageWithRegistrationID(String title, String msgC * Send an Android message with registration id. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. - * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param title The message title. + * @param msgContent The message content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param registrationID The registration id list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendAndroidMessageWithRegistrationID(String title, String msgContent, SMS sms, String... registrationID) throws APIConnectionException, APIRequestException { @@ -753,7 +758,7 @@ public PushResult sendAndroidMessageWithRegistrationID(String title, String msgC return _pushClient.sendPush(payload); } - public PushResult sendIosMessageWithAlias(String title, String msgContent, String... alias) + public PushResult sendIosMessageWithAlias(String title, String msgContent, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) @@ -770,13 +775,13 @@ public PushResult sendIosMessageWithAlias(String title, String msgContent, Strin * Send an iOS message with alias. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. + * @param title The message title. * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param alias The alias list. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosMessageWithAlias(String title, String msgContent, SMS sms, String... alias) throws APIConnectionException, APIRequestException { @@ -792,7 +797,7 @@ public PushResult sendIosMessageWithAlias(String title, String msgContent, SMS s return _pushClient.sendPush(payload); } - public PushResult sendIosMessageWithRegistrationID(String title, String msgContent, String... registrationID) + public PushResult sendIosMessageWithRegistrationID(String title, String msgContent, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) @@ -809,13 +814,13 @@ public PushResult sendIosMessageWithRegistrationID(String title, String msgConte * Send an iOS message with registration id. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. - * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param title The message title. + * @param msgContent The message content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param registrationID The registrationIds generated by JPush. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosMessageWithRegistrationID(String title, String msgContent, SMS sms, String... registrationID) throws APIConnectionException, APIRequestException { @@ -831,7 +836,7 @@ public PushResult sendIosMessageWithRegistrationID(String title, String msgConte return _pushClient.sendPush(payload); } - public PushResult sendMessageWithRegistrationID(String title, String msgContent, String... registrationID) + public PushResult sendMessageWithRegistrationID(String title, String msgContent, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.all()) @@ -848,13 +853,13 @@ public PushResult sendMessageWithRegistrationID(String title, String msgContent, * Send a message with registrationIds. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. - * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param title The message title. + * @param msgContent The message content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param registrationID The registrationIds generated by JPush. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendMessageWithRegistrationID(String title, String msgContent, SMS sms, String... registrationID) throws APIConnectionException, APIRequestException { @@ -872,7 +877,8 @@ public PushResult sendMessageWithRegistrationID(String title, String msgContent, /** * Delete a push by msgId. - * @param msgId The message id + * + * @param msgId The message id * @return delete result * @throws APIConnectionException if a remote or network exception occurs. * @throws APIRequestException if a request exception occurs @@ -881,85 +887,85 @@ public DefaultResult deletePush(String msgId) throws APIConnectionException, API return _pushClient.deletePush(msgId); } - + // ----------------------- Device - - public TagAliasResult getDeviceTagAlias(String registrationId) - throws APIConnectionException, APIRequestException { - return _deviceClient.getDeviceTagAlias(registrationId); + + public TagAliasResult getDeviceTagAlias(String registrationId) + throws APIConnectionException, APIRequestException { + return _deviceClient.getDeviceTagAlias(registrationId); } public DefaultResult updateDeviceTagAlias(String registrationId, boolean clearAlias, boolean clearTag) - throws APIConnectionException, APIRequestException { - return _deviceClient.updateDeviceTagAlias(registrationId, clearAlias, clearTag); + throws APIConnectionException, APIRequestException { + return _deviceClient.updateDeviceTagAlias(registrationId, clearAlias, clearTag); + } + + public DefaultResult updateDeviceTagAlias(String registrationId, String alias, + Set tagsToAdd, Set tagsToRemove) + throws APIConnectionException, APIRequestException { + return _deviceClient.updateDeviceTagAlias(registrationId, alias, tagsToAdd, tagsToRemove); + } + + public TagListResult getTagList() + throws APIConnectionException, APIRequestException { + return _deviceClient.getTagList(); + } + + public BooleanResult isDeviceInTag(String theTag, String registrationID) + throws APIConnectionException, APIRequestException { + return _deviceClient.isDeviceInTag(theTag, registrationID); + } + + public DefaultResult addRemoveDevicesFromTag(String theTag, + Set toAddUsers, Set toRemoveUsers) + throws APIConnectionException, APIRequestException { + return _deviceClient.addRemoveDevicesFromTag(theTag, toAddUsers, + toRemoveUsers); + } + + public DefaultResult deleteTag(String theTag, String platform) + throws APIConnectionException, APIRequestException { + return _deviceClient.deleteTag(theTag, platform); + } + + public AliasDeviceListResult getAliasDeviceList(String alias, + String platform) throws APIConnectionException, APIRequestException { + return _deviceClient.getAliasDeviceList(alias, platform); + } + + public DefaultResult deleteAlias(String alias, String platform) + throws APIConnectionException, APIRequestException { + return _deviceClient.deleteAlias(alias, platform); } - - public DefaultResult updateDeviceTagAlias(String registrationId, String alias, - Set tagsToAdd, Set tagsToRemove) + + public DefaultResult removeDevicesFromAlias(String alias, Set toRemoveDevice) throws APIConnectionException, APIRequestException { - return _deviceClient.updateDeviceTagAlias(registrationId, alias, tagsToAdd, tagsToRemove); - } - - public TagListResult getTagList() - throws APIConnectionException, APIRequestException { - return _deviceClient.getTagList(); - } - - public BooleanResult isDeviceInTag(String theTag, String registrationID) - throws APIConnectionException, APIRequestException { - return _deviceClient.isDeviceInTag(theTag, registrationID); - } - - public DefaultResult addRemoveDevicesFromTag(String theTag, - Set toAddUsers, Set toRemoveUsers) - throws APIConnectionException, APIRequestException { - return _deviceClient.addRemoveDevicesFromTag(theTag, toAddUsers, - toRemoveUsers); - } - - public DefaultResult deleteTag(String theTag, String platform) - throws APIConnectionException, APIRequestException { - return _deviceClient.deleteTag(theTag, platform); - } - - public AliasDeviceListResult getAliasDeviceList(String alias, - String platform) throws APIConnectionException, APIRequestException { - return _deviceClient.getAliasDeviceList(alias, platform); - } - - public DefaultResult deleteAlias(String alias, String platform) - throws APIConnectionException, APIRequestException { - return _deviceClient.deleteAlias(alias, platform); - } - - public DefaultResult removeDevicesFromAlias(String alias, Set toRemoveDevice) - throws APIConnectionException, APIRequestException { - return _deviceClient.removeDevicesFromAlias(alias, toRemoveDevice); - } + return _deviceClient.removeDevicesFromAlias(alias, toRemoveDevice); + } public Map getUserOnlineStatus(String... registrationIds) - throws APIConnectionException, APIRequestException - { + throws APIConnectionException, APIRequestException { return _deviceClient.getUserOnlineStatus(registrationIds); } public DefaultResult bindMobile(String registrationId, String mobile) - throws APIConnectionException, APIRequestException - { + throws APIConnectionException, APIRequestException { return _deviceClient.bindMobile(registrationId, mobile); } // ----------------------- Schedule + /** * Create a single schedule. - * @param name The schedule name. - * @param time The push time, format is 'yyyy-MM-dd HH:mm:ss' - * @param push The push payload. + * + * @param name The schedule name. + * @param time The push time, format is 'yyyy-MM-dd HH:mm:ss' + * @param push The push payload. * @param masterSecret master secret - * @param appKey app key + * @param appKey app key * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createSingleSchedule(String name, String time, PushPayload push, String masterSecret, String appKey) @@ -979,16 +985,17 @@ public ScheduleResult createSingleSchedule(String name, String time, PushPayload /** * Create a daily schedule push everyday. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss' - * @param push The push payload. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss' + * @param push The push payload. * @param masterSecret master secret - * @param appKey app key + * @param appKey app key * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createDailySchedule(String name, String start, String end, String time, PushPayload push, String masterSecret, String appKey) @@ -999,17 +1006,18 @@ public ScheduleResult createDailySchedule(String name, String start, String end, /** * Create a daily schedule push with a custom frequency. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss' - * @param frequency The custom frequency. - * @param push The push payload. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss' + * @param frequency The custom frequency. + * @param push The push payload. * @param masterSecret master secret - * @param appKey app key + * @param appKey app key * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createDailySchedule(String name, String start, String end, String time, int frequency, PushPayload push, String masterSecret, String appKey) @@ -1020,17 +1028,18 @@ public ScheduleResult createDailySchedule(String name, String start, String end, /** * Create a weekly schedule push every week at the appointed days. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss' - * @param days The appointed days. - * @param push The push payload. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss' + * @param days The appointed days. + * @param push The push payload. * @param masterSecret master secret - * @param appKey app key + * @param appKey app key * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createWeeklySchedule(String name, String start, String end, String time, Week[] days, PushPayload push, String masterSecret, String appKey) @@ -1038,7 +1047,7 @@ public ScheduleResult createWeeklySchedule(String name, String start, String end Preconditions.checkArgument(null != days && days.length > 0, "The days must not be empty."); String[] points = new String[days.length]; - for(int i = 0 ; i < days.length; i++) { + for (int i = 0; i < days.length; i++) { points[i] = days[i].name(); } return createPeriodicalSchedule(name, start, end, time, TimeUnit.WEEK, 1, points, push, @@ -1047,18 +1056,19 @@ public ScheduleResult createWeeklySchedule(String name, String start, String end /** * Create a weekly schedule push with a custom frequency at the appointed days. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss'. - * @param frequency The custom frequency. - * @param days The appointed days. - * @param push The push payload. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss'. + * @param frequency The custom frequency. + * @param days The appointed days. + * @param push The push payload. * @param masterSecret master secret - * @param appKey app key + * @param appKey app key * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createWeeklySchedule(String name, String start, String end, String time, int frequency, Week[] days, PushPayload push, String masterSecret, String appKey) @@ -1066,7 +1076,7 @@ public ScheduleResult createWeeklySchedule(String name, String start, String end Preconditions.checkArgument(null != days && days.length > 0, "The days must not be empty."); String[] points = new String[days.length]; - for(int i = 0 ; i < days.length; i++) { + for (int i = 0; i < days.length; i++) { points[i] = days[i].name(); } return createPeriodicalSchedule(name, start, end, time, TimeUnit.WEEK, frequency, points, push, masterSecret, appKey); @@ -1074,17 +1084,18 @@ public ScheduleResult createWeeklySchedule(String name, String start, String end /** * Create a monthly schedule push every month at the appointed days. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss'. - * @param points The appointed days. - * @param push The push payload. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss'. + * @param points The appointed days. + * @param push The push payload. * @param masterSecret master secret - * @param appKey app key + * @param appKey app key * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createMonthlySchedule(String name, String start, String end, String time, String[] points, PushPayload push, String masterSecret, String appKey) @@ -1095,18 +1106,19 @@ public ScheduleResult createMonthlySchedule(String name, String start, String en /** * Create a monthly schedule push with a custom frequency at the appointed days. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss'. - * @param frequency The custom frequency. - * @param points The appointed days. - * @param push The push payload. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss'. + * @param frequency The custom frequency. + * @param points The appointed days. + * @param push The push payload. * @param masterSecret master secret - * @param appKey app key + * @param appKey app key * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createMonthlySchedule(String name, String start, String end, String time, int frequency, String[] points, PushPayload push, String masterSecret, String appKey) @@ -1117,33 +1129,36 @@ public ScheduleResult createMonthlySchedule(String name, String start, String en /** * Get the schedule information by the schedule id. + * * @param scheduleId The schedule id. * @return The schedule information. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult getSchedule(String scheduleId) throws APIConnectionException, APIRequestException { - return _scheduleClient.getSchedule(scheduleId); + return _scheduleClient.getSchedule(scheduleId); } - + /** * Get the message id by the schedule id. + * * @param scheduleId The schedule id. * @return The message id list. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleMsgIdsResult getScheduleMsgIds(String scheduleId) throws APIConnectionException, APIRequestException { - return _scheduleClient.getScheduleMsgIds(scheduleId); + return _scheduleClient.getScheduleMsgIds(scheduleId); } /** * Get the schedule list size and the first page. + * * @return The schedule list size and the first page. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleListResult getScheduleList() throws APIConnectionException, APIRequestException { @@ -1152,10 +1167,11 @@ public ScheduleListResult getScheduleList() /** * Get the schedule list by the page. + * * @param page The page to search. * @return The schedule list of the appointed page. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleListResult getScheduleList(int page) throws APIConnectionException, APIRequestException { @@ -1164,11 +1180,12 @@ public ScheduleListResult getScheduleList(int page) /** * Update the schedule name + * * @param scheduleId The schedule id. - * @param name The new name. + * @param name The new name. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult updateScheduleName(String scheduleId, String name) throws APIConnectionException, APIRequestException { @@ -1181,10 +1198,11 @@ public ScheduleResult updateScheduleName(String scheduleId, String name) /** * Enable the schedule. + * * @param scheduleId The schedule id. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult enableSchedule(String scheduleId) throws APIConnectionException, APIRequestException { @@ -1197,10 +1215,11 @@ public ScheduleResult enableSchedule(String scheduleId) /** * Disable the schedule. + * * @param scheduleId The schedule id. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult disableSchedule(String scheduleId) throws APIConnectionException, APIRequestException { @@ -1212,11 +1231,12 @@ public ScheduleResult disableSchedule(String scheduleId) /** * Update the trigger of the schedule. + * * @param scheduleId The schedule id. - * @param trigger The new trigger. + * @param trigger The new trigger. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult updateScheduleTrigger(String scheduleId, TriggerPayload trigger) throws APIConnectionException, APIRequestException { @@ -1229,11 +1249,12 @@ public ScheduleResult updateScheduleTrigger(String scheduleId, TriggerPayload tr /** * Update the push content of the schedule. + * * @param scheduleId The schedule id. - * @param push The new push payload. + * @param push The new push payload. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult updateSchedulePush(String scheduleId, PushPayload push) throws APIConnectionException, APIRequestException { @@ -1246,11 +1267,12 @@ public ScheduleResult updateSchedulePush(String scheduleId, PushPayload push) /** * Update a schedule by the id. + * * @param scheduleId The schedule id to update. - * @param payload The new schedule payload. + * @param payload The new schedule payload. * @return The new schedule information. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult updateSchedule(String scheduleId, SchedulePayload payload) throws APIConnectionException, APIRequestException { @@ -1259,9 +1281,10 @@ public ScheduleResult updateSchedule(String scheduleId, SchedulePayload payload) /** * Delete a schedule by id. + * * @param scheduleId The schedule id. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public void deleteSchedule(String scheduleId) throws APIConnectionException, APIRequestException { @@ -1274,7 +1297,7 @@ private ScheduleResult createPeriodicalSchedule(String name, String start, Strin throws APIConnectionException, APIRequestException { TriggerPayload trigger = TriggerPayload.newBuilder() .setPeriodTime(start, end, time) - .setTimeFrequency(timeUnit, frequency, point ) + .setTimeFrequency(timeUnit, frequency, point) .buildPeriodical(); SchedulePayload payload = SchedulePayload.newBuilder() .setName(name) @@ -1286,6 +1309,10 @@ private ScheduleResult createPeriodicalSchedule(String name, String start, Strin return _scheduleClient.createSchedule(payload, masterSecret, appKey); } + public PushResult sendLiveActivity(LiveActivity liveActivity) throws APIConnectionException, APIRequestException { + return _pushClient.sendLiveActivity(liveActivity); + } + public void close() { _pushClient.close(); } diff --git a/src/main/java/cn/jpush/api/push/PushClient.java b/src/main/java/cn/jpush/api/push/PushClient.java index 4a572d88..493d0818 100644 --- a/src/main/java/cn/jpush/api/push/PushClient.java +++ b/src/main/java/cn/jpush/api/push/PushClient.java @@ -10,6 +10,7 @@ import cn.jiguang.common.utils.sm2.SM2Util; import cn.jpush.api.push.model.*; import cn.jpush.api.push.model.audience.Audience; +import cn.jpush.api.push.model.live_activity.LiveActivity; import com.google.gson.*; import java.util.List; @@ -45,7 +46,8 @@ public class PushClient { // encrypt type, the default value is empty private String _encryptType; - public PushClient() {} + public PushClient() { + } /** * Create a Push Client. @@ -57,8 +59,8 @@ public PushClient(String masterSecret, String appKey) { this(masterSecret, appKey, null, ClientConfig.getInstance()); } - public PushClient(String masterSecret, String appKey,ClientConfig clientConfig){ - this(masterSecret,appKey,null,clientConfig); + public PushClient(String masterSecret, String appKey, ClientConfig clientConfig) { + this(masterSecret, appKey, null, clientConfig); } /** @@ -379,6 +381,12 @@ private void checkPushPayload(PushPayload pushPayload) { } } + + public PushResult sendLiveActivity(LiveActivity liveActivity) throws APIConnectionException, APIRequestException { + ResponseWrapper response = _httpClient.sendPost(_baseUrl + _pushPath, liveActivity.toJSON().toString()); + return BaseResult.fromResponse(response, PushResult.class); + } + } diff --git a/src/main/java/cn/jpush/api/push/model/live_activity/LiveActivity.java b/src/main/java/cn/jpush/api/push/model/live_activity/LiveActivity.java new file mode 100644 index 00000000..65ad98ad --- /dev/null +++ b/src/main/java/cn/jpush/api/push/model/live_activity/LiveActivity.java @@ -0,0 +1,194 @@ +package cn.jpush.api.push.model.live_activity; + +import cn.jpush.api.push.model.PushModel; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; + +public class LiveActivity implements PushModel { + + private final Boolean apnsProduction; + + private final String liveActivityId; + + private final String iOSEvent; + private final JsonObject iOSContentState; + private final String iOSAlertTitle; + private final String iOSAlertAlternateTitle; + private final String iOSAlertBody; + private final String iOSAlertAlternateBody; + private final String iOSAlertSound; + private final Integer iOSDismissalDate; + + public LiveActivity(Boolean apnsProduction, String liveActivityId, String iOSEvent, JsonObject iOSContentState, String iOSAlertTitle, String iOSAlertAlternateTitle, String iOSAlertBody, String iOSAlertAlternateBody, String iOSAlertSound, Integer iOSDismissalDate) { + this.apnsProduction = apnsProduction; + this.liveActivityId = liveActivityId; + this.iOSEvent = iOSEvent; + this.iOSContentState = iOSContentState; + this.iOSAlertTitle = iOSAlertTitle; + this.iOSAlertAlternateTitle = iOSAlertAlternateTitle; + this.iOSAlertBody = iOSAlertBody; + this.iOSAlertAlternateBody = iOSAlertAlternateBody; + this.iOSAlertSound = iOSAlertSound; + this.iOSDismissalDate = iOSDismissalDate; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public static class Builder { + private Boolean apnsProduction; + private String liveActivityId; + private String iOSEvent; + private JsonObject iOSContentState; + private String iOSAlertTitle; + private String iOSAlertAlternateTitle; + private String iOSAlertBody; + private String iOSAlertAlternateBody; + private String iOSAlertSound; + private Integer iOSDismissalDate; + + public Builder apnsProduction(Boolean apnsProduction) { + this.apnsProduction = apnsProduction; + return this; + } + + public Builder liveActivityId(String liveActivityId) { + this.liveActivityId = liveActivityId; + return this; + } + + public Builder iOSEvent(LiveActivityEvent iOSEvent) { + if (iOSEvent != null) { + this.iOSEvent = iOSEvent.getValue(); + } + return this; + } + + public Builder iOSContentState(String key, String value) { + if (this.iOSContentState == null) { + this.iOSContentState = new JsonObject(); + } + this.iOSContentState.addProperty(key, value); + return this; + } + + public Builder iOSContentState(String key, Number value) { + if (this.iOSContentState == null) { + this.iOSContentState = new JsonObject(); + } + this.iOSContentState.addProperty(key, value); + return this; + } + + public Builder iOSContentState(String key, Boolean value) { + if (this.iOSContentState == null) { + this.iOSContentState = new JsonObject(); + } + this.iOSContentState.addProperty(key, value); + return this; + } + + public Builder iOSAlertTitle(String iOSAlertTitle) { + this.iOSAlertTitle = iOSAlertTitle; + return this; + } + + public Builder iOSAlertAlternateTitle(String iOSAlertAlternateTitle) { + this.iOSAlertAlternateTitle = iOSAlertAlternateTitle; + return this; + } + + public Builder iOSAlertBody(String iOSAlertBody) { + this.iOSAlertBody = iOSAlertBody; + return this; + } + + public Builder iOSAlertAlternateBody(String iOSAlertAlternateBody) { + this.iOSAlertAlternateBody = iOSAlertAlternateBody; + return this; + } + + public Builder iOSAlertSound(String iOSAlertSound) { + this.iOSAlertSound = iOSAlertSound; + return this; + } + + public Builder iOSDismissalDate(Integer iOSDismissalDate) { + this.iOSDismissalDate = iOSDismissalDate; + return this; + } + + public LiveActivity build() { + return new LiveActivity(apnsProduction, liveActivityId, iOSEvent, iOSContentState, iOSAlertTitle, iOSAlertAlternateTitle, iOSAlertBody, iOSAlertAlternateBody, iOSAlertSound, iOSDismissalDate); + } + + } + + @Override + public JsonElement toJSON() { + JsonObject jsonObject = new JsonObject(); + + JsonArray platformJsonArray = new JsonArray(); + platformJsonArray.add(new JsonPrimitive("ios")); + + JsonObject audienceJsonObject = new JsonObject(); + if (liveActivityId != null) { + audienceJsonObject.addProperty("live_activity_id", liveActivityId); + } + + JsonObject optionsJsonObject = new JsonObject(); + if (apnsProduction != null) { + optionsJsonObject.addProperty("apns_production", apnsProduction); + } + if (iOSAlertTitle != null || iOSAlertAlternateTitle != null || iOSAlertBody != null || iOSAlertAlternateBody != null || iOSAlertSound != null) { + optionsJsonObject.addProperty("alternate_set", true); + } + + JsonObject liveActivityJsonObject = new JsonObject(); + JsonObject iOSJsonObject = new JsonObject(); + JsonObject alertJsonObject = new JsonObject(); + + if (iOSAlertTitle != null) { + alertJsonObject.addProperty("title", iOSAlertTitle); + } + if (iOSAlertAlternateTitle != null) { + alertJsonObject.addProperty("alternate_title", iOSAlertAlternateTitle); + } + if (iOSAlertBody != null) { + alertJsonObject.addProperty("body", iOSAlertBody); + } + if (iOSAlertAlternateBody != null) { + alertJsonObject.addProperty("alternate_body", iOSAlertAlternateBody); + } + if (iOSAlertSound != null) { + alertJsonObject.addProperty("sound", iOSAlertSound); + } + + if (iOSEvent != null) { + iOSJsonObject.addProperty("event", iOSEvent); + } + if (iOSContentState != null) { + iOSJsonObject.add("content-state", iOSContentState); + } + if (!alertJsonObject.entrySet().isEmpty()) { + iOSJsonObject.add("alert", alertJsonObject); + } + if (iOSDismissalDate != null) { + iOSJsonObject.addProperty("dismissal-date", iOSDismissalDate); + } + + if (!iOSJsonObject.entrySet().isEmpty()) { + liveActivityJsonObject.add("ios", iOSJsonObject); + } + + jsonObject.add("platform", platformJsonArray); + jsonObject.add("audience", audienceJsonObject); + jsonObject.add("live_activity", liveActivityJsonObject); + jsonObject.add("options", optionsJsonObject); + return jsonObject; + } + +} diff --git a/src/main/java/cn/jpush/api/push/model/live_activity/LiveActivityEvent.java b/src/main/java/cn/jpush/api/push/model/live_activity/LiveActivityEvent.java new file mode 100644 index 00000000..4f53e546 --- /dev/null +++ b/src/main/java/cn/jpush/api/push/model/live_activity/LiveActivityEvent.java @@ -0,0 +1,24 @@ +package cn.jpush.api.push.model.live_activity; + +public enum LiveActivityEvent { + + UPDATE("update", "更新"), + END("end", "结束,dismissal-date为结束展示时间"); + + private String value; + private String describe; + + LiveActivityEvent(String value, String describe) { + this.value = value; + this.describe = describe; + } + + public String getValue() { + return this.value; + } + + public String getDescribe() { + return this.describe; + } + +} diff --git a/src/test/java/cn/jpush/api/push/model/LiveActivityTest.java b/src/test/java/cn/jpush/api/push/model/LiveActivityTest.java new file mode 100644 index 00000000..a25955ed --- /dev/null +++ b/src/test/java/cn/jpush/api/push/model/LiveActivityTest.java @@ -0,0 +1,38 @@ +package cn.jpush.api.push.model; + +import cn.jiguang.common.resp.APIConnectionException; +import cn.jiguang.common.resp.APIRequestException; +import cn.jpush.api.FastTests; +import cn.jpush.api.JPushClient; +import cn.jpush.api.push.PushResult; +import cn.jpush.api.push.model.live_activity.LiveActivity; +import cn.jpush.api.push.model.live_activity.LiveActivityEvent; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(FastTests.class) +public class LiveActivityTest { + + @Test + public void send() { + LiveActivity liveActivity = new LiveActivity.Builder() + .liveActivityId("LiveActivity-1") + .apnsProduction(false) + .iOSEvent(LiveActivityEvent.UPDATE) + .iOSContentState("eventStr", "你好") + .iOSContentState("eventTime", System.currentTimeMillis()) + .build(); + System.out.println("send liveActivity param:" + liveActivity.toJSON()); + + try { + JPushClient pushClient = new JPushClient("8d8623440ff329ff38597da3", "2785bc46145eaa91a00c0728"); + PushResult pushResult = pushClient.sendLiveActivity(liveActivity); + System.out.println("send liveActivity result:" + pushResult); + } catch (APIConnectionException e) { + throw new RuntimeException(e); + } catch (APIRequestException e) { + throw new RuntimeException(e); + } + } + +}