1 package com.zone.weixin4j.request;
2
3 import com.zone.weixin4j.type.MessageType;
4
5 import javax.xml.bind.annotation.XmlElement;
6 import javax.xml.bind.annotation.XmlTransient;
7 import java.io.Serializable;
8 import java.util.Date;
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 public class WeixinMessage implements Serializable {
41
42 private static final long serialVersionUID = 7761192742840031607L;
43
44
45
46
47 @XmlElement(name = "ToUserName")
48 private String toUserName;
49
50
51
52 @XmlElement(name = "FromUserName")
53 private String fromUserName;
54
55
56
57 @XmlElement(name = "CreateTime")
58 private long createTime;
59
60
61
62 @XmlElement(name = "MsgType")
63 private String msgType;
64
65
66
67 @XmlElement(name = "MsgId")
68 private long msgId;
69
70
71
72 @XmlElement(name = "AgentID")
73 private String agentId;
74
75 public WeixinMessage() {
76
77 }
78
79 public WeixinMessage(String msgType) {
80 this.msgType = msgType;
81 }
82
83 public String getToUserName() {
84 return toUserName;
85 }
86
87 public String getFromUserName() {
88 return fromUserName;
89 }
90
91 public long getCreateTime() {
92 return createTime;
93 }
94
95 @XmlTransient
96 public Date getFormatCreateTime() {
97 return new Date(createTime * 1000l);
98 }
99
100 public String getMsgType() {
101 return msgType;
102 }
103
104 @XmlTransient
105 public MessageType getFormatMsgType() {
106 return MessageType.valueOf(msgType);
107 }
108
109 public long getMsgId() {
110 return msgId;
111 }
112
113 public String getAgentId() {
114 return agentId;
115 }
116
117 @Override
118 public int hashCode() {
119 final int prime = 31;
120 int result = 1;
121 result = prime * result + ((agentId == null) ? 0 : agentId.hashCode());
122 result = prime * result + (int) (createTime ^ (createTime >>> 32));
123 result = prime * result
124 + ((fromUserName == null) ? 0 : fromUserName.hashCode());
125 result = prime * result + (int) (msgId ^ (msgId >>> 32));
126 result = prime * result + ((msgType == null) ? 0 : msgType.hashCode());
127 result = prime * result
128 + ((toUserName == null) ? 0 : toUserName.hashCode());
129 return result;
130 }
131
132 @Override
133 public boolean equals(Object obj) {
134 if (this == obj)
135 return true;
136 if (obj == null)
137 return false;
138 if (getClass() != obj.getClass())
139 return false;
140 WeixinMessage other = (WeixinMessage) obj;
141 if (msgId > 0l && other.getMsgId() > 0l) {
142 return msgId == other.getMsgId();
143 }
144 return fromUserName.equals(other.getFromUserName())
145 && createTime == other.getCreateTime();
146 }
147
148 @Override
149 public String toString() {
150 String toString = " toUserName=" + toUserName + ", fromUserName="
151 + fromUserName + ", createTime=" + createTime + ", msgType="
152 + msgType;
153 if (msgId > 0l) {
154 toString += ", msgId=" + msgId;
155 }
156 if (agentId != null) {
157 toString += ", agentId=" + agentId;
158 }
159 return toString;
160 }
161 }