admin
2021-02-27 4ebe7c447e964e1b3ead12abb1d95b75faf67426
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.tencent.xinge;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.Vector;
 
import org.json.JSONArray;
import org.json.JSONObject;
 
public class MessageIOS {
    public MessageIOS()
    {
        this.m_sendTime = "2014-03-13 16:13:00";
        this.m_acceptTimes = new Vector<TimeInterval>();
        this.m_raw = "";
        this.m_alertStr = "";
        this.m_alertJo = new JSONObject();
        this.m_badge = 0;
        this.m_sound = "";
        this.m_category = "";
        this.m_loopInterval = -1;
        this.m_loopTimes = -1;
    }
    
    public void setExpireTime(int expireTime)
    {
        this.m_expireTime = expireTime;
    }
    public int getExpireTime()
    {
        return this.m_expireTime;
    }
    public void setSendTime(String sendTime)
    {
        this.m_sendTime = sendTime;
    }
    public String getSendTime()
    {
        return this.m_sendTime;
    }
    public void addAcceptTime(TimeInterval acceptTime)
    {
        this.m_acceptTimes.add(acceptTime);
    }
    public String acceptTimeToJson()
    {
        JSONArray json_arr = new JSONArray();
        for (TimeInterval ti : m_acceptTimes) 
        {
            JSONObject jtmp = ti.toJsonObject();
            json_arr.put(jtmp);
        }
        return json_arr.toString();
    }
    public JSONArray acceptTimeToJsonArray()
    {
        JSONArray json_arr = new JSONArray();
        for (TimeInterval ti : m_acceptTimes) 
        {
            JSONObject jtmp = ti.toJsonObject();
            json_arr.put(jtmp);
        }
        return json_arr;
    }
    public int getType()
    {
        return 0;
    }
    public void setCustom(Map<String, Object> custom)
    {
        this.m_custom = custom;
    }
    public void setRaw(String raw)
    {
        this.m_raw = raw;
    }
    public void setAlert(String alert)
    {
        m_alertStr = alert;
    }
    public void setAlert(JSONObject alert)
    {
        m_alertJo = alert;
    }
    public void setBadge(int badge)
    {
        m_badge = badge;
    }
    public void setSound(String sound)
    {
        m_sound = sound;
    }
    public void setCategory(String category) {
        m_category = category;
    }
    public int getLoopInterval()
    {
        return m_loopInterval;
    }
    public void setLoopInterval(int loopInterval)
    {
        m_loopInterval = loopInterval;
    }
    public int getLoopTimes()
    {
        return m_loopTimes;
    }
    public void setLoopTimes(int loopTimes)
    {
        m_loopTimes = loopTimes;
    }
    
    public boolean isValid()
    {
        if (m_expireTime<0 || m_expireTime>3*24*60*60)
            return false;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try
        {
            sdf.parse(m_sendTime);
        }catch(ParseException e){
            return false;
        }
        if (!m_raw.isEmpty()) return true;
        for (TimeInterval ti : m_acceptTimes) {
            if(!ti.isValid()) return false;
        }
        if(m_alertStr.isEmpty() && m_alertJo.length()==0)
            return false;
        
        return true;
    }
    
    public String toJson()
    {
        if (!m_raw.isEmpty()) return m_raw;
        JSONObject json = new JSONObject(m_custom);
        json.put("accept_time", acceptTimeToJsonArray());
        JSONObject aps = new JSONObject();
        if(m_alertJo.length()!=0)
            aps.put("alert", m_alertJo);
        else
            aps.put("alert", m_alertStr);
        if(m_badge!=0) aps.put("badge", m_badge);
        if(!m_sound.isEmpty()) aps.put("sound", m_sound);
        if(!m_category.isEmpty()) aps.put("category", m_category);
        json.put("aps", aps);
 
        return json.toString();
    }
    
    private int m_expireTime;
    private String m_sendTime;
    private Vector<TimeInterval> m_acceptTimes;
    private Map<String, Object> m_custom;
    private String m_raw;
    private String m_alertStr;
    private JSONObject m_alertJo;
    private int m_badge;
    private String m_sound;
    private String m_category;
    private int m_loopInterval;
    private int m_loopTimes;
}