Skip to content

Commit b7ba456

Browse files
authored
Merge pull request #110 from JoshLipan/master
3.3.6 master
2 parents bba1457 + 0e05229 commit b7ba456

File tree

11 files changed

+179
-20
lines changed

11 files changed

+179
-20
lines changed

.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<attribute name="maven.pomderived" value="true"/>
3030
</attributes>
3131
</classpathentry>
32-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
32+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
3333
<attributes>
3434
<attribute name="maven.pomderived" value="true"/>
3535
</attributes>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ bin/
44
target/
55
test-output/
66
.idea/
7+
.classpath
78

89
*.class
910
*.project

.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.jdt.core.javabuilder</name>
1015
<arguments>
@@ -19,5 +24,6 @@
1924
<natures>
2025
<nature>org.eclipse.m2e.core.maven2Nature</nature>
2126
<nature>org.eclipse.jdt.core.javanature</nature>
27+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
2228
</natures>
2329
</projectDescription>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>cn.jpush.api</groupId>
2626
<artifactId>jpush-client</artifactId>
27-
<version>3.3.4</version>
27+
<version>3.3.6</version>
2828
</dependency>
2929
```
3030
### jar 包方式

example/main/java/cn/jpush/api/examples/PushExample.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public class PushExample {
3434
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);
3535

3636
// demo App defined in resources/jpush-api.conf
37-
protected static final String APP_KEY ="d4ee2375846bc30fa51334f5";
38-
protected static final String MASTER_SECRET = "f3b222f7e0dde430b6d8fa5a";
37+
protected static final String APP_KEY ="7b4b94cca0d185d611e53cca";
38+
protected static final String MASTER_SECRET = "860803cf613ed54aa3b941a8";
3939
protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c";
4040
protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e";
4141

@@ -50,8 +50,8 @@ public class PushExample {
5050
public static void main(String[] args) {
5151
// testSendPushWithCustomConfig();
5252
// testSendIosAlert();
53-
// testSendPush();
54-
testGetCidList();
53+
testSendPush();
54+
// testGetCidList();
5555
// testSendPushes();
5656
// testSendPush_fromJSON();
5757
// testSendPushWithCallback();
@@ -408,7 +408,7 @@ public static void testSendIosAlert() {
408408
public static void testSendWithSMS() {
409409
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY);
410410
try {
411-
SMS sms = SMS.content("Test SMS", 10);
411+
SMS sms = SMS.content(1, 10);
412412
PushResult result = jpushClient.sendAndroidMessageWithAlias("Test SMS", "test sms", sms, "alias1");
413413
LOG.info("Got result - " + result);
414414
} catch (APIConnectionException e) {

example/main/java/cn/jpush/api/examples/ReportsExample.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class ReportsExample {
1919
protected static final Logger LOG = LoggerFactory.getLogger(ReportsExample.class);
2020

2121
// demo App defined in resources/jpush-api.conf
22-
private static final String appKey = "dd1066407b044738b6479275";
23-
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
22+
private static final String appKey = "7b4b94cca0d185d611e53cca";
23+
private static final String masterSecret = "860803cf613ed54aa3b941a8";
2424
public static final String REGISTRATION_ID1 = "0900e8d85ef";
2525
public static final String REGISTRATION_ID2 = "0a04ad7d8b4";
2626
public static final String REGISTRATION_ID3 = "18071adc030dcba91c0";
@@ -29,6 +29,7 @@ public static void main(String[] args) {
2929
testGetReport();
3030
testGetMessages();
3131
testGetUsers();
32+
testGetMessageStatus();
3233
}
3334

3435

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>cn.jpush.api</groupId>
55
<artifactId>jpush-client</artifactId>
6-
<version>3.3.5-SNAPSHOT</version>
6+
<version>3.3.7-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<url>https://github.com/jpush/jpush-api-java-client</url>
99
<name>JPush API Java Client</name>

src/main/java/cn/jpush/api/push/model/Message.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ public class Message implements PushModel {
2222
private final Map<String, String> extras;
2323
private final Map<String, Number> numberExtras;
2424
private final Map<String, Boolean> booleanExtras;
25+
private final Map<String, JsonObject> jsonExtras;
2526

2627
private Message(String title, String msgContent, String contentType,
2728
Map<String, String> extras,
2829
Map<String, Number> numberExtras,
29-
Map<String, Boolean> booleanExtras) {
30+
Map<String, Boolean> booleanExtras,
31+
Map<String, JsonObject> jsonExtras) {
3032
this.title = title;
3133
this.msgContent = msgContent;
3234
this.contentType = contentType;
3335
this.extras = extras;
3436
this.numberExtras = numberExtras;
3537
this.booleanExtras = booleanExtras;
38+
this.jsonExtras = jsonExtras;
3639
}
3740

3841
public static Builder newBuilder() {
@@ -80,6 +83,11 @@ public JsonElement toJSON() {
8083
extrasObject.add(key, new JsonPrimitive(booleanExtras.get(key)));
8184
}
8285
}
86+
if (null != jsonExtras) {
87+
for (String key : jsonExtras.keySet()) {
88+
extrasObject.add(key, jsonExtras.get(key));
89+
}
90+
}
8391

8492
if (null != extras || null != numberExtras || null != booleanExtras) {
8593
json.add(EXTRAS, extrasObject);
@@ -95,6 +103,7 @@ public static class Builder {
95103
private Map<String, String> extrasBuilder;
96104
private Map<String, Number> numberExtrasBuilder;
97105
private Map<String, Boolean> booleanExtrasBuilder;
106+
protected Map<String, JsonObject> jsonExtrasBuilder;
98107

99108
public Builder setTitle(String title) {
100109
this.title = title;
@@ -149,11 +158,20 @@ public Builder addExtra(String key, Boolean value) {
149158
return this;
150159
}
151160

161+
public Builder addExtra(String key, JsonObject value) {
162+
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
163+
if (null == jsonExtrasBuilder) {
164+
jsonExtrasBuilder = new HashMap<String, JsonObject>();
165+
}
166+
jsonExtrasBuilder.put(key, value);
167+
return this;
168+
}
169+
152170
public Message build() {
153171
Preconditions.checkArgument(! (null == msgContent),
154172
"msgContent should be set");
155173
return new Message(title, msgContent, contentType,
156-
extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder);
174+
extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder,jsonExtrasBuilder);
157175
}
158176
}
159177
}

src/main/java/cn/jpush/api/push/model/PushPayload.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cn.jpush.api.push.model;
22

33
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
45
import com.google.gson.JsonElement;
56
import com.google.gson.JsonObject;
67
import com.google.gson.JsonPrimitive;
@@ -33,7 +34,7 @@ public class PushPayload implements PushModel {
3334
private static final int MAX_GLOBAL_ENTITY_LENGTH = 4000; // Definition acording to JPush Docs
3435
private static final int MAX_IOS_PAYLOAD_LENGTH = 2000; // Definition acording to JPush Docs
3536

36-
private static Gson _gson = new Gson();
37+
private static Gson _gson = new GsonBuilder().disableHtmlEscaping().create();
3738

3839
private final Platform platform;
3940
private final Audience audience;

src/main/java/cn/jpush/api/push/model/SMS.java

Lines changed: 134 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
11
package cn.jpush.api.push.model;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
36
import com.google.gson.JsonElement;
7+
import com.google.gson.JsonNull;
48
import com.google.gson.JsonObject;
9+
import com.google.gson.JsonPrimitive;
510

611
import cn.jiguang.common.utils.Preconditions;
7-
import cn.jiguang.common.utils.StringUtils;
812

913
public class SMS implements PushModel {
1014

1115
private final String content;
1216
private final int delay_time;
17+
private final long temp_id;
18+
private final Map<String, String> extras;
19+
private final Map<String, Number> numberExtras;
20+
private final Map<String, Boolean> booleanExtras;
21+
private final Map<String, JsonObject> jsonExtras;
1322

14-
private SMS(String content, int delay_time) {
23+
private SMS(String content, int delay_time, long temp_id,
24+
Map<String, String> extras,
25+
Map<String, Number> numberExtras,
26+
Map<String, Boolean> booleanExtras,
27+
Map<String, JsonObject> jsonExtras) {
1528
this.content = content;
1629
this.delay_time = delay_time;
30+
this.temp_id = temp_id;
31+
this.extras = extras;
32+
this.numberExtras = numberExtras;
33+
this.booleanExtras = booleanExtras;
34+
this.jsonExtras = jsonExtras;
35+
1736
}
1837

1938
public static Builder newBuilder() {
2039
return new Builder();
2140
}
2241

2342
/**
43+
* This will be removed in the future. Please use content(long tempId, int delayTime) this constructor.
2444
* Create a SMS content with a delay time.
2545
* JPush will send a SMS if the message doesn't received within the delay time. If the delay time is 0, the SMS will be sent immediately.
2646
* Please note the delay time only works on Android.
@@ -30,24 +50,81 @@ public static Builder newBuilder() {
3050
* @param delayTime The seconds you want to delay, should be greater than or equal to 0.
3151
* @return SMS payload.
3252
*/
53+
@Deprecated
3354
public static SMS content(String content, int delayTime) {
3455
return new Builder()
3556
.setContent(content)
3657
.setDelayTime(delayTime)
3758
.build();
3859
}
60+
61+
public static SMS content(long tempId, int delayTime) {
62+
return new Builder()
63+
.setTempID(tempId)
64+
.setDelayTime(delayTime)
65+
.build();
66+
}
67+
3968

4069
@Override
4170
public JsonElement toJSON() {
4271
JsonObject json = new JsonObject();
43-
json.addProperty("content", content);
72+
4473
json.addProperty("delay_time", delay_time);
74+
75+
if (temp_id > 0) {
76+
json.addProperty("temp_id", temp_id);
77+
}
78+
79+
if (null != content) {
80+
json.addProperty("content", content);
81+
}
82+
83+
84+
JsonObject extrasObject = null;
85+
if (null != extras || null != numberExtras || null != booleanExtras) {
86+
extrasObject = new JsonObject();
87+
}
88+
89+
if (null != extras) {
90+
for (String key : extras.keySet()) {
91+
if (extras.get(key) != null) {
92+
extrasObject.add(key, new JsonPrimitive(extras.get(key)));
93+
} else {
94+
extrasObject.add(key, JsonNull.INSTANCE);
95+
}
96+
}
97+
}
98+
if (null != numberExtras) {
99+
for (String key : numberExtras.keySet()) {
100+
extrasObject.add(key, new JsonPrimitive(numberExtras.get(key)));
101+
}
102+
}
103+
if (null != booleanExtras) {
104+
for (String key : booleanExtras.keySet()) {
105+
extrasObject.add(key, new JsonPrimitive(booleanExtras.get(key)));
106+
}
107+
}
108+
if (null != jsonExtras) {
109+
for (String key : jsonExtras.keySet()) {
110+
extrasObject.add(key, jsonExtras.get(key));
111+
}
112+
}
113+
114+
if (null != extras || null != numberExtras || null != booleanExtras) {
115+
json.add("temp_para", extrasObject);
116+
}
45117
return json;
46118
}
47119

48120
public static class Builder {
49121
private String content;
50122
private int delay_time;
123+
private long temp_id;
124+
private Map<String, String> extrasBuilder;
125+
private Map<String, Number> numberExtrasBuilder;
126+
private Map<String, Boolean> booleanExtrasBuilder;
127+
protected Map<String, JsonObject> jsonExtrasBuilder;
51128

52129
public Builder setContent(String content) {
53130
this.content = content;
@@ -58,12 +135,64 @@ public Builder setDelayTime(int delayTime) {
58135
this.delay_time = delayTime;
59136
return this;
60137
}
138+
139+
public Builder setTempID(long tempID) {
140+
this.temp_id = tempID;
141+
return this;
142+
}
143+
144+
public Builder addPara(String key, String value) {
145+
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
146+
if (null == extrasBuilder) {
147+
extrasBuilder = new HashMap<String, String>();
148+
}
149+
extrasBuilder.put(key, value);
150+
return this;
151+
}
152+
153+
public Builder addParas(Map<String, String> extras) {
154+
Preconditions.checkArgument(! (null == extras), "extras should not be null.");
155+
if (null == extrasBuilder) {
156+
extrasBuilder = new HashMap<String, String>();
157+
}
158+
for (String key : extras.keySet()) {
159+
extrasBuilder.put(key, extras.get(key));
160+
}
161+
return this;
162+
}
163+
164+
public Builder addPara(String key, Number value) {
165+
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
166+
if (null == numberExtrasBuilder) {
167+
numberExtrasBuilder = new HashMap<String, Number>();
168+
}
169+
numberExtrasBuilder.put(key, value);
170+
return this;
171+
}
172+
173+
public Builder addPara(String key, Boolean value) {
174+
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
175+
if (null == booleanExtrasBuilder) {
176+
booleanExtrasBuilder = new HashMap<String, Boolean>();
177+
}
178+
booleanExtrasBuilder.put(key, value);
179+
return this;
180+
}
181+
182+
public Builder addPara(String key, JsonObject value) {
183+
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
184+
if (null == jsonExtrasBuilder) {
185+
jsonExtrasBuilder = new HashMap<String, JsonObject>();
186+
}
187+
jsonExtrasBuilder.put(key, value);
188+
return this;
189+
}
61190

62191
public SMS build() {
63-
Preconditions.checkArgument(StringUtils.isNotEmpty(content), "The content must not be empty.");
64192
Preconditions.checkArgument(delay_time >= 0, "The delay time must be greater than or equal to 0");
65193

66-
return new SMS(content, delay_time);
194+
return new SMS(content, delay_time, temp_id,
195+
extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder,jsonExtrasBuilder);
67196
}
68197

69198
}

0 commit comments

Comments
 (0)