dev --- 3.8.0.A版本, openProject引用 ; formao-live --- 3.7.0.B 版本, formallProject引用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

512 lines
15 KiB

  1. package chanjarster.weixin.bean;
  2. import java.io.InputStream;
  3. import javax.xml.bind.JAXBException;
  4. import javax.xml.bind.annotation.XmlAccessType;
  5. import javax.xml.bind.annotation.XmlAccessorType;
  6. import javax.xml.bind.annotation.XmlElement;
  7. import javax.xml.bind.annotation.XmlRootElement;
  8. import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
  9. import chanjarster.weixin.api.WxConsts;
  10. import chanjarster.weixin.util.xml.AdapterCDATA;
  11. import chanjarster.weixin.util.xml.XmlTransformer;
  12. /**
  13. * <pre>
  14. * 微信推送过来的消息,也是同步回复给用户的消息,xml格式
  15. * 相关字段的解释看微信开发者文档:
  16. * http://mp.weixin.qq.com/wiki/index.php?title=接收普通消息
  17. * http://mp.weixin.qq.com/wiki/index.php?title=接收事件推送
  18. * http://mp.weixin.qq.com/wiki/index.php?title=接收语音识别结果
  19. * </pre>
  20. * @author chanjarster
  21. *
  22. */
  23. @XmlRootElement(name = "xml")
  24. @XmlAccessorType(XmlAccessType.FIELD)
  25. public class WxXmlMessage {
  26. ///////////////////////
  27. // 以下都是微信推送过来的消息的xml的element所对应的属性
  28. ///////////////////////
  29. @XmlElement(name="ToUserName")
  30. @XmlJavaTypeAdapter(AdapterCDATA.class)
  31. private String ToUserName;
  32. @XmlElement(name="FromUserName")
  33. @XmlJavaTypeAdapter(AdapterCDATA.class)
  34. private String FromUserName;
  35. @XmlElement(name="CreateTime")
  36. private Long CreateTime;
  37. @XmlElement(name="MsgType")
  38. @XmlJavaTypeAdapter(AdapterCDATA.class)
  39. private String MsgType;
  40. @XmlElement(name="Content")
  41. @XmlJavaTypeAdapter(AdapterCDATA.class)
  42. private String Content;
  43. @XmlElement(name="MsgId")
  44. private Long MsgId;
  45. @XmlElement(name="PicUrl")
  46. @XmlJavaTypeAdapter(AdapterCDATA.class)
  47. private String PicUrl;
  48. @XmlElement(name="MediaId")
  49. @XmlJavaTypeAdapter(AdapterCDATA.class)
  50. private String MediaId;
  51. @XmlElement(name="Format")
  52. @XmlJavaTypeAdapter(AdapterCDATA.class)
  53. private String Format;
  54. @XmlElement(name="ThumbMediaId")
  55. @XmlJavaTypeAdapter(AdapterCDATA.class)
  56. private String ThumbMediaId;
  57. @XmlElement(name="Location_X")
  58. private Double Location_X;
  59. @XmlElement(name="Location_Y")
  60. private Double Location_Y;
  61. @XmlElement(name="Scale")
  62. private Double Scale;
  63. @XmlElement(name="Label")
  64. @XmlJavaTypeAdapter(AdapterCDATA.class)
  65. private String Label;
  66. @XmlElement(name="Title")
  67. @XmlJavaTypeAdapter(AdapterCDATA.class)
  68. private String Title;
  69. @XmlElement(name="Description")
  70. @XmlJavaTypeAdapter(AdapterCDATA.class)
  71. private String Description;
  72. @XmlElement(name="Url")
  73. @XmlJavaTypeAdapter(AdapterCDATA.class)
  74. private String Url;
  75. @XmlElement(name="Event")
  76. @XmlJavaTypeAdapter(AdapterCDATA.class)
  77. private String Event;
  78. @XmlElement(name="EventKey")
  79. @XmlJavaTypeAdapter(AdapterCDATA.class)
  80. private String EventKey;
  81. @XmlElement(name="Ticket")
  82. @XmlJavaTypeAdapter(AdapterCDATA.class)
  83. private String Ticket;
  84. @XmlElement(name="Latitude")
  85. private Double Latitude;
  86. @XmlElement(name="Longitude")
  87. private Double Longitude;
  88. @XmlElement(name="Precision")
  89. private Double Precision;
  90. @XmlElement(name="Recognition")
  91. @XmlJavaTypeAdapter(AdapterCDATA.class)
  92. private String Recognition;
  93. ///////////////////////////////////////
  94. // 群发消息返回的结果
  95. ///////////////////////////////////////
  96. /**
  97. * 群发的结果
  98. */
  99. @XmlElement(name="Status")
  100. @XmlJavaTypeAdapter(AdapterCDATA.class)
  101. private String Status;
  102. /**
  103. * group_id下粉丝数;或者openid_list中的粉丝数
  104. */
  105. private Integer TotalCount;
  106. /**
  107. * 过滤(过滤是指特定地区、性别的过滤、用户设置拒收的过滤,用户接收已超4条的过滤)后,准备发送的粉丝数,原则上,FilterCount = SentCount + ErrorCount
  108. */
  109. private Integer FilterCount;
  110. /**
  111. * 发送成功的粉丝数
  112. */
  113. private Integer SentCount;
  114. /**
  115. * 发送失败的粉丝数
  116. */
  117. private Integer ErrorCount;
  118. public String getToUserName() {
  119. return ToUserName;
  120. }
  121. public void setToUserName(String toUserName) {
  122. ToUserName = toUserName;
  123. }
  124. public Long getCreateTime() {
  125. return CreateTime;
  126. }
  127. public void setCreateTime(Long createTime) {
  128. CreateTime = createTime;
  129. }
  130. /**
  131. * <pre>
  132. * 当接受用户消息时,可能会获得以下值:
  133. * {@link WxConsts#XML_MSG_TEXT}
  134. * {@link WxConsts#XML_MSG_IMAGE}
  135. * {@link WxConsts#XML_MSG_VOICE}
  136. * {@link WxConsts#XML_MSG_VIDEO}
  137. * {@link WxConsts#XML_MSG_LOCATION}
  138. * {@link WxConsts#XML_MSG_LINK}
  139. * {@link WxConsts#XML_MSG_EVENT}
  140. * </pre>
  141. * @return
  142. */
  143. public String getMsgType() {
  144. return MsgType;
  145. }
  146. /**
  147. * <pre>
  148. * 当发送消息的时候使用:
  149. * {@link WxConsts#XML_MSG_TEXT}
  150. * {@link WxConsts#XML_MSG_IMAGE}
  151. * {@link WxConsts#XML_MSG_VOICE}
  152. * {@link WxConsts#XML_MSG_VIDEO}
  153. * {@link WxConsts#XML_MSG_NEWS}
  154. * {@link WxConsts#XML_MSG_MUSIC}
  155. * </pre>
  156. * @param msgType
  157. */
  158. public void setMsgType(String msgType) {
  159. MsgType = msgType;
  160. }
  161. public String getContent() {
  162. return Content;
  163. }
  164. public void setContent(String content) {
  165. Content = content;
  166. }
  167. public Long getMsgId() {
  168. return MsgId;
  169. }
  170. public void setMsgId(Long msgId) {
  171. MsgId = msgId;
  172. }
  173. public String getPicUrl() {
  174. return PicUrl;
  175. }
  176. public void setPicUrl(String picUrl) {
  177. PicUrl = picUrl;
  178. }
  179. public String getMediaId() {
  180. return MediaId;
  181. }
  182. public void setMediaId(String mediaId) {
  183. MediaId = mediaId;
  184. }
  185. public String getFormat() {
  186. return Format;
  187. }
  188. public void setFormat(String format) {
  189. Format = format;
  190. }
  191. public String getThumbMediaId() {
  192. return ThumbMediaId;
  193. }
  194. public void setThumbMediaId(String thumbMediaId) {
  195. ThumbMediaId = thumbMediaId;
  196. }
  197. public Double getLocation_X() {
  198. return Location_X;
  199. }
  200. public void setLocation_X(Double location_X) {
  201. Location_X = location_X;
  202. }
  203. public Double getLocation_Y() {
  204. return Location_Y;
  205. }
  206. public void setLocation_Y(Double location_Y) {
  207. Location_Y = location_Y;
  208. }
  209. public Double getScale() {
  210. return Scale;
  211. }
  212. public void setScale(Double scale) {
  213. Scale = scale;
  214. }
  215. public String getLabel() {
  216. return Label;
  217. }
  218. public void setLabel(String label) {
  219. Label = label;
  220. }
  221. public String getTitle() {
  222. return Title;
  223. }
  224. public void setTitle(String title) {
  225. Title = title;
  226. }
  227. public String getDescription() {
  228. return Description;
  229. }
  230. public void setDescription(String description) {
  231. Description = description;
  232. }
  233. public String getUrl() {
  234. return Url;
  235. }
  236. public void setUrl(String url) {
  237. Url = url;
  238. }
  239. public String getEvent() {
  240. return Event;
  241. }
  242. public void setEvent(String event) {
  243. Event = event;
  244. }
  245. public String getEventKey() {
  246. return EventKey;
  247. }
  248. public void setEventKey(String eventKey) {
  249. EventKey = eventKey;
  250. }
  251. public String getTicket() {
  252. return Ticket;
  253. }
  254. public void setTicket(String ticket) {
  255. Ticket = ticket;
  256. }
  257. public Double getLatitude() {
  258. return Latitude;
  259. }
  260. public void setLatitude(Double latitude) {
  261. Latitude = latitude;
  262. }
  263. public Double getLongitude() {
  264. return Longitude;
  265. }
  266. public void setLongitude(Double longitude) {
  267. Longitude = longitude;
  268. }
  269. public Double getPrecision() {
  270. return Precision;
  271. }
  272. public void setPrecision(Double precision) {
  273. Precision = precision;
  274. }
  275. public String getRecognition() {
  276. return Recognition;
  277. }
  278. public void setRecognition(String recognition) {
  279. Recognition = recognition;
  280. }
  281. public String getFromUserName() {
  282. return FromUserName;
  283. }
  284. public void setFromUserName(String fromUserName) {
  285. FromUserName = fromUserName;
  286. }
  287. public static WxXmlMessage fromXml(String xml) {
  288. try {
  289. return XmlTransformer.fromXml(WxXmlMessage.class, xml);
  290. } catch (JAXBException e) {
  291. throw new RuntimeException(e);
  292. }
  293. }
  294. public static WxXmlMessage fromXml(InputStream is) {
  295. try {
  296. return XmlTransformer.fromXml(WxXmlMessage.class, is);
  297. } catch (JAXBException e) {
  298. throw new RuntimeException(e);
  299. }
  300. }
  301. public String getStatus() {
  302. return Status;
  303. }
  304. public void setStatus(String status) {
  305. Status = status;
  306. }
  307. public Integer getTotalCount() {
  308. return TotalCount;
  309. }
  310. public void setTotalCount(Integer totalCount) {
  311. TotalCount = totalCount;
  312. }
  313. public Integer getFilterCount() {
  314. return FilterCount;
  315. }
  316. public void setFilterCount(Integer filterCount) {
  317. FilterCount = filterCount;
  318. }
  319. public Integer getSentCount() {
  320. return SentCount;
  321. }
  322. public void setSentCount(Integer sentCount) {
  323. SentCount = sentCount;
  324. }
  325. public Integer getErrorCount() {
  326. return ErrorCount;
  327. }
  328. public void setErrorCount(Integer errorCount) {
  329. ErrorCount = errorCount;
  330. }
  331. @Override
  332. public int hashCode() {
  333. final int prime = 31;
  334. int result = 1;
  335. result = prime * result + ((Content == null) ? 0 : Content.hashCode());
  336. result = prime * result + ((CreateTime == null) ? 0 : CreateTime.hashCode());
  337. result = prime * result + ((Description == null) ? 0 : Description.hashCode());
  338. result = prime * result + ErrorCount;
  339. result = prime * result + ((Event == null) ? 0 : Event.hashCode());
  340. result = prime * result + ((EventKey == null) ? 0 : EventKey.hashCode());
  341. result = prime * result + FilterCount;
  342. result = prime * result + ((Format == null) ? 0 : Format.hashCode());
  343. result = prime * result + ((FromUserName == null) ? 0 : FromUserName.hashCode());
  344. result = prime * result + ((Label == null) ? 0 : Label.hashCode());
  345. result = prime * result + ((Latitude == null) ? 0 : Latitude.hashCode());
  346. result = prime * result + ((Location_X == null) ? 0 : Location_X.hashCode());
  347. result = prime * result + ((Location_Y == null) ? 0 : Location_Y.hashCode());
  348. result = prime * result + ((Longitude == null) ? 0 : Longitude.hashCode());
  349. result = prime * result + ((MediaId == null) ? 0 : MediaId.hashCode());
  350. result = prime * result + ((MsgId == null) ? 0 : MsgId.hashCode());
  351. result = prime * result + ((MsgType == null) ? 0 : MsgType.hashCode());
  352. result = prime * result + ((PicUrl == null) ? 0 : PicUrl.hashCode());
  353. result = prime * result + ((Precision == null) ? 0 : Precision.hashCode());
  354. result = prime * result + ((Recognition == null) ? 0 : Recognition.hashCode());
  355. result = prime * result + ((Scale == null) ? 0 : Scale.hashCode());
  356. result = prime * result + SentCount;
  357. result = prime * result + ((Status == null) ? 0 : Status.hashCode());
  358. result = prime * result + ((ThumbMediaId == null) ? 0 : ThumbMediaId.hashCode());
  359. result = prime * result + ((Ticket == null) ? 0 : Ticket.hashCode());
  360. result = prime * result + ((Title == null) ? 0 : Title.hashCode());
  361. result = prime * result + ((ToUserName == null) ? 0 : ToUserName.hashCode());
  362. result = prime * result + TotalCount;
  363. result = prime * result + ((Url == null) ? 0 : Url.hashCode());
  364. return result;
  365. }
  366. @Override
  367. public boolean equals(Object obj) {
  368. if (this == obj) return true;
  369. if (obj == null) return false;
  370. if (getClass() != obj.getClass()) return false;
  371. WxXmlMessage other = (WxXmlMessage) obj;
  372. if (Content == null) {
  373. if (other.Content != null) return false;
  374. } else if (!Content.equals(other.Content)) return false;
  375. if (CreateTime == null) {
  376. if (other.CreateTime != null) return false;
  377. } else if (!CreateTime.equals(other.CreateTime)) return false;
  378. if (Description == null) {
  379. if (other.Description != null) return false;
  380. } else if (!Description.equals(other.Description)) return false;
  381. if (ErrorCount != other.ErrorCount) return false;
  382. if (Event == null) {
  383. if (other.Event != null) return false;
  384. } else if (!Event.equals(other.Event)) return false;
  385. if (EventKey == null) {
  386. if (other.EventKey != null) return false;
  387. } else if (!EventKey.equals(other.EventKey)) return false;
  388. if (FilterCount != other.FilterCount) return false;
  389. if (Format == null) {
  390. if (other.Format != null) return false;
  391. } else if (!Format.equals(other.Format)) return false;
  392. if (FromUserName == null) {
  393. if (other.FromUserName != null) return false;
  394. } else if (!FromUserName.equals(other.FromUserName)) return false;
  395. if (Label == null) {
  396. if (other.Label != null) return false;
  397. } else if (!Label.equals(other.Label)) return false;
  398. if (Latitude == null) {
  399. if (other.Latitude != null) return false;
  400. } else if (!Latitude.equals(other.Latitude)) return false;
  401. if (Location_X == null) {
  402. if (other.Location_X != null) return false;
  403. } else if (!Location_X.equals(other.Location_X)) return false;
  404. if (Location_Y == null) {
  405. if (other.Location_Y != null) return false;
  406. } else if (!Location_Y.equals(other.Location_Y)) return false;
  407. if (Longitude == null) {
  408. if (other.Longitude != null) return false;
  409. } else if (!Longitude.equals(other.Longitude)) return false;
  410. if (MediaId == null) {
  411. if (other.MediaId != null) return false;
  412. } else if (!MediaId.equals(other.MediaId)) return false;
  413. if (MsgId == null) {
  414. if (other.MsgId != null) return false;
  415. } else if (!MsgId.equals(other.MsgId)) return false;
  416. if (MsgType == null) {
  417. if (other.MsgType != null) return false;
  418. } else if (!MsgType.equals(other.MsgType)) return false;
  419. if (PicUrl == null) {
  420. if (other.PicUrl != null) return false;
  421. } else if (!PicUrl.equals(other.PicUrl)) return false;
  422. if (Precision == null) {
  423. if (other.Precision != null) return false;
  424. } else if (!Precision.equals(other.Precision)) return false;
  425. if (Recognition == null) {
  426. if (other.Recognition != null) return false;
  427. } else if (!Recognition.equals(other.Recognition)) return false;
  428. if (Scale == null) {
  429. if (other.Scale != null) return false;
  430. } else if (!Scale.equals(other.Scale)) return false;
  431. if (SentCount != other.SentCount) return false;
  432. if (Status == null) {
  433. if (other.Status != null) return false;
  434. } else if (!Status.equals(other.Status)) return false;
  435. if (ThumbMediaId == null) {
  436. if (other.ThumbMediaId != null) return false;
  437. } else if (!ThumbMediaId.equals(other.ThumbMediaId)) return false;
  438. if (Ticket == null) {
  439. if (other.Ticket != null) return false;
  440. } else if (!Ticket.equals(other.Ticket)) return false;
  441. if (Title == null) {
  442. if (other.Title != null) return false;
  443. } else if (!Title.equals(other.Title)) return false;
  444. if (ToUserName == null) {
  445. if (other.ToUserName != null) return false;
  446. } else if (!ToUserName.equals(other.ToUserName)) return false;
  447. if (TotalCount != other.TotalCount) return false;
  448. if (Url == null) {
  449. if (other.Url != null) return false;
  450. } else if (!Url.equals(other.Url)) return false;
  451. return true;
  452. }
  453. }