Esempio n. 1
0
        public static string GetRequestXmlString(Stream xmlStream, IEncodingKeyProvider encodingKeyProvider)
        {
            if (xmlStream == null || xmlStream.Length == 0)
            {
                return(null);
            }
            XmlDocument doc = new XmlDocument();

            doc.Load(xmlStream);
            XmlNode firstNode = doc.FirstChild;

            if (firstNode == null)
            {
                return(null);
            }
            //if (encodingKeyProvider != null)
            //{
            //    encodingKeyProvider.InitFromXmlNode(firstNode);
            //}
            var encryptXml = firstNode.GetInnerXml("Encrypt");

            if (encryptXml != null)
            {
                return(encodingKeyProvider.Decrypt(encryptXml));
            }
            return(doc.InnerXml);
        }
Esempio n. 2
0
        /// <summary>
        /// 得到具体的消息处理实例
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static RequestMessageBase GetInstance(string xml, IEncodingKeyProvider encodingKeyProvider)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            return(GetInstance(doc, encodingKeyProvider, false));
        }
Esempio n. 3
0
        /// <summary>
        /// 得到具体的消息处理实例
        /// </summary>
        /// <param name="xmlStream"></param>
        /// <returns></returns>
        public static RequestMessageBase GetInstance(Stream xmlStream, IEncodingKeyProvider encodingKeyProvider)
        {
            if (xmlStream == null || xmlStream.Length == 0)
            {
                return(null);
            }
            ////得到请求的内容
            //byte[] bytes = new byte[xmlStream.Length];
            //xmlStream.Read(bytes, 0, (int)xmlStream.Length);
            //string xml = Encoding.UTF8.GetString(bytes);
            //return GetInstance(xml);

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlStream);
            return(GetInstance(doc, encodingKeyProvider, false));
        }
Esempio n. 4
0
        static RequestMessageBase GetEncodingInstance(string context, IEncodingKeyProvider encodingKeyProvider)
        {
            if (encodingKeyProvider == null)
            {
                return(null);
            }
            string xml = encodingKeyProvider.Decrypt(context);

            if (xml == null)
            {
            }
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            //return GetEncodingInstance(doc, encodingKeyProvider);
            return(GetInstance(doc, encodingKeyProvider, true));
        }
Esempio n. 5
0
 public string GetResponse(IEncodingKeyProvider encodingKeyProvider)
 {
     return(encodingKeyProvider.Encrypt(GetResponseInternal()));
 }
Esempio n. 6
0
        static RequestMessageBase GetInstance(XmlDocument doc, IEncodingKeyProvider encodingKeyProvider, bool encoding)
        {
            RequestMessageBase message = null;

            try
            {
                XmlNode firstNode = doc.FirstChild;
                if (firstNode == null)
                {
                    return(null);
                }
                //if (encodingKeyProvider != null)
                //{
                //    encodingKeyProvider.InitFromXmlNode(firstNode);
                //}

                var encryptXml = firstNode.GetInnerText("Encrypt");

                if (encryptXml != null)
                {
                    //var instance = GetEncodingInstance(encryptXml, encodingKeyProvider);
                    var instance = GetEncodingInstance(doc.InnerXml, encodingKeyProvider);
                    if (instance != null)
                    {
                        return(instance);
                    }
                }

                //消息类型
                var text = firstNode.GetInnerText("MsgType");
                if (text == null)
                {
                    return(null);
                }
                message = GetInstance(WeChatHelper.ToEnum <MessageType>(text));
                if (message != null)
                {
                    if (encoding)
                    {
                        message.EncodingKeyProvider = encodingKeyProvider;
                    }

                    message.Node = firstNode;
                    //发送者
                    text = firstNode.GetInnerText("FromUserName");
                    if (text == null)
                    {
                        return(null);
                    }
                    message.FromUserName = text;
                    //接收者
                    text = firstNode.GetInnerText("ToUserName");
                    if (text == null)
                    {
                        return(null);
                    }
                    message.ToUserName = text;
                    //创建时间
                    text = firstNode.GetInnerText("CreateTime");
                    if (text == null)
                    {
                        return(null);
                    }
                    message.CreateTime = Convert.ToInt64(text);

                    ////Url
                    //tempNode = firstNode.SelectSingleNode("URL");
                    //if (tempNode != null)
                    //{
                    //    message.Url = tempNode.InnerText;
                    //}


                    return(message.Parse());
                }
                return(message);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public string GetResponse(IEncodingKeyProvider encodingKeyProvider)
 {
     return("success");
 }