Skip to content

Commit

Permalink
增加对智能时机参数的支持 v4.3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiboZhang1 committed Jul 27, 2021
1 parent 33c8495 commit 9eeb55e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
21 changes: 13 additions & 8 deletions example/main/java/cn/jpush/api/examples/PushExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class PushExample {
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);

// demo App defined in resources/jpush-api.conf
protected static final String APP_KEY = "e4ceeaf7a53ad745dd4728f2";
protected static final String MASTER_SECRET = "1582b986adeaf48ceec1e354";
protected static final String APP_KEY = "32f266ea08c3b3d7a059b378";
protected static final String MASTER_SECRET = "03b3ab9ae0a099ef26dd2168";
protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c";
protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e";

Expand All @@ -48,15 +48,15 @@ public class PushExample {
public static void main(String[] args) {

// 回调参数可参考下面方法
testSendPushWithCustom();
testSendPushWithCustomField();
// testSendPushWithCustom();
// testSendPushWithCustomField();
// testBatchSend();
testSendPushWithCustomConfig();
// testSendPushWithCustomConfig();
// testSendIosAlert();
// testSendPush();
testSendPush();
// testGetCidList();
// testSendPushes();
testSendPush_fromJSON();
// testSendPush_fromJSON();
// testSendPushWithCallback();
// testSendPushWithCid();
}
Expand Down Expand Up @@ -281,14 +281,19 @@ public static PushPayload buildPushObject_android_and_ios() {
.setPlatform(Platform.android_ios())
.setAudience(Audience.all())
.setNotification(Notification.newBuilder()
.setAlert("alert content")
.setAiOpportunity(true)
.setAlert("testing alert content")
.addPlatformNotification(AndroidNotification.newBuilder()
.setTitle("Android Title")
.addExtras(extras).build())
.addPlatformNotification(IosNotification.newBuilder()
.incrBadge(1)
.addExtra("extra_key", "extra_value").build())
.build())
.setOptions(Options.newBuilder()
.setApnsProduction(false)
.setTimeToLive(43200)
.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@
import cn.jiguang.common.utils.Preconditions;
import cn.jpush.api.push.model.PushModel;

public class Notification implements PushModel {
public class Notification implements PushModel {
private boolean aiOpportunity = false;
private final Object alert;
private final Set<PlatformNotification> notifications;

private Notification(Object alert, Set<PlatformNotification> notifications) {
private Notification(boolean aiOpportunity, Object alert, Set<PlatformNotification> notifications) {
this.aiOpportunity = aiOpportunity;
this.alert = alert;
this.notifications = notifications;
}

public static Builder newBuilder() {
return new Builder();
}

public static Notification aiOpportunity(boolean ai_opportunity) {
return newBuilder().setAiOpportunity(ai_opportunity).build();
}

/**
* Quick set all platform alert.
Expand Down Expand Up @@ -92,6 +98,8 @@ public static Notification winphone(String alert, Map<String, String> extras) {

public JsonElement toJSON() {
JsonObject json = new JsonObject();
json.addProperty("ai_opportunity", aiOpportunity);

if (null != alert) {
if(alert instanceof JsonObject) {
json.add(PlatformNotification.ALERT, (JsonObject) alert);
Expand All @@ -117,9 +125,15 @@ public JsonElement toJSON() {
}

public static class Builder {
private boolean aiOpportunity;
private Object alert;
private Set<PlatformNotification> builder;


public Builder setAiOpportunity(boolean aiOpportunity) {
this.aiOpportunity = aiOpportunity;
return this;
}

public Builder setAlert(Object alert) {
this.alert = alert;
return this;
Expand All @@ -134,9 +148,9 @@ public Builder addPlatformNotification(PlatformNotification notification) {
}

public Notification build() {
Preconditions.checkArgument(! (null == builder && null == alert),
Preconditions.checkArgument(! (null == builder && null == alert),
"No notification payload is set.");
return new Notification(alert, builder);
return new Notification(aiOpportunity, alert, builder);
}
}
}
Expand Down

0 comments on commit 9eeb55e

Please sign in to comment.