Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@

> 一下片断来自项目代码里面的文件:example / cn.jpush.api.examples.ClientExample

* 配置的SSLVersion表示指定至少支持的协议版本,也可能支持其他多个协议版本,最终支持的协议版本列表取决于JRE和运行环境
```Java
public static void testCustomClient() {
ClientConfig config = ClientConfig.getInstance();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.2.8</version>
<version>3.2.9-SNAPSHOT</version>
<packaging>jar</packaging>
<url>https://github.com/jpush/jpush-api-java-client</url>
<name>JPush API Java Client</name>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/cn/jpush/api/common/resp/BaseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public abstract class BaseResult implements IRateLimiting {
import java.io.Serializable;

public abstract class BaseResult implements IRateLimiting, Serializable {
public static final int ERROR_CODE_NONE = -1;
public static final int ERROR_CODE_OK = 0;
public static final String ERROR_MESSAGE_NONE = "None error message.";

protected static final int RESPONSE_OK = 200;
protected static Gson _gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();


private static final long serialVersionUID = 4810924314887130678L;

private ResponseWrapper responseWrapper;

public void setResponseWrapper(ResponseWrapper responseWrapper) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/cn/jpush/api/common/resp/ResponseWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ResponseWrapper {
import java.io.Serializable;

public class ResponseWrapper implements Serializable {

private static final Logger LOG = LoggerFactory.getLogger(ResponseWrapper.class);
private static final int RESPONSE_CODE_NONE = -1;

private static final long serialVersionUID = -4227962073448507865L;

private static Gson _gson = new Gson();
private static JsonParser jsonParser = new JsonParser();

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/cn/jpush/api/device/OnlineStatus.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package cn.jpush.api.device;

public class OnlineStatus {
import java.io.Serializable;

Boolean online;
String last_online_time;
public class OnlineStatus implements Serializable {

private static final long serialVersionUID = -5436655826293828109L;

private Boolean online;
private String last_online_time;

public Boolean getOnline() {
return online;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/jpush/api/device/TagAliasResult.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cn.jpush.api.device;

import java.util.List;

import cn.jpush.api.common.resp.BaseResult;

import com.google.gson.annotations.Expose;

import java.util.List;

public class TagAliasResult extends BaseResult {

private static final long serialVersionUID = -4765083329495728276L;
@Expose public List<String> tags;
@Expose public String alias;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/cn/jpush/api/device/TagListResult.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cn.jpush.api.device;

import java.util.ArrayList;
import java.util.List;

import cn.jpush.api.common.resp.BaseResult;

import com.google.gson.annotations.Expose;

import java.util.ArrayList;
import java.util.List;

public class TagListResult extends BaseResult {


private static final long serialVersionUID = -5395153728332839175L;
@Expose public List<String> tags = new ArrayList<String>();

}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/cn/jpush/api/push/PushResult.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cn.jpush.api.push;

import cn.jpush.api.common.resp.BaseResult;

import com.google.gson.annotations.Expose;

public class PushResult extends BaseResult {


private static final long serialVersionUID = 93783137655776743L;

@Expose public long msg_id;
@Expose public int sendno;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/jpush/api/report/MessagesResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class MessagesResult extends BaseResult {
private static final Type MESSAGE_TYPE = new TypeToken<List<Message>>() {}.getType();
private static final long serialVersionUID = -1582895355000647292L;

@Expose
public List<Message> messages = new ArrayList<Message>();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/jpush/api/report/ReceivedsResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class ReceivedsResult extends BaseResult {
private static final Type RECEIVED_TYPE = new TypeToken<List<Received>>() {}.getType();
private static final long serialVersionUID = 1761456104618847304L;

@Expose
public List<Received> received_list = new ArrayList<Received>();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/jpush/api/report/UsersResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class UsersResult extends BaseResult {

private static final long serialVersionUID = -963296929272770550L;
@Expose public TimeUnit time_unit;
@Expose public String start;
@Expose public int duration;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/cn/jpush/api/schedule/ScheduleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class ScheduleClient {
private String hostName;
private String schedulePath;

// If not present, true by default.
private int apnsProduction;

// If not present, the default value is 86400(s) (one day)
private long timeToLive;

public ScheduleClient(String masterSecret, String appkey) {
this(masterSecret, appkey, null, ClientConfig.getInstance());
}
Expand All @@ -47,6 +53,8 @@ public ScheduleClient(String masterSecret, String appKey, int maxRetryTimes, Htt

hostName = (String) conf.get(ClientConfig.SCHEDULE_HOST_NAME);
schedulePath = (String) conf.get(ClientConfig.SCHEDULE_PATH);
apnsProduction = (Integer) conf.get(ClientConfig.APNS_PRODUCTION);
timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);

String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
Expand All @@ -63,6 +71,8 @@ public ScheduleClient(String masterSecret, String appKey, HttpProxy proxy, Clien
ServiceHelper.checkBasic(appKey, masterSecret);
hostName = (String) conf.get(ClientConfig.SCHEDULE_HOST_NAME);
schedulePath = (String) conf.get(ClientConfig.SCHEDULE_PATH);
apnsProduction = (Integer) conf.get(ClientConfig.APNS_PRODUCTION);
timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);

String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
Expand All @@ -72,6 +82,16 @@ public ScheduleResult createSchedule(SchedulePayload payload) throws APIConnecti

Preconditions.checkArgument(null != payload, "payload should not be null");

if (apnsProduction > 0) {
payload.resetPushApnsProduction(true);
} else if(apnsProduction == 0) {
payload.resetPushApnsProduction(false);
}

if (timeToLive >= 0) {
payload.resetPushTimeToLive(timeToLive);
}

ResponseWrapper response = _httpClient.sendPost(hostName + schedulePath, payload.toString());
return ScheduleResult.fromResponse(response, ScheduleResult.class);
}
Expand All @@ -97,6 +117,16 @@ public ScheduleResult updateSchedule(String scheduleId, SchedulePayload payload)
Preconditions.checkArgument(StringUtils.isNotEmpty(scheduleId), "scheduleId should not be empty");
Preconditions.checkArgument(null != payload, "payload should not be null");

if (apnsProduction > 0) {
payload.resetPushApnsProduction(true);
} else if(apnsProduction == 0) {
payload.resetPushApnsProduction(false);
}

if (timeToLive >= 0) {
payload.resetPushTimeToLive(timeToLive);
}

ResponseWrapper response = _httpClient.sendPut(hostName + schedulePath + "/" + scheduleId,
payload.toString());
return ScheduleResult.fromResponse(response, ScheduleResult.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class ScheduleListResult extends BaseResult{

private static final long serialVersionUID = 86248096939746151L;
@Expose int total_count;
@Expose int total_pages;
@Expose int page;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/jpush/api/schedule/ScheduleResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class ScheduleResult extends BaseResult{

private static final long serialVersionUID = 995450157929190757L;
@Expose String schedule_id;
@Expose String name;
@Expose Boolean enabled;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/cn/jpush/api/schedule/model/SchedulePayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public String toString() {
return gson.toJson(toJSON());
}

public void resetPushApnsProduction(boolean apnsProduction) {
if(null != push) {
push.resetOptionsApnsProduction(apnsProduction);
}
}

public void resetPushTimeToLive(long timeToLive) {
if(null != push) {
push.resetOptionsTimeToLive(timeToLive);
}
}

public static class Builder{
private String name;
private Boolean enabled;
Expand Down