diff --git a/README.md b/README.md index 40c55d37..185e9c2e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ +# 新版 SDK +欢迎使用新一代 [jiguang-sdk-java](https://github.com/jpush/jiguang-sdk-java)!这个 SDK 旨在提供更好的性能、更多功能和更好的用户体验。 + +为什么升级? +* 性能优化:新版本经过优化,运行更快,消耗更少的资源。 +* 功能增强:引入了许多新功能和改进,使您的开发工作更加高效。 +* Bug 修复:解决了上个版本存在的问题,提高了稳定性和可靠性。 + +> 极光已推出新版本的 SDK 供广大用户使用,当前版本后续将不推荐使用,请移步仓库 [jiguang-sdk-java](https://github.com/jpush/jiguang-sdk-java) 了解更多。 + +# ~~旧版 SDK~~ + [![GitHub version](https://badge.fury.io/gh/jpush%2Fjpush-api-java-client.svg)](http://badge.fury.io/gh/jpush%2Fjpush-api-java-client) # JPush API Java Library diff --git a/pom.xml b/pom.xml index 65d76ebb..7a3330df 100644 --- a/pom.xml +++ b/pom.xml @@ -3,25 +3,17 @@ cn.jpush.api jpush-client - 3.5.2 + 3.7.8 jar https://github.com/jpush/jpush-api-java-client JPush API Java Client JPush's officially supported Java client library for accessing JPush APIs. - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - github UTF-8 - 1.7 - 1.7 + 1.6 + 1.6 @@ -51,7 +43,7 @@ cn.jpush.api jiguang-common - 1.1.11 + 1.2.7 org.apache.httpcomponents @@ -108,7 +100,7 @@ junit junit - 4.11 + 4.13.1 test @@ -131,218 +123,4 @@ - - - - maven-compiler-plugin - 3.1 - - ${jdkVersion} - ${jdkVersion} - 1.5 - true - true - true - true - - -Xlint:unchecked - - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.1 - - - org.apache.maven.plugins - maven-scm-plugin - 1.9.2 - - - - deploy,site - false - true - true - v@{project.version} - - - - - com.github.github - site-maven-plugin - 0.9 - - Creating site for ${project.version} - github - - - - - site - - site - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.17 - - cn.jpush.api.FastTests - -Dfile.encoding=UTF-8 - - **/mock/*Test.java - - - - - org.apache.maven.surefire - surefire-junit47 - 2.17 - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.17 - - UTF-8 - cn.jpush.api.SlowTests - -Dfile.encoding=UTF-8 - - **/mock/*Test.java - - - - - - integration-test - verify - - - - **/*.class - - - - - - - org.apache.maven.surefire - surefire-junit47 - 2.17 - - - - - - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://oss.sonatype.org/ - - false - - - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots/ - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.8 - - - - dependencies - license - scm - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - resources/javadoc-overview.html - - - - - - 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/admin/AdminClient.java b/src/main/java/cn/jpush/api/admin/AdminClient.java index 040b791b..57bce1c2 100644 --- a/src/main/java/cn/jpush/api/admin/AdminClient.java +++ b/src/main/java/cn/jpush/api/admin/AdminClient.java @@ -115,8 +115,8 @@ public void uploadCertificate(String appKey, String devCertificateFile, String d NativeHttpClient client = (NativeHttpClient) mHttpClient; String url = mBasePath + mV1AppPath + "/" + appKey + "/certificate"; - Map fileMap = new HashMap<>(); - Map textMap = new HashMap<>(); + Map fileMap = new HashMap(); + Map textMap = new HashMap(); if(devCertificateFile != null) { textMap.put("devCertificatePassword", devCertificatePassword); diff --git a/src/main/java/cn/jpush/api/file/FileClient.java b/src/main/java/cn/jpush/api/file/FileClient.java index ac38257d..da1ac10f 100644 --- a/src/main/java/cn/jpush/api/file/FileClient.java +++ b/src/main/java/cn/jpush/api/file/FileClient.java @@ -46,22 +46,29 @@ public FileClient(String masterSecret, String appKey, HttpProxy proxy, ClientCon this._httpClient = new NativeHttpClient(authCode, proxy, conf); } - public FileUploadResult uploadFile(FileType type, String filename) + public FileUploadResult uploadFile(FileType type, String filename, Integer ttl) throws APIConnectionException, APIRequestException { Preconditions.checkArgument(type != null, "type should not be null"); Preconditions.checkArgument(StringUtils.isNotEmpty(filename), "filename should not be null"); + Preconditions.checkArgument(ttl >= 1 && ttl <= 720,"TTL is not in the range of 1 to 720"); NativeHttpClient client = (NativeHttpClient) _httpClient; String typeStr = type.value(); String url = _baseUrl + _filesPath + "/" + typeStr; - Map fileMap = new HashMap<>(); + Map fileMap = new HashMap(); fileMap.put("filename", filename); - String response = client.formUploadByPost(url, null, fileMap, null); + Map textMap = new HashMap(); + textMap.put("ttl",String.valueOf(ttl)); + String response = client.formUploadByPost(url, textMap, fileMap, null); LOG.info("uploadFile:{}", response); return _gson.fromJson(response, new TypeToken() { }.getType()); } + public FileUploadResult uploadFile(FileType type, String filename) throws APIConnectionException, APIRequestException { + return uploadFile(type,filename,720); + } + public FileModelPage queryEffectFiles() throws APIConnectionException, APIRequestException { String url = _baseUrl + _filesPath + "/"; ResponseWrapper response = _httpClient.sendGet(url); diff --git a/src/main/java/cn/jpush/api/image/ImageClient.java b/src/main/java/cn/jpush/api/image/ImageClient.java index 0ec491f2..101f78c7 100644 --- a/src/main/java/cn/jpush/api/image/ImageClient.java +++ b/src/main/java/cn/jpush/api/image/ImageClient.java @@ -79,17 +79,14 @@ public ImageUploadResult uploadImage(ImageUrlPayload imageUrlPayload) * Upload image by file. Require at least 1 non-null fileName. Currently only support Xiaomi and OPPO * @param imageFilePayload image file payload * @return {@link ImageUploadResult} - * @throws APIConnectionException connect exception - * @throws APIRequestException request exception */ - public ImageUploadResult uploadImage(ImageFilePayload imageFilePayload) - throws APIConnectionException, APIRequestException{ + public ImageUploadResult uploadImage(ImageFilePayload imageFilePayload) { Preconditions.checkArgument(imageFilePayload.getImageType() != null, "Image type should not be null"); checkImageFilePayload(imageFilePayload); NativeHttpClient client = (NativeHttpClient) _httpClient; String url = _baseUrl + _imagesPath + "/" + ImageSource.FILE.value(); - Map textMap = new HashMap<>(); + Map textMap = new HashMap(); textMap.put("image_type", String.valueOf(imageFilePayload.getImageType().value())); Map fileMap = imageFilePayload.toFileMap(); @@ -139,11 +136,8 @@ public ImageUploadResult modifyImage(String mediaId, ImageUrlPayload imageUrlPay * @param mediaId media id * @param imageFilePayload image file payload * @return {@link ImageUploadResult} - * @throws APIConnectionException connection exception - * @throws APIRequestException request exception */ - public ImageUploadResult modifyImage(String mediaId, ImageFilePayload imageFilePayload) - throws APIConnectionException, APIRequestException { + public ImageUploadResult modifyImage(String mediaId, ImageFilePayload imageFilePayload) { Preconditions.checkArgument(StringUtils.isNotEmpty(mediaId), "mediaId should not be empty"); checkImageFilePayload(imageFilePayload); NativeHttpClient client = (NativeHttpClient) _httpClient; @@ -181,4 +175,4 @@ private void checkImageFilePayload(ImageFilePayload imageFilePayload) { } -} +} \ No newline at end of file diff --git a/src/main/java/cn/jpush/api/image/model/ImageFilePayload.java b/src/main/java/cn/jpush/api/image/model/ImageFilePayload.java index 7a4be086..f8143484 100644 --- a/src/main/java/cn/jpush/api/image/model/ImageFilePayload.java +++ b/src/main/java/cn/jpush/api/image/model/ImageFilePayload.java @@ -22,7 +22,7 @@ public class ImageFilePayload { private String jiguangFileName; public Map toFileMap() { - HashMap fileMap = new HashMap<>(); + HashMap fileMap = new HashMap(); if (null != oppoFileName) { fileMap.put(OPPO_IMAGE_FILE, oppoFileName); } diff --git a/src/main/java/cn/jpush/api/push/PushClient.java b/src/main/java/cn/jpush/api/push/PushClient.java index e0262406..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,6 +59,10 @@ 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); + } + /** * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig} instead of this constructor. * @@ -375,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/Message.java b/src/main/java/cn/jpush/api/push/model/Message.java index e57c5641..b87f5b6a 100644 --- a/src/main/java/cn/jpush/api/push/model/Message.java +++ b/src/main/java/cn/jpush/api/push/model/Message.java @@ -22,18 +22,20 @@ public class Message implements PushModel { private static final String MSG_CONTENT = "msg_content"; private static final String TITLE = "title"; private static final String CONTENT_TYPE = "content_type"; + private static final String TEST_MESSAGE = "test_message"; private static final String EXTRAS = "extras"; private final String msgContent; private final String title; private final String contentType; + private final Boolean testMessage; private final Map extras; private final Map numberExtras; private final Map booleanExtras; private final Map jsonExtras; private final Map customData; - private Message(String title, String msgContent, String contentType, + private Message(String title, String msgContent, String contentType, Boolean testMessage, Map extras, Map numberExtras, Map booleanExtras, @@ -42,6 +44,7 @@ private Message(String title, String msgContent, String contentType, this.title = title; this.msgContent = msgContent; this.contentType = contentType; + this.testMessage = testMessage; this.extras = extras; this.numberExtras = numberExtras; this.booleanExtras = booleanExtras; @@ -69,6 +72,9 @@ public JsonElement toJSON() { if (null != contentType) { json.add(CONTENT_TYPE, new JsonPrimitive(contentType)); } + if (null != testMessage) { + json.add(TEST_MESSAGE, new JsonPrimitive(testMessage)); + } JsonObject extrasObject = null; if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras) { @@ -118,6 +124,7 @@ public static class Builder { private String title; private String msgContent; private String contentType; + private Boolean testMessage; private Map extrasBuilder; private Map numberExtrasBuilder; private Map booleanExtrasBuilder; @@ -139,6 +146,11 @@ public Builder setContentType(String contentType) { return this; } + public Builder setTestMessage(Boolean testMessage) { + this.testMessage = testMessage; + return this; + } + public Builder addExtra(String key, String value) { Preconditions.checkArgument(!(null == key || null == value), "Key/Value should not be null."); if (null == extrasBuilder) { @@ -188,7 +200,7 @@ public Builder addExtra(String key, JsonObject value) { public Builder addCustom(Map extras) { if (customData == null) { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } for (Map.Entry entry : extras.entrySet()) { customData.put(entry.getKey(), new JsonPrimitive(entry.getValue())); @@ -199,7 +211,7 @@ public Builder addCustom(Map extras) { public Builder addCustom(String key, Number value) { Preconditions.checkArgument(!(null == key), "Key should not be null."); if (customData == null) { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } customData.put(key, new JsonPrimitive(value)); return this; @@ -208,7 +220,7 @@ public Builder addCustom(String key, Number value) { public Builder addCustom(String key, String value) { Preconditions.checkArgument(!(null == key), "Key should not be null."); if (customData == null) { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } customData.put(key, new JsonPrimitive(value)); return this; @@ -217,7 +229,7 @@ public Builder addCustom(String key, String value) { public Builder addCustom(String key, Boolean value) { Preconditions.checkArgument(!(null == key), "Key should not be null."); if (customData == null) { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } customData.put(key, new JsonPrimitive(value)); return this; @@ -226,7 +238,7 @@ public Builder addCustom(String key, Boolean value) { public Message build() { Preconditions.checkArgument(!(null == msgContent), "msgContent should be set"); - return new Message(title, msgContent, contentType, + return new Message(title, msgContent, contentType, testMessage, extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder, customData); } } diff --git a/src/main/java/cn/jpush/api/push/model/Notification3rd.java b/src/main/java/cn/jpush/api/push/model/Notification3rd.java index 7d0bd71b..ef78e8ad 100644 --- a/src/main/java/cn/jpush/api/push/model/Notification3rd.java +++ b/src/main/java/cn/jpush/api/push/model/Notification3rd.java @@ -14,7 +14,7 @@ * 使用说明 * notification_3rd 只针对开通了厂商通道的用户生效; * notification 和 notification_3rd 不能同时有内容,如果这两块同时有内容,则会返回错误提示; - * notification_3rd 的内容对 iOS 和 WinPhone 平台无效,只针对 Android 平台生效; + * notification_3rd 的内容对 iOS 和 HMOS 平台无效,只针对 Android 平台生效; * notification_3rd 是用作补发厂商通知的内容,只有当 message 部分有内容,才允许传递此字段,且要两者都不为空时,才会对离线的厂商设备转发厂商通道的通知。 */ public class Notification3rd implements PushModel{ @@ -24,6 +24,7 @@ public class Notification3rd implements PushModel{ private static final String URI_ACTIVITY = "uri_activity"; private static final String URI_ACTION = "uri_action"; private static final String BADGE_ADD_NUM = "badge_add_num"; + private static final String BADGE_SET_NUM = "badge_set_num"; private static final String BADGE_CLASS = "badge_class"; private static final String SOUND = "sound"; private static final String EXTRAS = "extras"; @@ -35,6 +36,7 @@ public class Notification3rd implements PushModel{ private final String uri_activity; private final String uri_action; private final int badge_add_num; + private final int badge_set_num; private final String badge_class; private final String sound; private final Map extras; @@ -43,7 +45,7 @@ public class Notification3rd implements PushModel{ private final Map jsonExtras; private Notification3rd(String title, String content, String channel_id, - String uri_activity, String uri_action, int badge_add_num, + String uri_activity, String uri_action, int badge_add_num,int badge_set_num, String badge_class, String sound, Map extras, Map numberExtras, @@ -55,6 +57,7 @@ private Notification3rd(String title, String content, String channel_id, this.uri_activity = uri_activity; this.uri_action = uri_action; this.badge_add_num = badge_add_num; + this.badge_set_num = badge_set_num; this.badge_class = badge_class; this.sound = sound; this.extras = extras; @@ -97,6 +100,10 @@ public JsonElement toJSON() { json.addProperty(BADGE_ADD_NUM, badge_add_num); } + if (0 != badge_set_num) { + json.addProperty(BADGE_SET_NUM, badge_set_num); + } + if (null != badge_class) { json.addProperty(BADGE_CLASS, badge_class); } @@ -164,6 +171,7 @@ public static class Builder{ private String uri_activity; private String uri_action; private int badge_add_num; + private int badge_set_num; private String badge_class; private String sound; protected Map extrasBuilder; @@ -201,6 +209,11 @@ public Builder setBadgeAddNum(int badge_add_num) { return this; } + public Builder setBadgeSetNum(int badge_set_num) { + this.badge_set_num = badge_set_num; + return this; + } + public Builder setBadgeClass(String badge_class) { this.badge_class = badge_class; return this; @@ -263,7 +276,7 @@ public Builder addExtra(String key, JsonObject value) { public Notification3rd build() { Preconditions.checkArgument(content != null && content != "", "content should not be null or empty"); - return new Notification3rd(title, content, channel_id, uri_activity, uri_action, badge_add_num, + return new Notification3rd(title, content, channel_id, uri_activity, uri_action, badge_add_num, badge_set_num, badge_class, sound, extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder); } } diff --git a/src/main/java/cn/jpush/api/push/model/Options.java b/src/main/java/cn/jpush/api/push/model/Options.java index 0e0f07e6..dfcae593 100644 --- a/src/main/java/cn/jpush/api/push/model/Options.java +++ b/src/main/java/cn/jpush/api/push/model/Options.java @@ -11,6 +11,22 @@ import java.util.Map; import java.util.Set; +/** + * 参考文档:https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push#options + * + *

