Skip to content

Commit 5d1a59b

Browse files
committed
PushPayload中增加inapp_message的参数支持
1 parent 9eeb55e commit 5d1a59b

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

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

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

3434
// demo App defined in resources/jpush-api.conf
35-
protected static final String APP_KEY = "32f266ea08c3b3d7a059b378";
36-
protected static final String MASTER_SECRET = "03b3ab9ae0a099ef26dd2168";
35+
protected static final String APP_KEY = "8f02a4fa717a6235734d92de";
36+
protected static final String MASTER_SECRET = "cf6de29f9e66432ba4ac1c32";
3737
protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c";
3838
protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e";
3939

@@ -281,7 +281,7 @@ public static PushPayload buildPushObject_android_and_ios() {
281281
.setPlatform(Platform.android_ios())
282282
.setAudience(Audience.all())
283283
.setNotification(Notification.newBuilder()
284-
.setAiOpportunity(true)
284+
.setAiOpportunity(false)
285285
.setAlert("testing alert content")
286286
.addPlatformNotification(AndroidNotification.newBuilder()
287287
.setTitle("Android Title")
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cn.jpush.api.push.model;
2+
3+
import cn.jiguang.common.utils.Preconditions;
4+
5+
import cn.jpush.api.push.model.notification.Notification;
6+
import com.google.gson.JsonElement;
7+
import com.google.gson.JsonObject;
8+
9+
10+
public class InappMessage implements PushModel{
11+
12+
private boolean inappMessage;
13+
14+
private InappMessage(boolean inappMessage) {
15+
this.inappMessage = inappMessage;
16+
}
17+
18+
public static Builder newBuilder() { return new Builder(); }
19+
20+
public static InappMessage inappMessage(boolean inappMessage) {
21+
return newBuilder().setInappMessage(inappMessage).build();
22+
}
23+
24+
25+
@Override
26+
public JsonElement toJSON() {
27+
JsonObject json = new JsonObject();
28+
29+
json.addProperty("inapp_message", inappMessage);
30+
31+
return json;
32+
}
33+
34+
35+
public static class Builder {
36+
private boolean inappMessage;
37+
38+
public Builder setInappMessage(boolean inappMessage) {
39+
this.inappMessage = inappMessage;
40+
return this;
41+
}
42+
43+
public InappMessage build() {
44+
return new InappMessage(inappMessage);
45+
}
46+
}
47+
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class PushPayload implements PushModel {
3131
private static final String PLATFORM = "platform";
3232
private static final String AUDIENCE = "audience";
3333
private static final String NOTIFICATION = "notification";
34+
private static final String INAPPMESSAGE = "inapp_message";
3435
private static final String MESSAGE = "message";
3536
private static final String OPTIONS = "options";
3637
private static final String SMS = "sms_message";
@@ -52,6 +53,7 @@ public class PushPayload implements PushModel {
5253
private final Platform platform;
5354
private final Audience audience;
5455
private final Notification notification;
56+
private final InappMessage inappMessage;
5557
private final Message message;
5658
private Options options;
5759
private SMS sms;
@@ -60,10 +62,11 @@ public class PushPayload implements PushModel {
6062
protected Map<String, JsonObject> custom;
6163

6264
private PushPayload(Platform platform, Audience audience,
63-
Notification notification, Message message, Options options, SMS sms, String cid, String target, Map<String, JsonObject> custom) {
65+
Notification notification, InappMessage inappMessage, Message message, Options options, SMS sms, String cid, String target, Map<String, JsonObject> custom) {
6466
this.platform = platform;
6567
this.audience = audience;
6668
this.notification = notification;
69+
this.inappMessage = inappMessage;
6770
this.message = message;
6871
this.options = options;
6972
this.sms = sms;
@@ -186,6 +189,9 @@ public JsonElement toJSON() {
186189
if (null != notification) {
187190
json.add(NOTIFICATION, notification.toJSON());
188191
}
192+
if (null != inappMessage) {
193+
json.add(INAPPMESSAGE, inappMessage.toJSON());
194+
}
189195
if (null != message) {
190196
json.add(MESSAGE, message.toJSON());
191197
}
@@ -261,6 +267,7 @@ public static class Builder {
261267
private Platform platform = null;
262268
private Audience audience = null;
263269
private Notification notification = null;
270+
private InappMessage inappMessage = null;
264271
private Message message = null;
265272
private Options options = null;
266273
private SMS sms = null;
@@ -291,6 +298,11 @@ public Builder setNotification(Notification notification) {
291298
this.notification = notification;
292299
return this;
293300
}
301+
302+
public Builder setInappMessage(InappMessage inappMessage) {
303+
this.inappMessage = inappMessage;
304+
return this;
305+
}
294306

295307
public Builder setMessage(Message message) {
296308
this.message = message;
@@ -336,7 +348,7 @@ public PushPayload build() {
336348
options = Options.sendno();
337349
}
338350

339-
return new PushPayload(platform, audience, notification, message, options, sms, cid, target, custom);
351+
return new PushPayload(platform, audience, notification, inappMessage, message, options, sms, cid, target, custom);
340352
}
341353
}
342354
}

0 commit comments

Comments
 (0)