1 package com.foxinmy.weixin4j.mp.model;
2
3 import java.io.Serializable;
4 import java.util.Date;
5 import java.util.List;
6
7 import com.alibaba.fastjson.JSONArray;
8 import com.alibaba.fastjson.annotation.JSONField;
9 import com.foxinmy.weixin4j.mp.type.FaceSize;
10 import com.foxinmy.weixin4j.mp.type.Lang;
11 import com.foxinmy.weixin4j.type.Gender;
12 import com.foxinmy.weixin4j.util.StringUtil;
13
14
15
16
17
18
19
20
21
22
23
24 public class User implements Serializable {
25
26 private static final long serialVersionUID = 1638176217299286265L;
27
28
29
30
31 @JSONField(name = "openid")
32 private String openId;
33
34
35
36 @JSONField(name = "nickname")
37 private String nickName;
38
39
40
41 @JSONField(name = "sex")
42 private int gender;
43
44
45
46 private String province;
47
48
49
50 private String city;
51
52
53
54 private String country;
55
56
57
58 private String headimgurl;
59
60
61
62 private JSONArray privilege;
63
64
65
66 @JSONField(name = "subscribe")
67 private boolean isSubscribe;
68
69
70
71 @JSONField(name = "subscribe_time")
72 private long subscribeTime;
73
74
75
76 private String language;
77
78
79
80 @JSONField(name = "unionid")
81 private String unionId;
82
83
84
85 private String remark;
86
87
88
89 @JSONField(name = "groupid")
90 private int groupId;
91
92
93
94 @JSONField(name = "tagid_list")
95 private List<Integer> tagIds;
96
97 public String getOpenId() {
98 return openId;
99 }
100
101 public void setOpenId(String openId) {
102 this.openId = openId;
103 }
104
105 public String getNickName() {
106 return nickName;
107 }
108
109 public void setNickName(String nickName) {
110 this.nickName = nickName;
111 }
112
113 public int getGender() {
114 return gender;
115 }
116
117 @JSONField(serialize = false)
118 public Gender getFormatGender() {
119 if (gender == 1) {
120 return Gender.male;
121 } else if (gender == 2) {
122 return Gender.female;
123 } else {
124 return Gender.unknown;
125 }
126 }
127
128 public void setGender(int gender) {
129 this.gender = gender;
130 }
131
132 public String getProvince() {
133 return province;
134 }
135
136 public void setProvince(String province) {
137 this.province = province;
138 }
139
140 public String getCity() {
141 return city;
142 }
143
144 public void setCity(String city) {
145 this.city = city;
146 }
147
148 public String getCountry() {
149 return country;
150 }
151
152 public void setCountry(String country) {
153 this.country = country;
154 }
155
156 public String getHeadimgurl() {
157 return headimgurl;
158 }
159
160 public String getHeadimgurl(FaceSize size) {
161 if (StringUtil.isNotBlank(headimgurl)) {
162 StringBuilder sb = new StringBuilder(headimgurl);
163 return sb.substring(0, headimgurl.lastIndexOf('/') + 1)
164 + size.getInt();
165 }
166 return "";
167 }
168
169 public void setHeadimgurl(String headimgurl) {
170 this.headimgurl = headimgurl;
171 }
172
173 public JSONArray getPrivilege() {
174 return privilege;
175 }
176
177 public void setPrivilege(JSONArray privilege) {
178 this.privilege = privilege;
179 }
180
181 public String getLanguage() {
182 return language;
183 }
184
185 @JSONField(serialize = false)
186 public Lang getFormatLanguage() {
187 return language != null ? Lang.valueOf(language) : null;
188 }
189
190 public void setLanguage(String language) {
191 this.language = language;
192 }
193
194 public boolean isSubscribe() {
195 return isSubscribe;
196 }
197
198 public void setSubscribe(boolean isSubscribe) {
199 this.isSubscribe = isSubscribe;
200 }
201
202 public long getSubscribeTime() {
203 return subscribeTime;
204 }
205
206 @JSONField(serialize = false)
207 public Date getFormatSubscribeTime() {
208 return new Date(subscribeTime * 1000l);
209 }
210
211 public void setSubscribeTime(long subscribeTime) {
212 this.subscribeTime = subscribeTime;
213 }
214
215 public String getUnionId() {
216 return unionId;
217 }
218
219 public void setUnionId(String unionId) {
220 this.unionId = unionId;
221 }
222
223 public String getRemark() {
224 return remark;
225 }
226
227 public void setRemark(String remark) {
228 this.remark = remark;
229 }
230
231 public int getGroupId() {
232 return groupId;
233 }
234
235 public void setGroupId(int groupId) {
236 this.groupId = groupId;
237 }
238
239 public List<Integer> getTagIds() {
240 return tagIds;
241 }
242
243 public void setTagIds(List<Integer> tagIds) {
244 this.tagIds = tagIds;
245 }
246
247 @Override
248 public int hashCode() {
249 return super.hashCode();
250 }
251
252 @Override
253 public boolean equals(Object obj) {
254 if (obj instanceof User) {
255 User another = (User) obj;
256 if (unionId != null && another.getUnionId() != null) {
257 return unionId.equals(another.getUnionId());
258 }
259 if (openId != null && another.getOpenId() != null) {
260 return openId.equals(another.getOpenId());
261 }
262 }
263 return false;
264 }
265
266 @Override
267 public String toString() {
268 return "User [openId=" + openId + ", nickName=" + nickName
269 + ", gender=" + gender + ", province=" + province + ", city="
270 + city + ", country=" + country + ", headimgurl=" + headimgurl
271 + ", privilege=" + privilege + ", isSubscribe=" + isSubscribe
272 + ", subscribeTime=" + subscribeTime + ", language=" + language
273 + ", unionId=" + unionId + ", remark=" + remark + ", groupId="
274 + groupId + ", tagIds=" + tagIds + "]";
275 }
276 }