admin
2024-10-16 7fa83e5dd03f7896bd1d1e8c47f5e926ff3d4ba0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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;
 
 
/**
 * <p><b>QuickApp 通知类</b></p>
 * <br>
 * 具体使用方法请参考官方文档 https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#platform
 * 支持 QuickApp Notification 的参数:
 * <ul>
 * <li>alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。</li>
 * <li>title: 支持 setTitle(string) 方法来设置;可替换快应用推送通知的标题。 </li>
 * <li>page: 支持 setPage(String) 方法来设置;可设置快应用跳转页面</li>
 * <li>extras: 继承自父类 PlatformNotification 的 extras 属性;支持通过 addExtra(key, value) 来添加自定义字段,具体看代码。 </li>
 * </ul>
 * <br>
 */
public class QuickappNotification extends PlatformNotification {
    private static final String NOTIFICATION_QUICKAPP = "quickapp";
 
    private static final String TITLE = "title";
    private static final String PAGE = "page";
 
    private final String title;
    private final String page;
 
    private QuickappNotification(Object alert, String title, String page,
                                 Map<String, String> extras,
                                 Map<String, Number> numberExtras,
                                 Map<String, Boolean> booleanExtras,
                                 Map<String, JsonObject> jsonExtras,
                                 Map<String, JsonPrimitive> customData) {
        super(alert, extras, numberExtras, booleanExtras, jsonExtras, customData);
 
        this.title = title;
        this.page = page;
    }
 
    public static Builder newBuilder() {
        return new Builder();
    }
 
    public static QuickappNotification alert(String alert) {
        return newBuilder().setAlert(alert).build();
    }
 
    @Override
    public String getPlatform() {
        return NOTIFICATION_QUICKAPP;
    }
 
    @Override
    public JsonElement toJSON() {
        JsonObject json = super.toJSON().getAsJsonObject();
 
        if (null != title) {
            json.add(TITLE, new JsonPrimitive(title));
        }
        if (null != page) {
            json.add(PAGE, new JsonPrimitive(page));
        }
 
        return json;
    }
 
    public static class Builder extends PlatformNotification.Builder<QuickappNotification, Builder> {
        private String title;
        private String page;
 
        @Override
        protected Builder getThis() {
            return this;
        }
 
        public Builder setTitle(String title) {
            this.title = title;
            return this;
        }
 
        public Builder setPage(String page) {
            this.page = page;
            return this;
        }
 
        @Override
        public Builder setAlert(Object alert) {
            this.alert = alert;
            return this;
        }
 
 
        public QuickappNotification build() {
            return new QuickappNotification(alert, title, page,
                    extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder, super.customData);
        }
    }
}