Options

+ *
+ * + */ public class Options implements PushModel { private static final String SENDNO = "sendno"; @@ -20,6 +36,7 @@ public class Options implements PushModel { private static final String BIG_PUSH_DURATION = "big_push_duration"; private static final String APNS_COLLAPSE_ID = "apns_collapse_id"; private static final String THIRD_PARTH_CHANNEl = "third_party_channel"; + private static final String CLASSIFICATION = "classification"; private static final long NONE_TIME_TO_LIVE = -1; @@ -30,38 +47,12 @@ public class Options implements PushModel { // minutes private int bigPushDuration; private String apnsCollapseId; - private final Map customData; - - + private int classification; /** - * { - * "third_party_channel":{ - * "xiaomi":{ - * "distribution":"ospush", - * "channel_id":"*******" - * }, - * "huawei":{ - * "distribution":"jpush" - * }, - * "meizu":{ - * "distribution":"jpush" - * }, - * "fcm":{ - * "distribution":"ospush" - * }, - * "oppo":{ - * "distribution":"ospush", - * "channel_id":"*******" - * }, - * "vivo":{ - * "distribution":"ospush", - * "classification":0 // 2020/06 新增,和vivo官方字段含义一致 0 代表运营消息,1 代表系统消息,不填vivo官方默认为0 - * // 使用此字段时,需使用setThirdPartyChannelV2方法,因为此值只能为整数形式 - * } - * } - * } + * 参考:https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push#third_party_channel-%E8%AF%B4%E6%98%8E */ private Map thirdPartyChannel; + private final Map customData; private Options(int sendno, long overrideMsgId, @@ -69,6 +60,7 @@ private Options(int sendno, boolean apnsProduction, int bigPushDuration, String apnsCollapseId, + int classification, Map thirdPartyChannel, Map customData) { this.sendno = sendno; @@ -77,6 +69,7 @@ private Options(int sendno, this.apnsProduction = apnsProduction; this.bigPushDuration = bigPushDuration; this.apnsCollapseId = apnsCollapseId; + this.classification = classification; this.thirdPartyChannel = thirdPartyChannel; this.customData = customData; } @@ -132,6 +125,8 @@ public JsonElement toJSON() { json.add(APNS_COLLAPSE_ID, new JsonPrimitive(apnsCollapseId)); } + json.add(CLASSIFICATION, new JsonPrimitive(classification)); + if (null != thirdPartyChannel && thirdPartyChannel.size() > 0) { JsonObject partyChannel = new JsonObject(); for (Map.Entry entry : thirdPartyChannel.entrySet()) { @@ -158,6 +153,7 @@ public static class Builder { private boolean apnsProduction = false; private int bigPushDuration = 0; private String apnsCollapseId; + private int classification; private Map thirdPartyChannel; private Map customData; @@ -191,15 +187,20 @@ public Builder setBigPushDuration(int bigPushDuration) { return this; } + public Builder setClassification(int classification) { + this.classification = classification; + return this; + } + @Deprecated public Map> getThirdPartyChannel() { if (null != thirdPartyChannel) { - Map> thirdPartyChannelRsp = new HashMap<>(); + Map> thirdPartyChannelRsp = new HashMap>(); Set> entrySet = thirdPartyChannel.entrySet(); for (Map.Entry entry : entrySet) { JsonObject entryValue = entry.getValue(); Set> valueEntrySet = entryValue.entrySet(); - Map valueMap = new HashMap<>(); + Map valueMap = new HashMap(); for (Map.Entry valueEntry : valueEntrySet) { valueMap.put(valueEntry.getKey(), null == valueEntry.getValue() ? null : valueEntry.getValue().getAsString()); } @@ -212,7 +213,7 @@ public Map> getThirdPartyChannel() { @Deprecated public Builder setThirdPartyChannel(Map> thirdPartyChannel) { - this.thirdPartyChannel = new HashMap<>(); + this.thirdPartyChannel = new HashMap(); if (null != thirdPartyChannel) { Set>> entrySet = thirdPartyChannel.entrySet(); for (Map.Entry> entry : entrySet) { @@ -239,7 +240,7 @@ public Builder setThirdPartyChannelV2(Map thirdPartyChannel) public Builder addCustom(Map extras) { if (customData == null) { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } for (Map.Entry entry : extras.entrySet()) { customData.put(entry.getKey(), new JsonPrimitive(entry.getValue())); @@ -248,27 +249,27 @@ public Builder addCustom(Map extras) { } public Builder addCustom(String key, Number value) { - Preconditions.checkArgument(! (null == key), "Key should not be null."); + Preconditions.checkArgument(!(null == key), "Key should not be null."); if (customData == null) { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } customData.put(key, new JsonPrimitive(value)); return this; } public Builder addCustom(String key, String value) { - Preconditions.checkArgument(! (null == key), "Key should not be null."); + Preconditions.checkArgument(!(null == key), "Key should not be null."); if (customData == null) { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } customData.put(key, new JsonPrimitive(value)); return this; } public Builder addCustom(String key, Boolean value) { - Preconditions.checkArgument(! (null == key), "Key should not be null."); + Preconditions.checkArgument(!(null == key), "Key should not be null."); if (customData == null) { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } customData.put(key, new JsonPrimitive(value)); return this; @@ -284,7 +285,7 @@ public Options build() { sendno = ServiceHelper.generateSendno(); } - return new Options(sendno, overrideMsgId, timeToLive, apnsProduction, bigPushDuration, apnsCollapseId, thirdPartyChannel, customData); + return new Options(sendno, overrideMsgId, timeToLive, apnsProduction, bigPushDuration, apnsCollapseId, classification, thirdPartyChannel, customData); } } diff --git a/src/main/java/cn/jpush/api/push/model/Platform.java b/src/main/java/cn/jpush/api/push/model/Platform.java index 406bf35a..eddeff42 100644 --- a/src/main/java/cn/jpush/api/push/model/Platform.java +++ b/src/main/java/cn/jpush/api/push/model/Platform.java @@ -12,7 +12,7 @@ /** * https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#platform * - * JPush 当前支持 Android, iOS, QuickApp,Windows Phone 四个平台的推送。其关键字分别为:"android", "ios", "quickapp","winphone"。 + * JPush 当前支持 Android, iOS, QuickApp, HMOS 四个平台的推送。其关键字分别为:"android", "ios", "quickapp","hmos"。 * 使用方法,只需要在PushPayload中调用setPlatform方法。如:setPlatform(Platform.android_ios()) * 如需要全平台推送,只需要setPlatform(Platform.all()) */ @@ -47,8 +47,8 @@ public static Platform quickapp() { return newBuilder().addDeviceType(DeviceType.QuickApp).build(); } - public static Platform winphone() { - return newBuilder().addDeviceType(DeviceType.WinPhone).build(); + public static Platform hmos() { + return newBuilder().addDeviceType(DeviceType.HMOS).build(); } public static Platform android_ios() { @@ -58,17 +58,17 @@ public static Platform android_ios() { .build(); } - public static Platform android_winphone() { + public static Platform android_hmos() { return newBuilder() .addDeviceType(DeviceType.Android) - .addDeviceType(DeviceType.WinPhone) + .addDeviceType(DeviceType.HMOS) .build(); } - public static Platform ios_winphone() { + public static Platform ios_hmos() { return newBuilder() .addDeviceType(DeviceType.IOS) - .addDeviceType(DeviceType.WinPhone) + .addDeviceType(DeviceType.HMOS) .build(); } @@ -86,10 +86,10 @@ public static Platform ios_quickapp() { .build(); } - public static Platform quickapp_winphone() { + public static Platform quickapp_hmos() { return newBuilder() .addDeviceType(DeviceType.QuickApp) - .addDeviceType(DeviceType.WinPhone) + .addDeviceType(DeviceType.HMOS) .build(); } @@ -101,27 +101,27 @@ public static Platform android_ios_quickapp() { .build(); } - public static Platform android_ios_winphone() { + public static Platform android_ios_hmos() { return newBuilder() .addDeviceType(DeviceType.Android) .addDeviceType(DeviceType.IOS) - .addDeviceType(DeviceType.WinPhone) + .addDeviceType(DeviceType.HMOS) .build(); } - public static Platform android_quickapp_winphone() { + public static Platform android_quickapp_hmos() { return newBuilder() .addDeviceType(DeviceType.Android) .addDeviceType(DeviceType.QuickApp) - .addDeviceType(DeviceType.WinPhone) + .addDeviceType(DeviceType.HMOS) .build(); } - public static Platform ios_quickapp_winphone() { + public static Platform ios_quickapp_hmos() { return newBuilder() .addDeviceType(DeviceType.IOS) .addDeviceType(DeviceType.QuickApp) - .addDeviceType(DeviceType.WinPhone) + .addDeviceType(DeviceType.HMOS) .build(); } diff --git a/src/main/java/cn/jpush/api/push/model/PushPayload.java b/src/main/java/cn/jpush/api/push/model/PushPayload.java index 9ab26205..e3030924 100644 --- a/src/main/java/cn/jpush/api/push/model/PushPayload.java +++ b/src/main/java/cn/jpush/api/push/model/PushPayload.java @@ -284,7 +284,7 @@ public static class Builder { private Map custom; public Builder() { - this.custom = new LinkedHashMap<>(); + this.custom = new LinkedHashMap(); } public Builder setTarget(String target) { diff --git a/src/main/java/cn/jpush/api/push/model/audience/Audience.java b/src/main/java/cn/jpush/api/push/model/audience/Audience.java index 1707bdd3..3aad28c9 100644 --- a/src/main/java/cn/jpush/api/push/model/audience/Audience.java +++ b/src/main/java/cn/jpush/api/push/model/audience/Audience.java @@ -145,7 +145,7 @@ public static Audience fromJsonElement(JsonElement jsonElement) { } boolean file = false; JsonObject jsonObject = jsonElement.getAsJsonObject(); - Set audienceTargetSet = new HashSet<>(); + Set audienceTargetSet = new HashSet(); for (AudienceType type : AudienceType.values()) { JsonArray jsonArray = jsonObject.getAsJsonArray(type.value()); if (jsonArray == null) { diff --git a/src/main/java/cn/jpush/api/push/model/audience/AudienceTarget.java b/src/main/java/cn/jpush/api/push/model/audience/AudienceTarget.java index 527dd908..47b6f4e5 100644 --- a/src/main/java/cn/jpush/api/push/model/audience/AudienceTarget.java +++ b/src/main/java/cn/jpush/api/push/model/audience/AudienceTarget.java @@ -114,7 +114,7 @@ public JsonElement toFileJSON() { } public static AudienceTarget fromJsonElement(JsonArray jsonArray, AudienceType type) { - Set stringSet = new HashSet<>(); + Set stringSet = new HashSet(); if (jsonArray != null) { for (int i=0; iHMOS Phone 通知类

+ *
+ * 具体使用方法请参考官方文档 https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#platform + * 支持 HMOS Notification 的参数: + *
    + *
  • alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。
  • + *
  • title: 支持 setTitle(string) 方法来设置;可替换通知标题。
  • + *
  • _open_page: 支持 setOpenPage(String) 方法来设置;可设置点击打开的页面名称
  • + *
  • extras: 继承自父类 PlatformNotification 的 extras 属性;支持通过 addExtra(key, value) 来添加自定义字段,具体看代码。
  • + *
+ *
+ */ +public class HmosNotification extends PlatformNotification { + private static final String NOTIFICATION_HMOS = "hmos"; + + private static final String TITLE = "title"; + private static final String CATEGORY = "category"; + private static final String LARGE_ICON = "large_icon"; + private static final String INTENT = "intent"; + private static final String BADGE_ADD_NUM = "badge_add_num"; + private static final String TEST_MESSAGE = "test_message"; + private static final String RECEIPT_ID = "receipt_id"; + + private final String title; + private final String category; + private final String large_icon; + private final JsonObject intent; + private final Integer badge_add_num; + private final Boolean test_message; + private final String receipt_id; + + private HmosNotification(Object alert, + String title, + String category, + String large_icon, + JsonObject intent, + Integer badge_add_num, + Boolean test_message, + String receipt_id, + Map extras, + Map numberExtras, + Map booleanExtras, + Map jsonExtras, + Map customData) { + super(alert, extras, numberExtras, booleanExtras, jsonExtras, customData); + + this.title = title; + this.category = category; + this.large_icon = large_icon; + this.intent = intent; + this.badge_add_num = badge_add_num; + this.test_message = test_message; + this.receipt_id = receipt_id; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public static HmosNotification alert(String alert) { + return newBuilder().setAlert(alert).build(); + } + + + @Override + public String getPlatform() { + return NOTIFICATION_HMOS; + } + + @Override + public JsonElement toJSON() { + JsonObject json = super.toJSON().getAsJsonObject(); + + if (null != title) { + json.add(TITLE, new JsonPrimitive(title)); + } + if (null != category) { + json.add(CATEGORY, new JsonPrimitive(category)); + } + if (null != large_icon) { + json.add(LARGE_ICON, new JsonPrimitive(large_icon)); + } + if (null != intent) { + json.add(INTENT, intent); + } + if (null != badge_add_num) { + json.add(BADGE_ADD_NUM, new JsonPrimitive(badge_add_num)); + } + if (null != test_message) { + json.add(TEST_MESSAGE, new JsonPrimitive(test_message)); + } + if (null != receipt_id) { + json.add(RECEIPT_ID, new JsonPrimitive(receipt_id)); + } + return json; + } + + + public static class Builder extends PlatformNotification.Builder { + private String title; + private String category; + private String large_icon; + private JsonObject intent; + private Integer badge_add_num; + private Boolean test_message; + private String receipt_id; + + @Override + protected Builder getThis() { + return this; + } + + @Override + public Builder setAlert(Object alert) { + this.alert = alert; + return this; + } + + public Builder setTitle(String title) { + this.title = title; + return this; + } + + public Builder setCategory(String category) { + this.category = category; + return this; + } + + public Builder setLarge_icon(String large_icon) { + this.large_icon = large_icon; + return this; + } + + public Builder setIntent(JsonObject intent) { + this.intent = intent; + return this; + } + + public Builder setBadge_add_num(Integer badge_add_num) { + this.badge_add_num = badge_add_num; + return this; + } + + public Builder setTest_message(Boolean test_message) { + this.test_message = test_message; + return this; + } + + public Builder setReceipt_id(String receipt_id) { + this.receipt_id = receipt_id; + return this; + } + + public HmosNotification build() { + return new HmosNotification(alert, title, category,large_icon,intent,badge_add_num,test_message,receipt_id, + extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder, super.customData); + } + } +} diff --git a/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java b/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java index 4e7cf7ca..c8c844af 100644 --- a/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java +++ b/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java @@ -14,13 +14,15 @@ * 支持 APNs 默认的几个参数: *
    *
  • alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。
  • - *
  • badge: 支持 setBadge(int) 方法来设置;支持 incrBadge(int) 方法来增加。
  • *
  • sound: 支持 setSound(string) 方法来设置声音文件。或者 setSound(JSON object) 对应官方payload结构
  • + *
  • badge: 支持 setBadge(int) 方法来设置;支持 incrBadge(int) 方法来增加。
  • *
  • content-available: 用来支持后台推送。如果该值赋值为 1,表示开启后台推送。
  • *
  • mutable-content: 通知扩展
  • *
  • category: IOS 8 才支持。设置 APNs payload 中的 "category" 字段值
  • *
  • mutable-content: 通知扩展
  • *
  • extras: JSON object. 支持更多的自定义字段信息。
  • + *
  • thread-id: string. ios 的远程通知通过该属性来对通知进行分组,同一个 thread-id 的通知归为一组。
  • + *
  • interruption-level: string. ios 15 的通知级别,取值只能是 active,critical,passive,time-sensitive 中的一个,详情参考:UNNotificationInterruptionLevel。
  • *
*
* 需要特别留意的是,JPush SDK 会对以下几个值有特别的默认设置考虑: @@ -41,7 +43,8 @@ public class IosNotification extends PlatformNotification { private static final String MUTABLE_CONTENT = "mutable-content"; private static final String CATEGORY = "category"; private static final String THREAD_ID = "thread-id"; - + private static final String INTERRUPTION_LEVEL = "interruption-level"; + private static final String ALERT_VALID_BADGE = "Badge number should be 0~99999, " + "and can be prefixed with + to add, - to minus"; @@ -54,10 +57,11 @@ public class IosNotification extends PlatformNotification { private final String category; private final boolean mutableContent; private final String threadId; + private final String interruptionLevel; private IosNotification(Object alert, Object sound, String badge, boolean contentAvailable, boolean soundDisabled, boolean badgeDisabled, - String category, boolean mutableContent,String threadId, + String category, boolean mutableContent,String threadId,String interruptionLevel, Map extras, Map numberExtras, Map booleanExtras, @@ -73,6 +77,7 @@ private IosNotification(Object alert, Object sound, String badge, this.category = category; this.mutableContent = mutableContent; this.threadId = threadId; + this.interruptionLevel = interruptionLevel; } public static Builder newBuilder() { @@ -124,6 +129,9 @@ public JsonElement toJSON() { if (null != threadId) { json.add(THREAD_ID, new JsonPrimitive(threadId)); } + if (null != interruptionLevel) { + json.add(INTERRUPTION_LEVEL, new JsonPrimitive(interruptionLevel)); + } return json; } @@ -138,6 +146,7 @@ public static class Builder extends PlatformNotification.Builder extras) { + public static Notification hmos(String alert, String title, Map extras) { return newBuilder() - .addPlatformNotification(WinphoneNotification.newBuilder() + .addPlatformNotification(HmosNotification.newBuilder() .setAlert(alert) + .setTitle(title) .addExtras(extras) .build()) .build(); diff --git a/src/main/java/cn/jpush/api/push/model/notification/PlatformNotification.java b/src/main/java/cn/jpush/api/push/model/notification/PlatformNotification.java index 163efe3e..ac2272dc 100644 --- a/src/main/java/cn/jpush/api/push/model/notification/PlatformNotification.java +++ b/src/main/java/cn/jpush/api/push/model/notification/PlatformNotification.java @@ -36,7 +36,7 @@ public PlatformNotification(Object alert, Map extras, this.numberExtras = numberExtras; this.booleanExtras = booleanExtras; this.jsonExtras = jsonExtras; - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); } public PlatformNotification(Object alert, Map extras, @@ -142,7 +142,7 @@ protected abstract static class Builder customData; public Builder () { - customData = new LinkedHashMap<>(); + customData = new LinkedHashMap(); theBuilder = getThis(); } diff --git a/src/main/java/cn/jpush/api/push/model/notification/WinphoneNotification.java b/src/main/java/cn/jpush/api/push/model/notification/WinphoneNotification.java deleted file mode 100644 index aaef3f3e..00000000 --- a/src/main/java/cn/jpush/api/push/model/notification/WinphoneNotification.java +++ /dev/null @@ -1,103 +0,0 @@ -package cn.jpush.api.push.model.notification; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -import java.util.Map; - -/** - *

Windows Phone 通知类

- *
- * 具体使用方法请参考官方文档 https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#platform - * 支持 Winphone Notification 的参数: - *
    - *
  • alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。
  • - *
  • title: 支持 setTitle(string) 方法来设置;可替换通知标题。
  • - *
  • _open_page: 支持 setOpenPage(String) 方法来设置;可设置点击打开的页面名称
  • - *
  • extras: 继承自父类 PlatformNotification 的 extras 属性;支持通过 addExtra(key, value) 来添加自定义字段,具体看代码。
  • - *
- *
- */ -public class WinphoneNotification extends PlatformNotification { - private static final String NOTIFICATION_WINPHONE = "winphone"; - - private static final String TITLE = "title"; - private static final String _OPEN_PAGE = "_open_page"; - - private final String title; - private final String openPage; - - private WinphoneNotification(Object alert, String title, String openPage, - Map extras, - Map numberExtras, - Map booleanExtras, - Map jsonExtras, - Map customData) { - super(alert, extras, numberExtras, booleanExtras, jsonExtras, customData); - - this.title = title; - this.openPage = openPage; - } - - public static Builder newBuilder() { - return new Builder(); - } - - public static WinphoneNotification alert(String alert) { - return newBuilder().setAlert(alert).build(); - } - - - @Override - public String getPlatform() { - return NOTIFICATION_WINPHONE; - } - - @Override - public JsonElement toJSON() { - JsonObject json = super.toJSON().getAsJsonObject(); - - if (null != title) { - json.add(TITLE, new JsonPrimitive(title)); - } - if (null != openPage) { - json.add(_OPEN_PAGE, new JsonPrimitive(openPage)); - } - - return json; - } - - - public static class Builder extends PlatformNotification.Builder { - private String title; - private String openPage; - - @Override - protected Builder getThis() { - return this; - } - - public Builder setTitle(String title) { - this.title = title; - return this; - } - - public Builder setOpenPage(String openPage) { - this.openPage = openPage; - return this; - } - - @Override - public Builder setAlert(Object alert) { - this.alert = alert; - return this; - } - - - public WinphoneNotification build() { - return new WinphoneNotification(alert, title, openPage, - extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder, super.customData); - } - } -} diff --git a/src/main/java/cn/jpush/api/report/GroupMessageDetailResult.java b/src/main/java/cn/jpush/api/report/GroupMessageDetailResult.java index 155f1377..1f380f71 100644 --- a/src/main/java/cn/jpush/api/report/GroupMessageDetailResult.java +++ b/src/main/java/cn/jpush/api/report/GroupMessageDetailResult.java @@ -19,7 +19,7 @@ public class GroupMessageDetailResult extends BaseResult { private static final Type RECEIVED_TYPE = new TypeToken>() {}.getType(); @Expose - public List received_list = new ArrayList<>(); + public List received_list = new ArrayList(); public static class Received { @Expose diff --git a/src/main/java/cn/jpush/api/report/MessageDetailResult.java b/src/main/java/cn/jpush/api/report/MessageDetailResult.java index 942bfef8..7fe5b6f5 100644 --- a/src/main/java/cn/jpush/api/report/MessageDetailResult.java +++ b/src/main/java/cn/jpush/api/report/MessageDetailResult.java @@ -28,6 +28,8 @@ public static class Received { @Expose public JsonObject android_pns; @Expose + public JsonObject details; + @Expose public IosDetail ios; @Expose public WinphoeDetail winphone; diff --git a/src/main/java/cn/jpush/api/schedule/ScheduleClient.java b/src/main/java/cn/jpush/api/schedule/ScheduleClient.java index ec7514d5..d5efa7fc 100644 --- a/src/main/java/cn/jpush/api/schedule/ScheduleClient.java +++ b/src/main/java/cn/jpush/api/schedule/ScheduleClient.java @@ -23,6 +23,8 @@ public class ScheduleClient { private String hostName; private String schedulePath; + private PushClient pushClient; + // If not present, true by default. private int apnsProduction; @@ -81,6 +83,8 @@ public ScheduleClient(String masterSecret, String appKey, HttpProxy proxy, Clien schedulePath = (String) conf.get(ClientConfig.SCHEDULE_PATH); apnsProduction = (Integer) conf.get(ClientConfig.APNS_PRODUCTION); timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE); + //createSchedule接口需要用到这个类 + pushClient = new PushClient(masterSecret, appKey, proxy, conf); String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret); this._httpClient = new NativeHttpClient(authCode, proxy, conf); @@ -104,7 +108,6 @@ public ScheduleResult createSchedule(SchedulePayload payload, String masterSecre // 调用getCidList方法来获取cid并赋值到payload中 String cid = payload.getCid(); if (cid == null) { - PushClient pushClient = new PushClient(masterSecret, appKey); CIDResult cidResult = pushClient.getCidList(1 , "schedule"); payload.setCid(cidResult.cidlist.get(0)); } diff --git a/src/test/java/cn/jpush/api/BaseTest.java b/src/test/java/cn/jpush/api/BaseTest.java index 14aebb88..030f65c1 100644 --- a/src/test/java/cn/jpush/api/BaseTest.java +++ b/src/test/java/cn/jpush/api/BaseTest.java @@ -4,8 +4,8 @@ public abstract class BaseTest { - protected static final String APP_KEY = "d4ee2375846bc30fa51334f5"; - protected static final String MASTER_SECRET = "3f045fd404d09a8a1f38d791"; + protected static final String APP_KEY = "eb67142502ec9f5556875b9a"; + protected static final String MASTER_SECRET = "186aa57bc697c94f8698bbbf"; protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e"; protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c"; diff --git a/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java b/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java index 23197e31..701aa501 100644 --- a/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java +++ b/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java @@ -200,7 +200,7 @@ public void testBindMobile_empty() throws APIConnectionException, APIRequestExce @Test @TestOrder(order = 330) public void testRemoveDevicesFromAlias() throws APIConnectionException, APIRequestException { - Set toRemoveDevice = new HashSet<>(); + Set toRemoveDevice = new HashSet(); toRemoveDevice.add(REGISTRATION_ID1); DefaultResult result = jpushClient.removeDevicesFromAlias("alias1", toRemoveDevice); assertTrue(result.isResultOK()); diff --git a/src/test/java/cn/jpush/api/files/FileClient2.java b/src/test/java/cn/jpush/api/files/FileClient2.java new file mode 100644 index 00000000..b005aa1b --- /dev/null +++ b/src/test/java/cn/jpush/api/files/FileClient2.java @@ -0,0 +1,92 @@ +package cn.jpush.api.files; + +import cn.jiguang.common.ClientConfig; +import cn.jiguang.common.ServiceHelper; +import cn.jiguang.common.connection.HttpProxy; +import cn.jiguang.common.connection.IHttpClient; +import cn.jiguang.common.connection.NativeHttpClient; +import cn.jiguang.common.resp.APIConnectionException; +import cn.jiguang.common.resp.APIRequestException; +import cn.jiguang.common.resp.ResponseWrapper; +import cn.jiguang.common.utils.Preconditions; +import cn.jiguang.common.utils.StringUtils; +import cn.jpush.api.file.model.FileModel; +import cn.jpush.api.file.model.FileModelPage; +import cn.jpush.api.file.model.FileType; +import cn.jpush.api.file.model.FileUploadResult; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author daixuan + * @version 2020/2/23 19:38 + */ +public class FileClient2 { + + protected static final Logger LOG = LoggerFactory.getLogger(FileClient2.class); + + private IHttpClient _httpClient; + private String _baseUrl; + private String _filesPath; + private Gson _gson = new Gson(); + + public FileClient2(String masterSecret, String appKey) { + this(masterSecret, appKey, null, ClientConfig.getInstance()); + } + + public FileClient2(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) { + _baseUrl = (String) conf.get(ClientConfig.PUSH_HOST_NAME); + _filesPath = (String) conf.get(ClientConfig.V3_FILES_PATH); + String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret); + this._httpClient = new NativeHttpClient(authCode, proxy, conf); + } + + public String uploadFile(FileType type, String filename, Integer ttl) + throws APIConnectionException, APIRequestException { + Preconditions.checkArgument(type != null, "type should not be null"); + Preconditions.checkArgument(StringUtils.isNotEmpty(filename), "filename should not be null"); + Preconditions.checkArgument(ttl >= 1 && ttl <= 720,"TTL is not in the range of 1 to 720"); + NativeHttpClient client = (NativeHttpClient) _httpClient; + String typeStr = type.value(); + String url = _baseUrl + _filesPath + "/" + typeStr; + Map fileMap = new HashMap(); + fileMap.put("filename", filename); + Map textMap = new HashMap(); + textMap.put("ttl",String.valueOf(ttl)); + String response = client.formUploadByPost(url, textMap, fileMap, null); + LOG.info("uploadFile:{}", response); + return response; + } + + public String uploadFile(FileType type, String filename) throws APIConnectionException, APIRequestException { + return uploadFile(type,filename,720); + } + + public String queryEffectFiles() throws APIConnectionException, APIRequestException { + String url = _baseUrl + _filesPath + "/"; + ResponseWrapper response = _httpClient.sendGet(url); + LOG.info("queryEffFiles:{}", response); + return response.responseContent; + } + + public String queryFile(String fileId) throws APIConnectionException, APIRequestException { + Preconditions.checkArgument(StringUtils.isNotEmpty(fileId), "fileId should not be null"); + String url = _baseUrl + _filesPath + "/" + fileId; + ResponseWrapper response = _httpClient.sendGet(url); + LOG.info("queryFile:{}", response); + return response.responseContent; + } + + public ResponseWrapper deleteFile(String fileId) throws APIConnectionException, APIRequestException { + Preconditions.checkArgument(StringUtils.isNotEmpty(fileId), "fileId should not be null"); + String url = _baseUrl + _filesPath + "/" + fileId; + ResponseWrapper response = _httpClient.sendDelete(url); + LOG.info("deleteFile:{}", response); + return response; + } +} diff --git a/src/test/java/cn/jpush/api/files/FileClientTest.java b/src/test/java/cn/jpush/api/files/FileClientTest.java index 3de8fb0d..8151b628 100644 --- a/src/test/java/cn/jpush/api/files/FileClientTest.java +++ b/src/test/java/cn/jpush/api/files/FileClientTest.java @@ -79,6 +79,8 @@ public void testQueryFile() { @Test public void testDeleteFile() { FileClient fileClient = new FileClient(MASTER_SECRET, APP_KEY); + + try { fileClient.deleteFile(fileId); } catch (APIConnectionException e) { @@ -91,4 +93,8 @@ public void testDeleteFile() { LOG.info("Msg ID: " + e.getMsgId()); } } + + + + } diff --git a/src/test/java/cn/jpush/api/image/ImageClientTest.java b/src/test/java/cn/jpush/api/image/ImageClientTest.java index 849a2322..8999ce5d 100644 --- a/src/test/java/cn/jpush/api/image/ImageClientTest.java +++ b/src/test/java/cn/jpush/api/image/ImageClientTest.java @@ -73,9 +73,9 @@ public void testUploadImageByFile() throws NoSuchFieldException { .setXiaomiFileName("dir/xiaomiXX.jpg") .build(); ImageUploadResult imageUploadResult = spyClient.uploadImage(payload); - HashMap textMap = new HashMap<>(); + HashMap textMap = new HashMap(); textMap.put("image_type", "2"); - HashMap fileMap = new HashMap<>(); + HashMap fileMap = new HashMap(); fileMap.put("oppo_file", "oppoXX.jpg"); fileMap.put("xiaomi_file", "dir/xiaomiXX.jpg"); verify(mockIHttpClient).formUploadByPost("https://api.jpush.cn/v3/images/byfiles", textMap, fileMap, null); @@ -136,7 +136,7 @@ public void testModifyImageByFile() throws NoSuchFieldException { .setXiaomiFileName("dir/xiaomiXX.jpg") .build(); ImageUploadResult imageUploadResult = spyClient.modifyImage(mediaId, payload); - HashMap fileMap = new HashMap<>(); + HashMap fileMap = new HashMap(); fileMap.put("oppo_file", "oppoXX.jpg"); fileMap.put("xiaomi_file", "dir/xiaomiXX.jpg"); verify(mockIHttpClient).formUploadByPut("https://api.jpush.cn/v3/images/byfiles/" + mediaId, null, fileMap, null); diff --git a/src/test/java/cn/jpush/api/push/PushClientTest.java b/src/test/java/cn/jpush/api/push/PushClientTest.java index e67239ab..0453a462 100644 --- a/src/test/java/cn/jpush/api/push/PushClientTest.java +++ b/src/test/java/cn/jpush/api/push/PushClientTest.java @@ -13,7 +13,9 @@ import cn.jpush.api.push.model.Platform; import cn.jpush.api.push.model.audience.Audience; import cn.jpush.api.push.model.notification.*; +import com.google.gson.JsonObject; import io.netty.handler.codec.http.HttpMethod; +import lombok.SneakyThrows; import org.junit.Test; import cn.jiguang.common.connection.HttpProxy; @@ -216,4 +218,46 @@ private static PushPayload buildPushObject_android_cid() { .build(); } + @Test + public void testAlertType(){ + Notification notification = Notification.newBuilder() + .addPlatformNotification(AndroidNotification.newBuilder() + .setAlert("android内容") + .setTitle("android标题") + .setAlertType(-1) + .addCustom("uri_activity","uri_activity") + .addCustom("uri_action","uri_action") + .addExtra("a","a") + .build() + ).build(); + System.out.println(notification.toJSON()); + } + + @Test + @SneakyThrows + public void testHmos(){ + JsonObject intentJson = new JsonObject(); + intentJson.addProperty("url","scheme://hmos?key1=val1&key2=val2"); + Notification notification = Notification.newBuilder() + .addPlatformNotification(HmosNotification.newBuilder() + .setAlert("hmos内容") + .setTitle("hmos标题") + .setCategory("IM") + .setLarge_icon("https://www.jiguang.cn/largeIcon.jpg") + .setIntent(intentJson) + .setBadge_add_num(1) + .setTest_message(false) + .setReceipt_id("receipt_id_2024") + .addExtra("a","a") + .build() + ).build(); + JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY); + PushPayload payload = PushPayload.newBuilder() + .setAudience(Audience.all()) + .setPlatform(Platform.hmos()) + .setNotification(notification) + .build(); + jpushClient.sendPush(payload); + } + } diff --git a/src/test/java/cn/jpush/api/push/mock/BaseMockTest.java b/src/test/java/cn/jpush/api/push/mock/BaseMockTest.java index f04d831b..2ff188e8 100644 --- a/src/test/java/cn/jpush/api/push/mock/BaseMockTest.java +++ b/src/test/java/cn/jpush/api/push/mock/BaseMockTest.java @@ -30,7 +30,7 @@ public class BaseMockTest implements IMockTest { static { SUPPORT_PLATFORM.add("android"); SUPPORT_PLATFORM.add("ios"); - SUPPORT_PLATFORM.add("winphone"); + SUPPORT_PLATFORM.add("hmos"); SUPPORT_AUDIENCE.add("tag"); SUPPORT_AUDIENCE.add("tag_and"); diff --git a/src/test/java/cn/jpush/api/push/mock/ResponseErrorTest.java b/src/test/java/cn/jpush/api/push/mock/ResponseErrorTest.java index 537cef39..e4641414 100644 --- a/src/test/java/cn/jpush/api/push/mock/ResponseErrorTest.java +++ b/src/test/java/cn/jpush/api/push/mock/ResponseErrorTest.java @@ -112,13 +112,13 @@ public void invalidParams_notification_ios() { } @Test - public void invalidParams_notification_winphone() { + public void invalidParams_notification_hmos() { JsonObject payload = new JsonObject(); payload.add("platform", Platform.all().toJSON()); payload.add("audience", Audience.all().toJSON()); JsonObject notification = new JsonObject(); - notification.add("winphone", new JsonPrimitive(ALERT)); + notification.add("hmos", new JsonPrimitive(ALERT)); payload.add("notification", notification); System.out.println("json string: " + payload.toString()); @@ -219,15 +219,15 @@ public void lackOfParams_notification_ios_empty() { } @Test - public void lackOfParams_notification_winphone_empty() { + public void lackOfParams_notification_hmos_empty() { JsonObject payload = new JsonObject(); payload.add("platform", Platform.all().toJSON()); payload.add("audience", Audience.all().toJSON()); JsonObject notification = new JsonObject(); - JsonObject winphone = new JsonObject(); + JsonObject hmos = new JsonObject(); - notification.add("winphone", winphone); + notification.add("hmos", hmos); payload.add("notification", notification); System.out.println("json string: " + payload.toString()); @@ -275,16 +275,16 @@ public void lackOfParams_notification_ios_noalert() { } @Test - public void lackOfParams_notification_winphone_noalert() { + public void lackOfParams_notification_hmos_noalert() { JsonObject payload = new JsonObject(); payload.add("platform", Platform.all().toJSON()); payload.add("audience", Audience.all().toJSON()); JsonObject notification = new JsonObject(); - JsonObject winphone = new JsonObject(); - winphone.add("title", new JsonPrimitive("title")); + JsonObject hmos = new JsonObject(); + hmos.add("title", new JsonPrimitive("title")); - notification.add("winphone", winphone); + notification.add("hmos", hmos); payload.add("notification", notification); System.out.println("json string: " + payload.toString()); 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..b8d1a797 --- /dev/null +++ b/src/test/java/cn/jpush/api/push/model/LiveActivityTest.java @@ -0,0 +1,68 @@ +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 update() { + LiveActivity liveActivity = new LiveActivity.Builder() + .liveActivityId("LiveActivity-1") + .apnsProduction(false) + .iOSEvent(LiveActivityEvent.UPDATE) + .iOSContentState("eventStr", "更新") + .iOSContentState("eventTime", System.currentTimeMillis()) + .iOSContentState("eventBool", true) + // 需要联系商务开通 alternate_set 才能使用 + // .iOSAlertTitle("alertTitle") + // .iOSAlertAlternateTitle("alertAlternateTitle") + // .iOSAlertBody("alertBody") + // .iOSAlertAlternateBody("alertAlternateBody") + // .iOSAlertSound("alertSound") + .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); + } + } + + @Test + public void end() { + LiveActivity liveActivity = new LiveActivity.Builder() + .liveActivityId("LiveActivity-1") + .apnsProduction(false) + .iOSEvent(LiveActivityEvent.END) + .iOSContentState("eventStr", "结束") + .iOSContentState("eventTime", System.currentTimeMillis()) + .iOSDismissalDate((System.currentTimeMillis() / 1000) + 60) + .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); + } + } + +} diff --git a/src/test/java/cn/jpush/api/push/model/OptionsTest.java b/src/test/java/cn/jpush/api/push/model/OptionsTest.java index 09356610..e36dd9d1 100644 --- a/src/test/java/cn/jpush/api/push/model/OptionsTest.java +++ b/src/test/java/cn/jpush/api/push/model/OptionsTest.java @@ -136,8 +136,8 @@ public void testBigPushDuration() { public void testThirdPartyChannel() { int sendno = ServiceHelper.generateSendno(); - Map> thirdMap = new HashMap<>(); - Map huaweiMap = new HashMap<>(); + Map> thirdMap = new HashMap>(); + Map huaweiMap = new HashMap(); huaweiMap.put("distribution", "jpush"); thirdMap.put("huawei", huaweiMap); @@ -163,7 +163,7 @@ public void testThirdPartyChannel() { public void testThirdPartyChannelV2() { int sendno = ServiceHelper.generateSendno(); - Map thirdMap = new HashMap<>(); + Map thirdMap = new HashMap(); JsonObject vivoJsonObj = new JsonObject(); vivoJsonObj.addProperty("distribution", "ospush"); vivoJsonObj.addProperty("classification", 1); diff --git a/src/test/java/cn/jpush/api/push/model/notification/AndroidNotificationTest.java b/src/test/java/cn/jpush/api/push/model/notification/AndroidNotificationTest.java index 460c2cb2..c3748e4c 100644 --- a/src/test/java/cn/jpush/api/push/model/notification/AndroidNotificationTest.java +++ b/src/test/java/cn/jpush/api/push/model/notification/AndroidNotificationTest.java @@ -11,7 +11,6 @@ import java.util.HashMap; import java.util.Map; -import java.util.Objects; @Category(FastTests.class) public class AndroidNotificationTest { @@ -68,7 +67,7 @@ public void testExtra_nullvalue() { @Test public void testCustomParam() { - Map customParams = new HashMap<>(); + Map customParams = new HashMap(); customParams.put("custom_field1", "field1"); customParams.put("custom_field2", "field2"); customParams.put("custom_field3", "field3"); diff --git a/src/test/java/cn/jpush/api/push/model/notification/WinphoneNotificationTest.java b/src/test/java/cn/jpush/api/push/model/notification/HmosNotificationTest.java similarity index 61% rename from src/test/java/cn/jpush/api/push/model/notification/WinphoneNotificationTest.java rename to src/test/java/cn/jpush/api/push/model/notification/HmosNotificationTest.java index 9cadb938..bbee925a 100644 --- a/src/test/java/cn/jpush/api/push/model/notification/WinphoneNotificationTest.java +++ b/src/test/java/cn/jpush/api/push/model/notification/HmosNotificationTest.java @@ -10,33 +10,33 @@ import com.google.gson.JsonPrimitive; @Category(FastTests.class) -public class WinphoneNotificationTest { +public class HmosNotificationTest { @Test public void testEmpty() { - WinphoneNotification winphone = WinphoneNotification.newBuilder().build(); - Assert.assertEquals("", new JsonObject(), winphone.toJSON()); + HmosNotification hmos = HmosNotification.newBuilder().build(); + Assert.assertEquals("", new JsonObject(), hmos.toJSON()); } @Test public void testQuickAlert() { - WinphoneNotification winphone = WinphoneNotification.alert("aaa"); + HmosNotification hmos = HmosNotification.alert("aaa"); JsonObject json = new JsonObject(); json.add("alert", new JsonPrimitive("aaa")); - Assert.assertEquals("", json, winphone.toJSON()); + Assert.assertEquals("", json, hmos.toJSON()); } @Test public void testTitle() { - WinphoneNotification winphone = WinphoneNotification.newBuilder().setTitle("title").build(); + HmosNotification hmos = HmosNotification.newBuilder().setTitle("title").build(); JsonObject json = new JsonObject(); json.add("title", new JsonPrimitive("title")); - Assert.assertEquals("", json, winphone.toJSON()); + Assert.assertEquals("", json, hmos.toJSON()); } @Test public void testExtra() { - WinphoneNotification winphone = WinphoneNotification.newBuilder() + HmosNotification hmos = HmosNotification.newBuilder() .addExtra("key2", 222) .addExtra("key", "value").build(); JsonObject json = new JsonObject(); @@ -44,7 +44,7 @@ public void testExtra() { extra.add("key", new JsonPrimitive("value")); extra.add("key2", new JsonPrimitive(222)); json.add("extras", extra); - Assert.assertEquals("", json, winphone.toJSON()); + Assert.assertEquals("", json, hmos.toJSON()); } diff --git a/src/test/java/cn/jpush/api/push/model/notification/NotificationTest.java b/src/test/java/cn/jpush/api/push/model/notification/NotificationTest.java index 666e054b..c2bdbfe1 100644 --- a/src/test/java/cn/jpush/api/push/model/notification/NotificationTest.java +++ b/src/test/java/cn/jpush/api/push/model/notification/NotificationTest.java @@ -64,15 +64,15 @@ public void testAlert_ios() { } @Test - public void testAlert_winphone() { + public void testAlert_hmos() { Notification notification = Notification.newBuilder() - .addPlatformNotification(WinphoneNotification.alert("alert")) + .addPlatformNotification(HmosNotification.alert("alert")) .build(); JsonObject json = new JsonObject(); - JsonObject winphone = new JsonObject(); - winphone.add("alert", new JsonPrimitive("alert")); + JsonObject hmos = new JsonObject(); + hmos.add("alert", new JsonPrimitive("alert")); json.addProperty("ai_opportunity", false); - json.add("winphone", winphone); + json.add("hmos", hmos); Assert.assertEquals("", json, notification.toJSON()); } diff --git a/src/test/java/cn/jpush/api/push/remote/AlertOverrideTest.java b/src/test/java/cn/jpush/api/push/remote/AlertOverrideTest.java index 298eab51..dcc24ace 100644 --- a/src/test/java/cn/jpush/api/push/remote/AlertOverrideTest.java +++ b/src/test/java/cn/jpush/api/push/remote/AlertOverrideTest.java @@ -14,7 +14,7 @@ import cn.jpush.api.push.model.notification.AndroidNotification; import cn.jpush.api.push.model.notification.IosNotification; import cn.jpush.api.push.model.notification.Notification; -import cn.jpush.api.push.model.notification.WinphoneNotification; +import cn.jpush.api.push.model.notification.HmosNotification; @Category(SlowTests.class) public class AlertOverrideTest extends BaseRemotePushTest { @@ -28,7 +28,7 @@ public void sendAlert_all() throws Exception { .setAlert("alert") .addPlatformNotification(AndroidNotification.alert("android alert")) .addPlatformNotification(IosNotification.alert("ios alert")) - .addPlatformNotification(WinphoneNotification.alert("winphone alert")) + .addPlatformNotification(HmosNotification.alert("hmos alert")) .build()) .build(); PushResult result = _client.sendPush(payload); @@ -67,13 +67,13 @@ public void sendAlert_ios() throws Exception { } @Test - public void sendAlert_wp() throws Exception { + public void sendAlert_hmos() throws Exception { PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.winphone()) + .setPlatform(Platform.hmos()) .setAudience(Audience.all()) .setNotification(Notification.newBuilder() .setAlert("alert") - .addPlatformNotification(WinphoneNotification.alert("winphone alert")) + .addPlatformNotification(HmosNotification.alert("hmos alert")) .build()) .build(); try { diff --git a/src/test/java/cn/jpush/api/push/remote/BasicFunctionsTest.java b/src/test/java/cn/jpush/api/push/remote/BasicFunctionsTest.java index 835a73e9..bc541daa 100644 --- a/src/test/java/cn/jpush/api/push/remote/BasicFunctionsTest.java +++ b/src/test/java/cn/jpush/api/push/remote/BasicFunctionsTest.java @@ -2,7 +2,6 @@ import static org.junit.Assert.assertTrue; -import cn.jiguang.common.resp.APIConnectionException; import cn.jiguang.common.resp.APIRequestException; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -17,7 +16,7 @@ import cn.jpush.api.push.model.notification.AndroidNotification; import cn.jpush.api.push.model.notification.IosNotification; import cn.jpush.api.push.model.notification.Notification; -import cn.jpush.api.push.model.notification.WinphoneNotification; +import cn.jpush.api.push.model.notification.HmosNotification; @Category(SlowTests.class) public class BasicFunctionsTest extends BaseRemotePushTest { @@ -88,12 +87,12 @@ public void sendSimpleNotification_Pall_Nios() throws Exception { } @Test - public void sendSimpleNotification_Pwp_Nwp() throws Exception { + public void sendSimpleNotification_Phmos_Nhmos() throws Exception { PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.winphone()) + .setPlatform(Platform.hmos()) .setAudience(Audience.all()) .setNotification(Notification.newBuilder() - .addPlatformNotification(WinphoneNotification.alert("Pwp Nwp alert")) + .addPlatformNotification(HmosNotification.alert("Phmos Nhmos alert")) .build()) .build(); try { @@ -104,12 +103,12 @@ public void sendSimpleNotification_Pwp_Nwp() throws Exception { } @Test - public void sendSimpleNotification_Pall_Nwp() throws Exception { + public void sendSimpleNotification_Pall_Nhmos() throws Exception { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.all()) .setAudience(Audience.all()) .setNotification(Notification.newBuilder() - .addPlatformNotification(WinphoneNotification.alert("Pall Nwp alert")) + .addPlatformNotification(HmosNotification.alert("Pall Nhmos alert")) .build()) .build(); try { @@ -125,11 +124,11 @@ public void sendSimpleNotification_Pall_Nall() throws Exception { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.newBuilder() .addDeviceType(DeviceType.IOS) - .addDeviceType(DeviceType.WinPhone) + .addDeviceType(DeviceType.HMOS) .addDeviceType(DeviceType.Android).build()) .setAudience(Audience.all()) .setNotification(Notification.newBuilder() - .addPlatformNotification(WinphoneNotification.alert("Pall Nall wp alert")) + .addPlatformNotification(HmosNotification.alert("Pall Nall hmos alert")) .addPlatformNotification(IosNotification.alert("Pall Nall ios alert")) .addPlatformNotification(AndroidNotification.alert("Pall Nall android alert")) .build()) @@ -169,18 +168,6 @@ public void sendSimpleMessage_Pios() throws Exception { e.printStackTrace(); } } - - //@Test - public void sendSimpleMessage_Pwinphone() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.winphone()) - .setAudience(Audience.all()) - .setMessage(Message.content("Pwp msg")) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - @Test public void sendSimpleMessageAndNotification_Pall() throws Exception { diff --git a/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java b/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java index 1d307fa0..e92ac55a 100644 --- a/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java +++ b/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java @@ -160,28 +160,7 @@ public void invalidParams_notification_ios() { assertEquals(INVALID_PARAMS, e.getErrorCode()); } } - /* - @Test - public void invalidParams_notification_winphone() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - notification.add("winphone", new JsonPrimitive(ALERT)); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - */ + @Test public void invalidParams_notification_android_builderidNotNumber() { JsonObject payload = new JsonObject(); @@ -254,15 +233,15 @@ public void invalidParams_notification_ios_empty() { } @Test - public void invalidParams_notification_winphone_empty() { + public void invalidParams_notification_hmos_empty() { JsonObject payload = new JsonObject(); payload.add("platform", Platform.all().toJSON()); payload.add("audience", Audience.all().toJSON()); JsonObject notification = new JsonObject(); - JsonObject winphone = new JsonObject(); + JsonObject hmos = new JsonObject(); - notification.add("winphone", winphone); + notification.add("hmos", hmos); payload.add("notification", notification); System.out.println("json string: " + payload.toString()); @@ -326,16 +305,16 @@ public void invalidParams_notification_ios_noalert() { } @Test - public void invalidParams_notification_winphone_noalert() { + public void invalidParams_notification_hmos_noalert() { JsonObject payload = new JsonObject(); payload.add("platform", Platform.all().toJSON()); payload.add("audience", Audience.all().toJSON()); JsonObject notification = new JsonObject(); - JsonObject winphone = new JsonObject(); - winphone.add("title", new JsonPrimitive("title")); + JsonObject hmos = new JsonObject(); + hmos.add("title", new JsonPrimitive("title")); - notification.add("winphone", winphone); + notification.add("hmos", hmos); payload.add("notification", notification); System.out.println("json string: " + payload.toString()); diff --git a/src/test/java/cn/jpush/api/report/MessageDetailsResultTest.java b/src/test/java/cn/jpush/api/report/MessageDetailsResultTest.java new file mode 100644 index 00000000..995b233b --- /dev/null +++ b/src/test/java/cn/jpush/api/report/MessageDetailsResultTest.java @@ -0,0 +1,17 @@ +package cn.jpush.api.report; + +import cn.jpush.api.BaseTest; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class MessageDetailsResultTest extends BaseTest { + + @Test + public void getMessageDetailsResultTest() throws Exception{ + MessageDetailResult result = jpushClient.getMessagesDetail("38280845540235675"); + assertTrue(result.isResultOK()); + System.out.println(result.received_list.get(0).details); + assertTrue(result.received_list.size() > 0); + } +} diff --git a/src/test/java/cn/jpush/api/schedule/ScheduleClientTest.java b/src/test/java/cn/jpush/api/schedule/ScheduleClientTest.java index 22169cfa..d9747321 100644 --- a/src/test/java/cn/jpush/api/schedule/ScheduleClientTest.java +++ b/src/test/java/cn/jpush/api/schedule/ScheduleClientTest.java @@ -60,10 +60,12 @@ public void testGetScheduleList() { * Method: deleteSchedule(String scheduleId) */ @Test - public void testScheduleMethods(String masterSecret, String appKey) { + public void testScheduleMethods() { + String masterSecret = MASTER_SECRET; + String appKey = APP_KEY; String name = "test_schedule"; TriggerPayload trigger = TriggerPayload.newBuilder() - .setSingleTime("2105-07-30 12:00:00") + .setSingleTime("2022-07-30 12:00:00") .buildSingle(); PushPayload push = PushPayload.alertAll("test schedule");