Beispiel #1
0
        public void Handle(string postStr)
        {
            //封装请求类

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(postStr);

            XmlElement rootElement = doc.DocumentElement;

            XmlNode MsgType = rootElement.SelectSingleNode("MsgType");

            RequestXML requestXML = new RequestXML();

            requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText;

            requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;

            requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText;

            requestXML.MsgType = MsgType.InnerText;

            if (requestXML.MsgType == "text")
            {

                requestXML.Content = rootElement.SelectSingleNode("Content").InnerText;

            }

            else if (requestXML.MsgType == "location")
            {

                requestXML.Location_X = rootElement.SelectSingleNode("Location_X").InnerText;

                requestXML.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText;

                requestXML.Scale = rootElement.SelectSingleNode("Scale").InnerText;

                requestXML.Label = rootElement.SelectSingleNode("Label").InnerText;

            }

            else if (requestXML.MsgType == "image")
            {

                requestXML.PicUrl = rootElement.SelectSingleNode("PicUrl").InnerText;

            }

            else if (requestXML.MsgType == "event")
            {

                requestXML.Event = rootElement.SelectSingleNode("Event").InnerText;
                requestXML.EventKey = rootElement.SelectSingleNode("EventKey").InnerText;

            }

            //回复消息

            ResponseMsg(requestXML);
        }
Beispiel #2
0
        /// <summary>
        /// 回复消息(微信信息返回)
        /// </summary>
        /// <param name="weixinXML"></param>
        private void ResponseMsg(RequestXML requestXML)
        {
            try
            {

                string resxml = "";

                Mijiya mi = new Mijiya(requestXML.Content, requestXML.FromUserName);

                if (requestXML.MsgType == "text")
                {

                    //在这里执行一系列操作,从而实现自动回复内容.

                    string _reMsg = mi.GetReMsg();

                    if (mi.msgType == 1)
                    {

                        resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[news]]></MsgType><Content><![CDATA[]]></Content><ArticleCount>2</ArticleCount><Articles>";

                        resxml += mi.GetRePic(requestXML.FromUserName);

                        resxml += "</Articles><FuncFlag>1</FuncFlag></xml>";

                    }

                    else
                    {

                        resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + _reMsg + "]]></Content><FuncFlag>1</FuncFlag></xml>";

                    }

                }

                else if (requestXML.MsgType == "location")
                {

                    //string city = GetMapInfo(requestXML.Location_X, requestXML.Location_Y);
                    string city = "0";
                    if (city == "0")
                    {

                        resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[好啦,我们知道您的位置啦。您可以:" + requestXML.Location_X + "|" + requestXML.Location_Y + "]]></Content><FuncFlag>1</FuncFlag></xml>";

                    }

                    else
                    {

                        resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[好啦,我们知道您的位置啦。您可以:" + mi.GetDefault() + "]]></Content><FuncFlag>1</FuncFlag></xml>";

                    }

                }

                else if (requestXML.MsgType == "image")
                {

                    resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[亲,我没有看懂你的意思。您可以:" + mi.GetDefault() + requestXML.PicUrl + "]]></Content><FuncFlag>1</FuncFlag></xml>";

                    //返回10以内条

                    //int size = 10;

                    //resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[news]]></MsgType><Content><![CDATA[]]></Content><ArticleCount>" + size + "</ArticleCount><Articles>";

                    //List<string> list = new List<string>();

                    ////假如有20条查询的返回结果

                    //for (int i = 0; i < 20; i++)

                    //{

                    //    list.Add("1");

                    //}

                    //string[] piclist = new string[] { "/Abstract_Pencil_Scribble_Background_Vector_main.jpg", "/balloon_tree.jpg", "/bloom.jpg", "/colorful_flowers.jpg", "/colorful_summer_flower.jpg", "/fall.jpg", "/fall_tree.jpg", "/growing_flowers.jpg", "/shoes_illustration.jpg", "/splashed_tree.jpg" };

                    //for (int i = 0; i < size && i < list.Count; i++)

                    //{

                    //    resxml += "<item><Title><![CDATA[沈阳-黑龙江]]></Title><Description><![CDATA[元旦特价:¥300 市场价:¥400]]></Description><PicUrl><![CDATA[" + "http://www.hougelou.com" + piclist[i] + "]]></PicUrl><Url><![CDATA[http://www.hougelou.com]]></Url></item>";

                    //}

                    //resxml += "</Articles><FuncFlag>1</FuncFlag></xml>";

                }

                //else if (wx_tmsg.GetMsgCount(requestXML.FromUserName) == 0)
                //{

                //    resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + mi.GetFirst() + "]]></Content><FuncFlag>1</FuncFlag></xml>";

                //}

                else if (requestXML.MsgType == "event")
                {

                    if (requestXML.Event == "subscribe")
                    {
                        resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[您好,欢迎来到微微生活秀,我们会给你的生活带来不同的精彩。]]></Content><FuncFlag>1</FuncFlag></xml>";
                    }
                    else if (requestXML.Event == "unsubscribe")
                    {
                        resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您对我们的关注,我们会更加努力,期待您的归来。]]></Content><FuncFlag>1</FuncFlag></xml>";
                    }

                }

                else
                {

                    resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[亲,我没有看懂你的意思。您可以:" + mi.GetDefault() + "]]></Content><FuncFlag>1</FuncFlag></xml>";

                }

                //WriteTxt(resxml);

                System.Web.HttpContext.Current.Response.Write(resxml);

                //WriteToDB(requestXML, resxml, mi.pid);

            }

            catch (Exception ex)
            {

                //WriteTxt("异常:" + ex.Message + "Struck:" + ex.StackTrace.ToString());

                //wx_logs.MyInsert("异常:" + ex.Message + "Struck:" + ex.StackTrace.ToString());

            }
        }