/// <summary>
        /// 回复消息(微信信息返回)
        /// </summary>
        /// <param name="weixinXML"></param>
        private void ResponseMsg(WXCUST_MSG_HIS requestXML)
        {
            string resxml = "<xml><ToUserName><![CDATA[" + requestXML.FROMUSERNAME + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.TOUSERNAME + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime>";

            try
            {
                if (requestXML.MSGTYPE == "text")
                {
                    if (requestXML.CONTENT == "海报")
                    {
                        new SeaNews().SeadSeaNews(requestXML.FROMUSERNAME);
                        resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[生成海报]]></Content><FuncFlag>0</FuncFlag></xml>";
                    }
                    else
                    {
                        int count = 0;
                        List <Information_EX> list = sbo.GetModelList(string.Format("  ((KeyWords like '%{0}%' and MatchingType=0) or (KeyWords ='{0}' and MatchingType=1)) AND replytype={1} and ToUserName='******'", requestXML.CONTENT, 1, requestXML.TOUSERNAME));
                        if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                        {
                            Information_EX f = list[0];// ibo.GetModel(requestXML.EventKey, 4); //自定义菜单回复

                            if (f != null)
                            {
                                switch (f.MsgType)
                                {
                                case "text":
                                    resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                    break;

                                case "news":
                                    resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                    resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                    resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                    break;

                                case "music":
                                    resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                    break;

                                default:
                                    //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                    break;
                                }
                            }
                        }
                        else if (list.Count > 1) //多图
                        {
                            count   = list.Count;
                            resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                            for (int i = 0; i < count; i++)
                            {
                                resxml += "<item><Title><![CDATA[" + list[i].Title + "]]></Title><Description><![CDATA[" + list[i].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[i].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[i].IsURL ? (list[i].FulltextUrl.Contains("?id") ? (list[i].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[i].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[i].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                            }
                            resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                        }
                        else
                        {
                            list = sbo.GetModelList(string.Format("   replytype={0} and ToUserName='******'", 3, requestXML.TOUSERNAME));
                            if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                            {
                                Information_EX f = list[0];

                                if (f != null)
                                {
                                    switch (f.MsgType)
                                    {
                                    case "text":
                                        resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "news":
                                        resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                        resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                        resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "music":
                                        resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                        break;

                                    default:
                                        //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;
                                    }
                                }
                            }
                            else if (list.Count > 1) //多图
                            {
                                int count2 = list.Count;
                                resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                                for (int z = 0; z < count2; z++)
                                {
                                    resxml += "<item><Title><![CDATA[" + list[z].Title + "]]></Title><Description><![CDATA[" + list[z].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[z].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[z].IsURL ? (list[z].FulltextUrl.Contains("?id") ? (list[z].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[z].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[z].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                                }
                                resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                            }
                        }
                    }
                }

                else if (requestXML.MSGTYPE == "event")
                {
                    if (requestXML.WXEVENT == "CLICK")
                    {
                        if (requestXML.EVENTKEY.ToLower() == "dkf") //多客服接口
                        {
                            resxml += "<MsgType><![CDATA[transfer_customer_service]]></MsgType></xml>";
                        }
                        else
                        {
                            List <CustomMenu_EX> list = sbo.GetCustomMenuModelList(string.Format("  c.ID='{0}'", requestXML.EVENTKEY));
                            if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                            {
                                CustomMenu_EX f = list[0];// ibo.GetModel(requestXML.EventKey, 4); //自定义菜单回复

                                if (f != null)
                                {
                                    switch (f.MsgType)
                                    {
                                    case "text":
                                        resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "news":
                                        resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                        resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                        resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "music":
                                        resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                        break;

                                    default:
                                        //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;
                                    }
                                }
                            }
                            else if (list.Count > 1) //多图
                            {
                                int count = list.Count;
                                resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                                for (int i = 0; i < count; i++)
                                {
                                    resxml += "<item><Title><![CDATA[" + list[i].Title + "]]></Title><Description><![CDATA[" + list[i].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[i].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[i].IsURL ? (list[i].FulltextUrl.Contains("?id") ? (list[i].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[i].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[i].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                                }
                                resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                            }
                        }
                    }
                    else if (requestXML.WXEVENT == "unsubscribe")
                    {
                        //取消关注 把粉丝表更新状态为0

                        InsertFS(requestXML.FROMUSERNAME, requestXML.TOUSERNAME, 0); //插入粉丝信息
                    }
                    else if (requestXML.WXEVENT.ToLower() == "location")             //获取地理位置
                    {
                    }
                    else if (requestXML.WXEVENT.ToLower() == "scan" || (requestXML.WXEVENT.ToLower() == "subscribe" && requestXML.EVENTKEY.ToLower().Contains("qrscene"))) //扫描二维码
                    {
                        string EVENTKEY = requestXML.EVENTKEY;
                        requestXML.EVENTKEY = requestXML.EVENTKEY.ToLower().Contains("qrscene") ? requestXML.EVENTKEY.Split('_')[1] : requestXML.EVENTKEY;
                        new MySmallShopService().SaveQRLog(new ORG_WX_QRLog {
                            CreateTime = DateTime.Now, FromUserName = requestXML.FROMUSERNAME, QRCodeID = int.Parse(requestXML.EVENTKEY), EVENTKEY = EVENTKEY
                        });
                        if (requestXML.WXEVENT.ToLower() == "subscribe")
                        {
                            resxml = Subscribe(requestXML, resxml);
                        }
                        //string jg = InsertQR(requestXML.FROMUSERNAME, requestXML.EVENTKEY);  //插入扫描记录
                        //if (jg == "扫描成功")
                        //{
                        //    WXGraphicDetail i = sbo.GetGraphicDetail(53);
                        //    if (i != null)
                        //    {

                        //        resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                        //        resxml += "<item><Title><![CDATA[" + i.Title + "]]></Title><Description><![CDATA[" + i.Describe + "]]></Description><PicUrl><![CDATA[" + WebUrl() + i.URL + "]]></PicUrl><Url><![CDATA[" + (i.IsURL.Value ? (i.URL.Contains("?id") ? (i.URL + "&FromUserName="******"&ToUserName="******"") : (i.URL + "?FromUserName="******"&ToUserName="******"")) : (WebUrl() + "/GraphicDisplay.aspx?id=" + i.ID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                        //        resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                        //    }
                        //}
                        //else
                        //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + jg + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                    }

                    //关注
                    else if (requestXML.WXEVENT.ToLower() == "subscribe")
                    {
                        resxml = Subscribe(requestXML, resxml);
                    }
                }
                requestXML.RESXML = resxml;
                if (!resxml.Contains("</xml>"))
                {
                    resxml = "";
                    //resxml += "<MsgType><![CDATA[text]]></MsgType><Content></Content><FuncFlag>0</FuncFlag></xml>";
                }
                if (requestXML.MSGTYPE == "text")
                {
                    try
                    {
                        WXCUST_MSG_RECORD msg = new WXCUST_MSG_RECORD();
                        msg.CONTENT      = requestXML.CONTENT;
                        msg.CREATE_DATE  = DateTime.Now;
                        msg.FROMUSERNAME = requestXML.FROMUSERNAME;
                        msg.GraphicID    = 0;
                        msg.IS_RETURN    = false;
                        msg.IS_STAR      = false;
                        msg.MSGTYPE      = "text";
                        msg.ReturnID     = 0;
                        msg.State        = 0;
                        msg.TOUSERNAME   = requestXML.TOUSERNAME;
                        sbo.SaveCUST_MSG_RECORD(msg);
                    }
                    catch (Exception)
                    {
                    }
                }
                sbo.AddCUST_MSG_HIS(requestXML);
            }
            catch (Exception ex)
            {
                //WriteTxt("异常:" + ex.Message);
                //WriteTxt(sql);
                resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + ex.Message.ToString() + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                Response.Write(resxml);
            }
            //if (!resxml.Contains("</xml>"))
            //{
            //    resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[]]></Content><FuncFlag>0</FuncFlag></xml>";
            //}
            WriteTxt("返回给粉丝的消息:" + resxml);

            Response.Write(resxml);
            Response.End();
        }
        private string Subscribe(WXCUST_MSG_HIS requestXML, string resxml)
        {
            // WriteTxt("----------关注信息,消息类型:" + requestXML.MSGTYPE + "----------:" + postStr);
            //获取被关注回复的消息
            List <Information_EX> list = sbo.GetModelList(string.Format("   replytype={0} and ToUserName='******'", 2, requestXML.TOUSERNAME));

            if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
            {
                Information_EX i = list[0];
                if (i != null)
                {
                    switch (i.MsgType)
                    {
                    case "text":
                        resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + i.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                        break;

                    case "news":
                        resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                        resxml += "<item><Title><![CDATA[" + i.Title + "]]></Title><Description><![CDATA[" + i.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + i.PicUrl + "]]></PicUrl><Url><![CDATA[" + (i.IsURL ? (i.FulltextUrl.Contains("?id") ? (i.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (i.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + i.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                        resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                        break;

                    case "music":
                        resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", i.Title, i.Description, ConfigurationSettings.AppSettings["WebUrl"] + i.PicUrl);
                        break;

                    default:
                        //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的关注]]></Content><FuncFlag>0</FuncFlag></xml>";
                        break;
                    }
                }
                else
                {
                    // resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的关注]]></Content><FuncFlag>0</FuncFlag></xml>";
                }
            }
            else if (list.Count > 1) //多图
            {
                int count = list.Count;
                resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                for (int i = 0; i < count; i++)
                {
                    resxml += "<item><Title><![CDATA[" + list[i].Title + "]]></Title><Description><![CDATA[" + list[i].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[i].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[i].IsURL ? (list[i].FulltextUrl.Contains("?id") ? (list[i].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[i].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[i].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                }
                resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
            }


            ////获取Token字符串
            //string access_token = acc_Token();
            ////获取用户信息列表
            //string info = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + access_token + "&openid=" + requestXML.FROMUSERNAME + "&lang=zh_CN";
            //string infomes = PostRequestGet(info);
            //Info winfo = JsonConvert.DeserializeObject<Info>(infomes);
            ////把用户的信息存到粉丝表,保存之前先判断粉丝表里面有没有这个用户
            ////确定用户关注成功了
            //if (winfo.subscribe == 1)
            //{

            //}

            InsertFS(requestXML.FROMUSERNAME, requestXML.TOUSERNAME, 1);  //插入粉丝信息
            SaveOA(requestXML.FROMUSERNAME, requestXML.TOUSERNAME);
            return(resxml);
        }
        /// <summary>
        /// 回复消息(微信信息返回)
        /// </summary>
        /// <param name="weixinXML"></param>
        private void ResponseMsg(WXCUST_MSG_HIS requestXML)
        {
            WriteTxt(requestXML.MSGTYPE);
            string resxml = "<xml><ToUserName><![CDATA[" + requestXML.FROMUSERNAME + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.TOUSERNAME + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime>";

            try
            {
                if (requestXML.MSGTYPE == "text")
                {
                    if (requestXML.CONTENT == "海报")
                    {
                    }
                    else
                    {
                        int count = 0;
                        List <Information_EX> list = sbo.GetModelList(string.Format("  ((KeyWords like '%{0}%' and MatchingType=0) or (KeyWords ='{0}' and MatchingType=1)) AND replytype={1} and ToUserName='******'", requestXML.CONTENT, 1, requestXML.TOUSERNAME));
                        if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                        {
                            Information_EX f = list[0];// ibo.GetModel(requestXML.EventKey, 4); //自定义菜单回复

                            if (f != null)
                            {
                                switch (f.MsgType)
                                {
                                case "text":
                                    resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                    break;

                                case "news":
                                    resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                    resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                    resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                    break;

                                case "music":
                                    resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                    break;

                                default:
                                    //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                    break;
                                }
                            }
                        }
                        else if (list.Count > 1) //多图
                        {
                            count   = list.Count;
                            resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                            for (int i = 0; i < count; i++)
                            {
                                resxml += "<item><Title><![CDATA[" + list[i].Title + "]]></Title><Description><![CDATA[" + list[i].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[i].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[i].IsURL ? (list[i].FulltextUrl.Contains("?id") ? (list[i].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[i].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[i].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                            }
                            resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                        }
                        else
                        {
                            list = sbo.GetModelList(string.Format("   replytype={0} and ToUserName='******'", 3, requestXML.TOUSERNAME));
                            if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                            {
                                Information_EX f = list[0];

                                if (f != null)
                                {
                                    switch (f.MsgType)
                                    {
                                    case "text":
                                        resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "news":
                                        resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                        resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                        resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "music":
                                        resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                        break;

                                    default:
                                        //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;
                                    }
                                }
                            }
                            else if (list.Count > 1) //多图
                            {
                                int count2 = list.Count;
                                resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                                for (int z = 0; z < count2; z++)
                                {
                                    resxml += "<item><Title><![CDATA[" + list[z].Title + "]]></Title><Description><![CDATA[" + list[z].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[z].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[z].IsURL ? (list[z].FulltextUrl.Contains("?id") ? (list[z].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[z].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[z].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                                }
                                resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                            }
                        }
                    }
                }

                else if (requestXML.MSGTYPE == "event")
                {
                    if (requestXML.WXEVENT == "CLICK")
                    {
                        WriteTxt("CLICK");
                        if (requestXML.EVENTKEY == InviteMenuId)
                        {
                            resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[分享海报邀请新用户,福利多多:\n• 邀请关注,赢佰草集太极.昼御夜养.源生霜、清肌养颜太极泥、三丽鸥KITTY礼品杯\n• 关注后注册绑定,还可获得380元代金券 \n\n点击进入<a href='" + WebUrl + "/wechat/SPA/HFOldAndNew.aspx'>活动主会场</a>\n分享海报,赢惊喜大礼!]]></Content><FuncFlag>0</FuncFlag></xml>";
                        }
                        else
                        {
                            List <CustomMenu_EX> list = sbo.GetCustomMenuModelList(string.Format("  c.ID='{0}'", requestXML.EVENTKEY));
                            if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                            {
                                CustomMenu_EX f = list[0];// ibo.GetModel(requestXML.EventKey, 4); //自定义菜单回复

                                if (f != null)
                                {
                                    switch (f.MsgType)
                                    {
                                    case "text":

                                        resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "news":
                                        resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                        resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                        resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "music":
                                        resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                        break;

                                    default:
                                        //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;
                                    }
                                }
                            }
                            else if (list.Count > 1) //多图
                            {
                                int count = list.Count;
                                resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                                for (int i = 0; i < count; i++)
                                {
                                    resxml += "<item><Title><![CDATA[" + list[i].Title + "]]></Title><Description><![CDATA[" + list[i].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[i].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[i].IsURL ? (list[i].FulltextUrl.Contains("?id") ? (list[i].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[i].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[i].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                                }
                                resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                            }
                        }
                    }
                    else if (requestXML.WXEVENT == "unsubscribe")
                    {
                        //取消关注 把粉丝表更新状态为0
                        WriteTxt("取消关注");
                        if (DateTime.Now < DateTime.Parse(ActiveEndDate))
                        {
                            InsertFS(requestXML.FROMUSERNAME, requestXML.TOUSERNAME, 0);  //插入粉丝信息
                            if (DateTime.Now < DateTime.Parse(ActiveEndDate))
                            {
                                MySmallShopService mss = new MySmallShopService();
                                //将表Cust_Old_New中的Jie改成 - 1 ToUserName = openid
                                //将表Cust_Old_New中的Jie改成 - 1 FromUserName = openid  ToUserName = fx
                                mss.UpdateCustOldNewJie(requestXML.FROMUSERNAME);
                                //将表OAauth_Log中的字段SeaImg = '' 参加活动数量-1
                                OAauth_Log oa = mss.GetOA(requestXML.FROMUSERNAME);
                                if (oa != null)
                                {
                                    oa.SeaImg    = "";
                                    oa.SeaSource = null;
                                    mss.SaveOA(oa);
                                }
                            }
                        }
                    }
                    else if (requestXML.WXEVENT.ToLower() == "location") //获取地理位置
                    {
                        WriteTxt("获取地理位置");
                    }
                    else if (requestXML.WXEVENT.ToLower() == "scan" || (requestXML.WXEVENT.ToLower() == "subscribe" && requestXML.EVENTKEY.ToLower().Contains("qrscene"))) //扫描二维码
                    {
                        WriteTxt("扫二维码");
                        string EVENTKEY = requestXML.EVENTKEY;
                        requestXML.EVENTKEY = requestXML.EVENTKEY.ToLower().Contains("qrscene") ? requestXML.EVENTKEY.Split('_')[1] : requestXML.EVENTKEY;
                        int num = int.Parse(requestXML.EVENTKEY);

                        if (requestXML.WXEVENT.ToLower() == "subscribe")
                        {
                            if (num > 10000) //邀请海报
                            {
                                resxml = OldAndNew(requestXML, resxml, num);
                            }
                            resxml = Subscribe(requestXML, resxml);
                        }
                    }

                    //关注
                    else if (requestXML.WXEVENT.ToLower() == "subscribe")
                    {
                        WriteTxt("关注");
                        resxml = Subscribe(requestXML, resxml);
                        if (DateTime.Now < DateTime.Parse(ActiveEndDate))
                        {
                        }
                    }
                }
                requestXML.RESXML = resxml;
                if (!resxml.Contains("</xml>"))
                {
                    resxml = "";
                }


                AddCUST_MSG_HISHandler handler = new AddCUST_MSG_HISHandler(sbo.AddCUST_MSG_HIS);
                int result = handler.Invoke(requestXML);
                //sbo.AddCUST_MSG_HIS(requestXML);
            }
            catch (Exception ex)
            {
                resxml = "";
            }
            finally
            {
                Response.Write(resxml);
                Response.End();
            }
        }