@Test public void testNewsToXML() throws JsonProcessingException { NewsXmlMessage newsXmlMessage = new NewsXmlMessage(); News news = new News(); Article article1 = new Article(); article1.setTitle("[1]测试news"); article1.setDescription("[1]今日头条，正在调试message API, 测试是否能正常发送news类型。"); article1.setUrl("http: article1.setPicUrl("http: news.add(article1); Article article2 = new Article(); article2.setTitle("[2]测试news"); article2.setDescription("[2]今日头条，正在调试message API, 测试是否能正常发送news类型。"); article2.setUrl("http: article2.setPicUrl("http: news.add(article2); newsXmlMessage.setNews(news); newsXmlMessage.setFromUser("from user"); newsXmlMessage.setToUser("to user"); newsXmlMessage.setCreateTime(new Date()); String xml = MpXmlMessages.toXml(newsXmlMessage); Assert.assertTrue(xml.contains("<ToUserName><![CDATA[to user]]></ToUserName>")); Assert.assertTrue(xml.contains("<FromUserName><![CDATA[from user]]>")); Assert.assertTrue(xml.contains("<MsgType><![CDATA[news]]></MsgType>")); Assert.assertTrue(xml.contains("<ArticleCount>2</ArticleCount>")); Assert.assertTrue(xml.contains("<Articles><item><Title><![CDATA[[1]测试news]]></Title>")); }
public static String toXml(XmlMessageHeader xmlMessage) { try { return XmlObjectMapper.defaultMapper().toXml(xmlMessage); } catch (JsonProcessingException e) { logger.error("message to xml failed", e); throw new WxRuntimeException(999, "message to xml failed," + e.getMessage()); } }
MpXmlMessages { public static String toXml(XmlMessageHeader xmlMessage) { try { return XmlObjectMapper.defaultMapper().toXml(xmlMessage); } catch (JsonProcessingException e) { logger.error("message to xml failed", e); throw new WxRuntimeException(999, "message to xml failed," + e.getMessage()); } } }
MpXmlMessages { public static String toXml(XmlMessageHeader xmlMessage) { try { return XmlObjectMapper.defaultMapper().toXml(xmlMessage); } catch (JsonProcessingException e) { logger.error("message to xml failed", e); throw new WxRuntimeException(999, "message to xml failed," + e.getMessage()); } }  }
MpXmlMessages { public static String toXml(XmlMessageHeader xmlMessage) { try { return XmlObjectMapper.defaultMapper().toXml(xmlMessage); } catch (JsonProcessingException e) { logger.error("message to xml failed", e); throw new WxRuntimeException(999, "message to xml failed," + e.getMessage()); } }  static XmlMessageHeader fromXml(String xml); static String toXml(XmlMessageHeader xmlMessage); }
MpXmlMessages { public static String toXml(XmlMessageHeader xmlMessage) { try { return XmlObjectMapper.defaultMapper().toXml(xmlMessage); } catch (JsonProcessingException e) { logger.error("message to xml failed", e); throw new WxRuntimeException(999, "message to xml failed," + e.getMessage()); } }  static XmlMessageHeader fromXml(String xml); static String toXml(XmlMessageHeader xmlMessage);  }