86183
2022-09-09 0d999e33085c0a25c5525242748f6aa62a401159
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
package com.dsh.app.util.push;
 
import com.alibaba.fastjson.JSONObject;
 
import java.util.Arrays;
import java.util.HashSet;
 
public abstract class UmengNotification {
    // This JSONObject is used for constructing the whole request string.
    protected final JSONObject rootJson = new JSONObject();
 
 
    // The app master secret
    protected String appMasterSecret;
 
    // Keys can be set in the root level
    protected static final HashSet<String> ROOT_KEYS = new HashSet<String>(Arrays.asList(new String[]{
            "appkey", "timestamp", "type", "device_tokens", "alias", "alias_type", "file_id",
            "filter", "production_mode", "feedback", "description", "thirdparty_id", "mipush", "mi_activity", "channel_properties"}));
 
    // Keys can be set in the policy level
    protected static final HashSet<String> POLICY_KEYS = new HashSet<String>(Arrays.asList(new String[]{
            "start_time", "expire_time", "max_send_num"
    }));
 
    // Set predefined keys in the rootJson, for extra keys(Android) or customized keys(IOS) please
    // refer to corresponding methods in the subclass.
    public abstract boolean setPredefinedKeyValue(String key, Object value) throws Exception;
 
    public void setAppMasterSecret(String secret) {
        appMasterSecret = secret;
    }
 
    public String getPostBody() {
        return rootJson.toString();
    }
 
    protected final String getAppMasterSecret() {
        return appMasterSecret;
    }
 
    protected void setProductionMode(Boolean prod) throws Exception {
        setPredefinedKeyValue("production_mode", prod.toString());
    }
 
    ///正式模式
    public void setProductionMode() throws Exception {
        setProductionMode(true);
    }
 
    ///测试模式
    public void setTestMode() throws Exception {
        setProductionMode(false);
    }
 
    ///发送消息描述,建议填写。
    public void setDescription(String description) throws Exception {
        setPredefinedKeyValue("description", description);
    }
 
    ///定时发送时间,若不填写表示立即发送。格式: "YYYY-MM-DD hh:mm:ss"。
    public void setStartTime(String startTime) throws Exception {
        setPredefinedKeyValue("start_time", startTime);
    }
 
    ///消息过期时间,格式: "YYYY-MM-DD hh:mm:ss"。
    public void setExpireTime(String expireTime) throws Exception {
        setPredefinedKeyValue("expire_time", expireTime);
    }
 
    ///发送限速,每秒发送的最大条数。
    public void setMaxSendNum(Integer num) throws Exception {
        setPredefinedKeyValue("max_send_num", num);
    }
 
    //厂商弹窗activity
    public void setChannelActivity(String activity) throws Exception {
        setPredefinedKeyValue("mipush", "true");
        setPredefinedKeyValue("mi_activity", activity);
    }
 
    //厂商属性配置
    public void setChannelProperties(String xiaoMiChannelId) throws Exception {
        JSONObject object = new JSONObject();
        object.put("xiaomi_channel_id", xiaoMiChannelId);
        setPredefinedKeyValue("channel_properties", object);
    }
 
}