示例#1
0
        /// <summary>
        /// 解码微信推送来的消息(简报)
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static MessageRecv DecodeXMLForBrief(string xml)
        {
            XDocument doc  = XDocument.Load(new StringReader(xml));
            XElement  root = doc.Root;

            MessageRecv recv = new MessageRecv();

            recv.ToUserName   = ReadElementString(root, "ToUserName");
            recv.FromUserName = ReadElementString(root, "FromUserName");
            recv.CreateTime   = Convert.ToInt64(ReadElementString(root, "CreateTime"));
            recv.MsgType      = ReadElementString(root, "MsgType");
            recv.Event        = ReadElementString(root, "Event");
            recv.MsgId        = ReadElementString(root, "MsgId");

            return(recv);
        }
示例#2
0
        /// <summary>
        /// 解码微信推送来的消息
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static MessageRecv DecodeXML(StreamReader reader)
        {
            XDocument doc  = XDocument.Load(reader);
            XElement  root = doc.Root;

            MessageRecv recv = new MessageRecv();

            recv.ToUserName   = ReadElementString(root, "ToUserName");
            recv.FromUserName = ReadElementString(root, "FromUserName");
            recv.CreateTime   = Convert.ToInt64(ReadElementString(root, "CreateTime"));
            recv.MsgType      = ReadElementString(root, "MsgType");
            recv.Content      = ReadElementString(root, "Content");
            recv.MediaId      = ReadElementString(root, "MediaId");
            recv.PicUrl       = ReadElementString(root, "PicUrl");
            recv.Format       = ReadElementString(root, "Format");
            recv.ThumbMediaId = ReadElementString(root, "ThumbMediaId");
            recv.Location_X   = ReadElementString(root, "Location_X");
            recv.Location_Y   = ReadElementString(root, "Location_Y");
            var Scale = ReadElementString(root, "Scale");

            recv.Scale     = string.IsNullOrEmpty(Scale) ? 0 : Convert.ToInt32(Scale);
            recv.Label     = ReadElementString(root, "Label");
            recv.Event     = ReadElementString(root, "Event");
            recv.Latitude  = ReadElementString(root, "Latitude");
            recv.Longitude = ReadElementString(root, "Longitude");
            recv.Precision = ReadElementString(root, "Precision");
            recv.EventKey  = ReadElementString(root, "EventKey");
            recv.MsgId     = ReadElementString(root, "MsgId");
            try
            {
                recv.AgentID = Convert.ToInt32(ReadElementString(root, "AgentID"));
            }
            catch { }
            var ScanCodeInfoNode = root.Element("ScanCodeInfo");

            if (ScanCodeInfoNode != null)
            {
                var scanCodeInfo = new ScanCodeInfo();
                scanCodeInfo.ScanType   = ReadElementString(ScanCodeInfoNode, "ScanType");
                scanCodeInfo.ScanResult = ReadElementString(ScanCodeInfoNode, "ScanResult");
                recv.ScanCodeInfo       = scanCodeInfo;
            }

            var SendPicsInfoNode = root.Element("SendPicsInfo");

            if (SendPicsInfoNode != null)
            {
                var sendPicsInfo = new SendPicsInfo();
                sendPicsInfo.Count   = Convert.ToInt32(ReadElementString(SendPicsInfoNode, "Count"));
                sendPicsInfo.PicList = new List <SendPicsInfoItem>();
                var PicListNode = SendPicsInfoNode.Element("PicList");
                foreach (var el in PicListNode.Elements("item"))
                {
                    var item = new SendPicsInfoItem()
                    {
                        PicMd5Sum = el.Element("PicMd5Sum").Value
                    };
                    sendPicsInfo.PicList.Add(item);
                }
                recv.SendPicsInfo = sendPicsInfo;
            }

            var SendLocationInfoNode = root.Element("SendLocationInfo");

            if (SendLocationInfoNode != null)
            {
                var sendLocationInfo = new SendLocationInfo();
                sendLocationInfo            = new SendLocationInfo();
                sendLocationInfo.Location_X = ReadElementString(SendLocationInfoNode, "Location_X");
                sendLocationInfo.Location_Y = ReadElementString(SendLocationInfoNode, "Location_Y");
                sendLocationInfo.Scale      = Convert.ToInt32(ReadElementString(SendLocationInfoNode, "Scale"));
                sendLocationInfo.Label      = ReadElementString(SendLocationInfoNode, "Label");
                sendLocationInfo.Poiname    = ReadElementString(SendLocationInfoNode, "Poiname");
                recv.SendLocationInfo       = sendLocationInfo;
            }

            var BatchJobNode = root.Element("BatchJob");

            if (BatchJobNode != null)
            {
                var batchJob = new BatchJob();
                batchJob.JobId   = ReadElementString(BatchJobNode, "JobId");
                batchJob.JobType = ReadElementString(BatchJobNode, "JobType");
                batchJob.ErrCode = Convert.ToInt32(ReadElementString(BatchJobNode, "ErrCode"));
                batchJob.ErrMsg  = ReadElementString(BatchJobNode, "ErrMsg");
                recv.BatchJob    = batchJob;
            }

            return(recv);
        }