Beispiel #1
0
        public void TestResponseNewsMessageSerialization()
        {
            var msg = new WeChatResponseNewsMessage();

            msg.FromUserName = "******";
            msg.ToUserName   = "******";
            var dt = new DateTime(2016, 3, 1, 12, 30, 11);

            msg.CreateTime = DateTimeHelper.ConvertToWeChatTimestamp(dt);
            msg.Articles.Add(new Article()
            {
                Title       = "Neuzilla 品牌介绍",
                Description = "Neuzilla作为上海芮石科技有限公司三大品牌之一,主营行业软件研发与定制服务、微信公众号开发、移动app开发、数据表单技术,条码及二维码生成及打印技术等",
                Url         = "http://mp.weixin.qq.com/s?__biz=MzIzOTM1MDYzNw==&mid=100000006&idx=1&sn=3cb63f2ce51d0c706f68d699170284c5&scene=1&srcid=0511YBgNBu9N5bg2RSxjxNi9#rd",
                PicUrl      = "https://mmbiz.qlogo.cn/mmbiz/wFDibJTSTzZ3bKghtg6Zgfulncb3jt3ZQCzfc7uCQ1Iia7N77YtrlJo8DtpEMKChibIIVGlzQyNLKjLtzjJlngTTA/0?wx_fmt=png"
            });

            var xml = XmlSerializationHelper.SerializeObject(msg);

            Assert.IsNotNull(xml);

            using (StringReader s = new StringReader(xml))
            {
                XDocument result = XDocument.Load(s);
                Assert.AreEqual("xml", result.Root.Name.LocalName);
                //Assert.AreEqual("test", result.Element("xml").Element("Image").Element("MediaId").Value);
                Assert.AreEqual("gh_a96a4a619366", result.Element("xml").Element("ToUserName").Value);
                Assert.AreEqual("olPjZjsXuQPJoV0HlruZkNzKc91E", result.Element("xml").Element("FromUserName").Value);
                Assert.AreEqual(dt, DateTimeHelper.ConvertFromWeChatTimeStamp(result.Element("xml").Element("CreateTime").Value));
            }
        }
Beispiel #2
0
        public void TestResponseImageMessageSerialization()
        {
            var msg = new WeChatResponseImageMessage();

            msg.FromUserName = "******";
            msg.ToUserName   = "******";
            var dt = new DateTime(2016, 3, 1, 12, 30, 11);

            msg.CreateTime    = DateTimeHelper.ConvertToWeChatTimestamp(dt);
            msg.Image         = new Image();
            msg.Image.MediaId = "test";

            var xml = XmlSerializationHelper.SerializeObject(msg);

            Assert.IsNotNull(xml);

            using (StringReader s = new StringReader(xml))
            {
                XDocument result = XDocument.Load(s);
                Assert.AreEqual("xml", result.Root.Name.LocalName);
                Assert.AreEqual("test", result.Element("xml").Element("Image").Element("MediaId").Value);
                Assert.AreEqual("gh_a96a4a619366", result.Element("xml").Element("ToUserName").Value);
                Assert.AreEqual("olPjZjsXuQPJoV0HlruZkNzKc91E", result.Element("xml").Element("FromUserName").Value);
                Assert.AreEqual(dt, DateTimeHelper.ConvertFromWeChatTimeStamp(result.Element("xml").Element("CreateTime").Value));
            }
        }
        public static string ToEncryptXml(this IWeChatResponseXmlMessage msg, string encodingAESKey, string appid)
        {
            string originalMsg = XmlSerializationHelper.SerializeObject(msg);

            return(Tencent.Cryptography.AES_encrypt(originalMsg, encodingAESKey, appid));
        }
 public static string ToXml(this IWeChatResponseXmlMessage msg)
 {
     return(XmlSerializationHelper.SerializeObject(msg));
 }