/// <summary>
 /// 关注
 /// </summary>
 /// <param name="wechatMessageModel"></param>
 /// <returns></returns>
 private void Subscribe(WeChatMsgViewModel wechatMessageModel)
 {
     try
     {
         LogUtil.Debug("新关注用户OpenId:" + wechatMessageModel.FromUserName);
         var dbNow  = TimeUtil.Now;
         var entity = wxUserServ.GetEntity(wechatMessageModel.FromUserName, EnumWeChatType.Client.GetHashCode());
         if (entity == null)
         {
             //新关注用户
             entity             = new WxUserEntity();
             entity.ShopId      = 0;
             entity.OpenId      = wechatMessageModel.FromUserName;
             entity.WxType      = EnumWeChatType.Client.GetHashCode();
             entity.EnabledFlag = EnabledFlagType.Valid.GetHashCode();
             entity.CreateDate  = dbNow;
             wxUserServ.InsertEntity(entity);
             LogUtil.Debug(string.Format("openId:{0},关注记录写入成功!", wechatMessageModel.FromUserName));
         }
         else
         {
             //已取消关注用户重新关注
             if (entity.EnabledFlag != EnabledFlagType.Valid.GetHashCode())
             {
                 entity.EnabledFlag = EnabledFlagType.Valid.GetHashCode();
                 wxUserServ.UpdateEntity(entity);
                 LogUtil.Debug(string.Format("openId:{0},关注记录更新成功!", wechatMessageModel.FromUserName));
             }
         }
     }
     catch (Exception ex)
     {
         LogUtil.Error(string.Format("openId:{0},关注记录写入失败,参考信息:{1}", wechatMessageModel.FromUserName, ex.Message));
     }
 }
        /// <summary>
        /// 处理json回调返回参数
        /// </summary>
        /// <param name="retstr"></param>
        public void HandleJsonCallBackStr(Stream stream, string opType = "")
        {
            byte[] b = new byte[stream.Length];
            stream.Read(b, 0, (int)stream.Length);
            string postStr = Encoding.UTF8.GetString(b);

            LogUtil.Debug(string.Format("{0}接收信息:{1}", opType, postStr));
            if (!string.IsNullOrEmpty(postStr))
            {
                WeChatMsgViewModel receiveMessageModel = new WeChatMsgViewModel();
                try
                {
                    LogUtil.Debug(string.Format("postStr:{0}", postStr));
                    WeChatDeviceMsgModel wechatDeviceMsgModel = JsonUtil.ToObject <WeChatDeviceMsgModel>(postStr);
                    LogUtil.Debug(string.Format("device_id:{0},download_url:{1},name:{2},user:{3},msg_type:{4}", wechatDeviceMsgModel.device_id, wechatDeviceMsgModel.services.wxmsg_file.download_url, wechatDeviceMsgModel.services.wxmsg_file.name, wechatDeviceMsgModel.user, wechatDeviceMsgModel.msg_type));
                    if (wechatDeviceMsgModel != null)
                    {
                        if (wechatDeviceMsgModel.msg_type.ToLower() == "set")
                        {
                            //todo...
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.Error(string.Format("json反序列化失败,异常信息:{0}", ex.Message));
                }
            }
        }
        /// <summary>
        /// 获取微信图文消息实体列表
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <param name="newsList"></param>
        /// <returns></returns>
        public string GetWxXmlNewsMsgTemplate(WeChatMsgViewModel wechatMessageModel, List <Dictionary <string, string> > newsList)
        {
            //图文项目明细
            var itemSb = new StringBuilder();

            foreach (var news in newsList)
            {
                itemSb.AppendLine("<item>");
                itemSb.AppendFormat("<Title><![CDATA[{0}]]></Title> ", news["Title"].ToString());
                itemSb.AppendFormat("<Description><![CDATA[{0}]]></Description>", news["Description"].ToString());
                itemSb.AppendFormat("<PicUrl><![CDATA[{0}]]></PicUrl>", news["PicUrl"].ToString());
                itemSb.AppendFormat("<Url><![CDATA[{0}]]></Url>", news["Url"].ToString());
                itemSb.Append("</item>");
            }

            //图文消息实体
            var xmlSb = new StringBuilder();

            xmlSb.AppendLine("<xml>");
            xmlSb.AppendFormat("<ToUserName><![CDATA[{0}]]></ToUserName>", wechatMessageModel.FromUserName);
            xmlSb.AppendFormat("<FromUserName><![CDATA[{0}]]></FromUserName>", wechatMessageModel.ToUserName);
            xmlSb.AppendFormat("<CreateTime>{0}</CreateTime>", wechatMessageModel.CreateTime);
            xmlSb.AppendLine("<MsgType><![CDATA[news]]></MsgType>");
            xmlSb.AppendFormat("<ArticleCount>{0}</ArticleCount>", newsList.Count);
            xmlSb.AppendLine("<Articles>");
            xmlSb.AppendFormat("{0}", itemSb.ToString());
            xmlSb.AppendLine("</Articles>");
            xmlSb.AppendLine("</xml>");
            return(xmlSb.ToString());
        }
        /// <summary>
        /// 关注
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <returns></returns>
        private void Subscribe(WeChatMsgViewModel wechatMessageModel)
        {
            LogUtil.Debug("openId:" + wechatMessageModel.FromUserName);
            var wxUser = SingleInstance <WeChatService> .Instance.GetWeiXinUser(wechatMessageModel.FromUserName, EnumWeChatType.Client.GetHashCode());

            if (wxUser == null)
            {
                //新关注用户
                wxUser            = new McpWeiXinUserInfo();
                wxUser.UserId     = 0;
                wxUser.OpenId     = wechatMessageModel.FromUserName;
                wxUser.WxType     = EnumWeChatType.Client.GetHashCode();
                wxUser.StatusCode = StatusCodeType.Valid.GetHashCode();
                SingleInstance <WeChatService> .Instance.BindWeiXinUser(wxUser);
            }
            else
            {
                //已取消关注用户重新关注
                if (wxUser.StatusCode != StatusCodeType.Valid.GetHashCode())
                {
                    wxUser.StatusCode = StatusCodeType.Valid.GetHashCode();
                    SingleInstance <WeChatService> .Instance.UpdateWeiXinUser(wxUser);
                }
            }
        }
        /// <summary>
        /// 关注后回复的消息内容
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <param name="xml"></param>
        /// <returns></returns>
        private string GetAubscribeAutoMessage(WeChatMsgViewModel wechatMessageModel, string xml)
        {
            string aubscribeAutoMessage = ConfigUtil.WechatSubscribeAutoMessage;

            xml = String.Format(xml, wechatMessageModel.FromUserName, wechatMessageModel.ToUserName, aubscribeAutoMessage, wechatMessageModel.CreateTime);
            return(xml);
        }
        /// <summary>
        /// 关注后回复的消息内容
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <param name="xml"></param>
        /// <returns></returns>
        private string GetAubscribeAutoMessage(WeChatMsgViewModel wechatMessageModel, string xml, string requestUrl)
        {
            string hrefUrl = String.Format("<a href='http://{0}/{1}?openid={2}'>", requestUrl, "html/login.html", wechatMessageModel.FromUserName);
            string aubscribeAutoMessage = String.Format(ConfigUtil.WechatSubscribeAutoMessage, hrefUrl, "</a>");

            xml = String.Format(xml, wechatMessageModel.FromUserName, wechatMessageModel.ToUserName, aubscribeAutoMessage, wechatMessageModel.CreateTime);
            return(xml);
        }
        /// <summary>
        /// 取消关注
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <returns></returns>
        private bool UnSubscribe(WeChatMsgViewModel wechatMessageModel)
        {
            LogUtil.Debug("openId:" + wechatMessageModel.FromUserName);
            var wxUser = SingleInstance <WeChatService> .Instance.GetWeiXinUser(wechatMessageModel.FromUserName, EnumWeChatType.Client.GetHashCode());

            LogUtil.Debug(string.Format("取消关注,微信用户openId:{0}:", wechatMessageModel.FromUserName));
            return(SingleInstance <WeChatService> .Instance.UnbindWeiXinUser(wxUser));
        }
        public string DisposeWechatMessage(WeChatMsgViewModel wechatMessageModel)
        {
            string xml = string.Empty;

            // 因为 枚举中不能使用event关键字  做特殊处理
            wechatMessageModel.MsgType = wechatMessageModel.MsgType != "event" ? wechatMessageModel.MsgType : "events";
            LogUtil.Debug("openId:" + wechatMessageModel.FromUserName);

            // 目前只处理图片 文字 和事件推送
            EnumWeChatMessageType wechatType = (EnumWeChatMessageType)Enum.Parse(typeof(EnumWeChatMessageType), wechatMessageModel.MsgType);

            switch (wechatType)
            {
            case EnumWeChatMessageType.events:
            {
                if (wechatMessageModel.Event == EnumWeChatEventType.subscribe.ToString())
                {
                    //关注
                    LogUtil.Debug("关注");
                    Subscribe(wechatMessageModel);

                    //发送关注消息
                    xml = @"<xml>
                                        <ToUserName><![CDATA[{0}]]></ToUserName>
                                        <FromUserName><![CDATA[{1}]]></FromUserName>
                                        <CreateTime>{3}</CreateTime>
                                        <MsgType><![CDATA[text]]></MsgType>
                                        <Content><![CDATA[{2}]]></Content>
                               </xml>";
                    xml = GetAubscribeAutoMessage(wechatMessageModel, xml);
                }
                if (wechatMessageModel.Event == EnumWeChatEventType.unsubscribe.ToString())
                {
                    //取消关注
                    LogUtil.Debug("取消关注");
                    UnSubscribe(wechatMessageModel);
                }
                if (wechatMessageModel.Event == EnumWeChatEventType.bind.ToString())
                {
                    //绑定设备
                    LogUtil.Debug("绑定设备");
                }
                if (wechatMessageModel.Event == EnumWeChatEventType.unbind.ToString())
                {
                    //解除绑定
                    LogUtil.Debug("解除绑定");
                }
                break;
            }

            default:
                break;
            }
            return(xml);
        }
        /// <summary>
        /// 获取微信图文消息实体
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <param name="msgTxt"></param>
        /// <returns></returns>
        private string GetWxXmlTextMsgTemplate(WeChatMsgViewModel wechatMessageModel, string msgTxt)
        {
            var xmlSb = new StringBuilder();

            xmlSb.AppendLine("<xml>");
            xmlSb.AppendFormat("<ToUserName><![CDATA[{0}]]></ToUserName>", wechatMessageModel.FromUserName);
            xmlSb.AppendFormat("<FromUserName><![CDATA[{0}]]></FromUserName>", wechatMessageModel.ToUserName);
            xmlSb.AppendFormat("<CreateTime>{0}</CreateTime>", wechatMessageModel.CreateTime);
            xmlSb.AppendLine("<MsgType><![CDATA[text]]></MsgType>");
            xmlSb.AppendFormat("<Content><![CDATA[{0}]]></Content>", msgTxt);
            xmlSb.Append("</xml>");
            return(xmlSb.ToString());
        }
        /// <summary>
        /// 获取音乐消息实体
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <param name="msgDic"></param>
        /// <returns></returns>
        public string GetWxXmMusicMsgTemplate(WeChatMsgViewModel wechatMessageModel, Dictionary <string, string> msgDic)
        {
            //音乐消息实体
            var xmlSb = new StringBuilder();

            xmlSb.AppendLine("<xml>");
            xmlSb.AppendFormat("<ToUserName><![CDATA[{0}]]></ToUserName>", wechatMessageModel.FromUserName);
            xmlSb.AppendFormat("<FromUserName><![CDATA[{0}]]></FromUserName>", wechatMessageModel.ToUserName);
            xmlSb.AppendFormat("<CreateTime>{0}</CreateTime>", wechatMessageModel.CreateTime);
            xmlSb.AppendLine("<MsgType><![CDATA[music]]></MsgType>");
            xmlSb.AppendLine("<Music>");
            xmlSb.AppendFormat("<Title><![CDATA[{0}]]></Title>", msgDic["Title"]);
            xmlSb.AppendFormat("<Description><![CDATA[{0}]]></Description>", msgDic["Description"]);
            xmlSb.AppendFormat("<MusicUrl><![CDATA[{0}]]></MusicUrl>", msgDic["MusicUrl"]);
            xmlSb.AppendFormat("<HQMusicUrl><![CDATA[{0}]]></HQMusicUrl>", msgDic["HQMusicUrl"]);
            xmlSb.AppendFormat("<ThumbMediaId><![CDATA[{0}]]></HQMusicUrl>", msgDic["ThumbMediaId"]);
            xmlSb.AppendLine("</Music>");
            xmlSb.AppendLine("</xml>");
            return(xmlSb.ToString());
        }
        /// <summary>
        /// 取消关注
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <returns></returns>
        private void UnSubscribe(WeChatMsgViewModel wechatMessageModel)
        {
            LogUtil.Debug(string.Format("取消关注,微信用户OpenId:{0}:", wechatMessageModel.FromUserName));
            using (TransactionScope tran = new TransactionScope())
            {
                var entity = wxUserServ.GetEntity(wechatMessageModel.FromUserName, EnumWeChatType.Client.GetHashCode());
                if (entity != null)
                {
                    //清空用户AccessToken强制用户重新登录
                    wxUserServ.DeleteEntity(entity.Id);
                    var currUser = SingleInstance <ShopBLL> .Instance.GetShopById(entity.ShopId);

                    if (currUser != null)
                    {
                        SingleInstance <ShopBLL> .Instance.DoLogout(currUser);
                    }
                }

                tran.Complete();
            }
        }
 /// <summary>
 /// 关键词自动回复消息内容
 /// </summary>
 /// <param name="wechatMessageModel"></param>
 /// <param name="xml"></param>
 /// <param name="responseUrl"></param>
 /// <returns></returns>
 private string GetKeyWordsAutoMessage(WeChatMsgViewModel wechatMessageModel, string xml, string responseUrl)
 {
     xml = String.Format(xml, wechatMessageModel.FromUserName, wechatMessageModel.ToUserName, responseUrl, wechatMessageModel.CreateTime);
     return(xml);
 }
        /// <summary>
        /// 处理xml推送消息后响应
        /// </summary>
        /// <param name="wechatMessageModel"></param>
        /// <param name="shopModel"></param>
        /// <returns></returns>
        public string DisposeWechatXmlMsg(WeChatMsgViewModel wechatMessageModel, string requestUrl)
        {
            string xmlMsg = string.Empty;

            // 因为 枚举中不能使用event关键字  做特殊处理
            wechatMessageModel.MsgType = wechatMessageModel.MsgType != "event" ? wechatMessageModel.MsgType : "events";
            LogUtil.Debug("openId:" + wechatMessageModel.FromUserName);

            // 目前只处理图片 文字 和事件推送
            var wechatType = (EnumWeChatMessageType)Enum.Parse(typeof(EnumWeChatMessageType), wechatMessageModel.MsgType);

            switch (wechatType)
            {
            case EnumWeChatMessageType.events:
            {
                if (wechatMessageModel.Event == EnumWeChatEventType.subscribe.ToString())
                {
                    //关注
                    LogUtil.Debug("关注");
                    //Subscribe(wechatMessageModel);

                    //发送关注消息
                    var hrefUrl = String.Format("<a href='http://{0}/{1}?openid={2}'>", requestUrl, "html/login.html", wechatMessageModel.FromUserName);
                    var aubscribeAutoMessage = String.Format(ConfigUtil.WechatSubscribeAutoMessage, hrefUrl, "</a>");
                    xmlMsg = GetWxXmlTextMsgTemplate(wechatMessageModel, aubscribeAutoMessage);
                }
                if (wechatMessageModel.Event == EnumWeChatEventType.unsubscribe.ToString())
                {
                    //取消关注
                    LogUtil.Debug("取消关注");
                    UnSubscribe(wechatMessageModel);
                    xmlMsg = EnumWeChatEventType.unsubscribe.ToString();
                }
                break;
            }

            case EnumWeChatMessageType.text:
            {
                //关键词回复
                if (wechatMessageModel.Content.Trim().ToInt() == EnumWeChatAutoMsgKey.WiFi.GetHashCode() ||
                    ConfigUtil.WechatAutoMsgKeyWord1.Contains(wechatMessageModel.Content.Trim().ToLower()))
                {
                    //Wi-Fi配网
                    var msgList = new List <Dictionary <string, string> >();
                    var msgDic  = new Dictionary <string, string>();
                    msgDic.Add("Title", EnumWeChatAutoMsgKey.WiFi.GetRemark());
                    msgDic.Add("Description", ConfigUtil.WechatAutoMsgKeyDesc1);
                    msgDic.Add("PicUrl", ConfigUtil.WechatAutoMsgKeyPicUrl1);
                    msgDic.Add("Url", ConfigUtil.WechatAutoMsgKeyUrl1);
                    msgList.Add(msgDic);
                    xmlMsg = GetWxXmlNewsMsgTemplate(wechatMessageModel, msgList);
                }
                else if (wechatMessageModel.Content.Trim().ToInt() == EnumWeChatAutoMsgKey.Guide.GetHashCode() ||
                         ConfigUtil.WechatAutoMsgKeyWord2.Contains(wechatMessageModel.Content.Trim().ToLower()))
                {
                    //平台使用指南
                    var msgList = new List <Dictionary <string, string> >();
                    var msgDic  = new Dictionary <string, string>();
                    msgDic.Add("Title", EnumWeChatAutoMsgKey.Guide.GetRemark());
                    msgDic.Add("Description", ConfigUtil.WechatAutoMsgKeyDesc2);
                    msgDic.Add("PicUrl", ConfigUtil.WechatAutoMsgKeyPicUrl2);
                    msgDic.Add("Url", ConfigUtil.WechatAutoMsgKeyUrl2);
                    msgList.Add(msgDic);
                    xmlMsg = GetWxXmlNewsMsgTemplate(wechatMessageModel, msgList);
                }
                else
                {
                    //关键词列表
                    var sbStr = new StringBuilder();
                    sbStr.AppendLine("你说啥?我没听清~");
                    sbStr.AppendLine("更多服务,请回复序号:");
                    sbStr.AppendLine("[1]查看打印机Wi-Fi配网指南");
                    sbStr.AppendLine("[2]查看平台使用指南");
                    xmlMsg = GetWxXmlTextMsgTemplate(wechatMessageModel, sbStr.ToString());
                }
                break;
            }

            default:
                break;
            }
            return(xmlMsg);
        }
        /// <summary>
        /// 处理xml回调返回参数
        /// </summary>
        /// <param name="retstr"></param>
        public string HandleXmlCallBackStr(Stream stream, string requestUrl, string opType = "")
        {
            var retStr = string.Empty;

            byte[] b = new byte[stream.Length];
            stream.Read(b, 0, (int)stream.Length);
            string postStr = Encoding.UTF8.GetString(b);

            LogUtil.Debug(string.Format("{0}接收信息:{1}", opType, postStr));
            if (!string.IsNullOrEmpty(postStr))
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(postStr);
                XmlNodeList        list = doc.GetElementsByTagName("xml");
                XmlNode            xn   = list[0];
                WeChatMsgViewModel receiveMessageModel = new WeChatMsgViewModel();
                receiveMessageModel.FromUserName = xn.SelectSingleNode("//FromUserName") != null?xn.SelectSingleNode("//FromUserName").InnerText : String.Empty;

                receiveMessageModel.ToUserName = xn.SelectSingleNode("//ToUserName") != null?xn.SelectSingleNode("//ToUserName").InnerText : String.Empty;

                receiveMessageModel.Content = xn.SelectSingleNode("//Content") != null?xn.SelectSingleNode("//Content").InnerText : String.Empty;

                receiveMessageModel.MsgType = xn.SelectSingleNode("//MsgType") != null?xn.SelectSingleNode("//MsgType").InnerText : String.Empty;

                receiveMessageModel.CreateTime = xn.SelectSingleNode("//CreateTime") != null?xn.SelectSingleNode("//CreateTime").InnerText : String.Empty;

                receiveMessageModel.Description = xn.SelectSingleNode("//Description") != null?xn.SelectSingleNode("//Description").InnerText : String.Empty;

                receiveMessageModel.Format = xn.SelectSingleNode("//Format") != null?xn.SelectSingleNode("//Format").InnerText : String.Empty;

                receiveMessageModel.MediaId = xn.SelectSingleNode("//MediaId") != null?xn.SelectSingleNode("//MediaId").InnerText : String.Empty;

                receiveMessageModel.PicUrl = xn.SelectSingleNode("//PicUrl") != null?xn.SelectSingleNode("//PicUrl").InnerText : String.Empty;

                receiveMessageModel.ThumbMediaId = xn.SelectSingleNode("//ThumbMediaId") != null?xn.SelectSingleNode("//ThumbMediaId").InnerText : String.Empty;

                receiveMessageModel.Title = xn.SelectSingleNode("//Title") != null?xn.SelectSingleNode("//Title").InnerText : String.Empty;

                receiveMessageModel.MsgId = xn.SelectSingleNode("//MsgId") != null?xn.SelectSingleNode("//MsgId").InnerText : String.Empty;

                receiveMessageModel.Event = xn.SelectSingleNode("//Event") != null?xn.SelectSingleNode("//Event").InnerText : String.Empty;

                receiveMessageModel.EventKey = xn.SelectSingleNode("//EventKey") != null?xn.SelectSingleNode("//EventKey").InnerText : String.Empty;

                receiveMessageModel.Latitude = xn.SelectSingleNode("//Latitude") != null?Extensions.ToDouble(xn.SelectSingleNode("//Latitude").InnerText) : 0;

                receiveMessageModel.Longitude = xn.SelectSingleNode("//Longitude") != null?Extensions.ToDouble(xn.SelectSingleNode("//Longitude").InnerText) : 0;

                receiveMessageModel.Precision = xn.SelectSingleNode("//Precision") != null?Extensions.ToDouble(xn.SelectSingleNode("//Precision").InnerText) : 0;

                #region 硬件平台属性

                receiveMessageModel.DeviceType = xn.SelectSingleNode("//DeviceType") != null?xn.SelectSingleNode("//DeviceType").InnerText : String.Empty;

                receiveMessageModel.DeviceID = xn.SelectSingleNode("//DeviceID") != null?xn.SelectSingleNode("//DeviceID").InnerText : String.Empty;

                receiveMessageModel.SessionID = xn.SelectSingleNode("//SessionID") != null?xn.SelectSingleNode("//SessionID").InnerText : String.Empty;

                receiveMessageModel.OpenID = xn.SelectSingleNode("//OpenID") != null?xn.SelectSingleNode("//OpenID").InnerText : String.Empty;

                #endregion

                retStr = DisposeWechatXmlMsg(receiveMessageModel, requestUrl);
            }
            return(retStr);
        }
        public void ReceiveMessage()
        {
            LogUtil.Debug(string.Format("原始消息:{0}", Request.QueryString.ToString()));

            // 判断是否是请求认证
            string echoStr = ConvertUtil.ToString(Request.QueryString["echostr"], String.Empty);

            if (CheckSignature(ConfigUtil.WechatToken))
            {
                if (!String.IsNullOrEmpty(echoStr))
                {
                    LogUtil.Debug(string.Format("自动回调:{0}", echoStr));
                    Response.Write(echoStr);
                    Response.End();
                }
                else
                {
                    Stream s = System.Web.HttpContext.Current.Request.InputStream;
                    byte[] b = new byte[s.Length];
                    s.Read(b, 0, (int)s.Length);
                    string postStr = Encoding.UTF8.GetString(b);
                    LogUtil.Debug(string.Format("接收信息:{0}", postStr));
                    if (!string.IsNullOrEmpty(postStr))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(postStr);
                        XmlNodeList        list = doc.GetElementsByTagName("xml");
                        XmlNode            xn   = list[0];
                        WeChatMsgViewModel receiveMessageModel = new WeChatMsgViewModel();
                        receiveMessageModel.FromUserName = xn.SelectSingleNode("//FromUserName") != null?xn.SelectSingleNode("//FromUserName").InnerText : String.Empty;

                        receiveMessageModel.ToUserName = xn.SelectSingleNode("//ToUserName") != null?xn.SelectSingleNode("//ToUserName").InnerText : String.Empty;

                        receiveMessageModel.Content = xn.SelectSingleNode("//Content") != null?xn.SelectSingleNode("//Content").InnerText : String.Empty;

                        receiveMessageModel.MsgType = xn.SelectSingleNode("//MsgType") != null?xn.SelectSingleNode("//MsgType").InnerText : String.Empty;

                        receiveMessageModel.CreateTime = xn.SelectSingleNode("//CreateTime") != null?xn.SelectSingleNode("//CreateTime").InnerText : String.Empty;

                        receiveMessageModel.Description = xn.SelectSingleNode("//Description") != null?xn.SelectSingleNode("//Description").InnerText : String.Empty;

                        receiveMessageModel.Format = xn.SelectSingleNode("//Format") != null?xn.SelectSingleNode("//Format").InnerText : String.Empty;

                        receiveMessageModel.MediaId = xn.SelectSingleNode("//MediaId") != null?xn.SelectSingleNode("//MediaId").InnerText : String.Empty;

                        receiveMessageModel.PicUrl = xn.SelectSingleNode("//PicUrl") != null?xn.SelectSingleNode("//PicUrl").InnerText : String.Empty;

                        receiveMessageModel.ThumbMediaId = xn.SelectSingleNode("//ThumbMediaId") != null?xn.SelectSingleNode("//ThumbMediaId").InnerText : String.Empty;

                        receiveMessageModel.Title = xn.SelectSingleNode("//Title") != null?xn.SelectSingleNode("//Title").InnerText : String.Empty;

                        receiveMessageModel.MsgId = xn.SelectSingleNode("//MsgId") != null?xn.SelectSingleNode("//MsgId").InnerText : String.Empty;

                        receiveMessageModel.Event = xn.SelectSingleNode("//Event") != null?xn.SelectSingleNode("//Event").InnerText : String.Empty;

                        receiveMessageModel.EventKey = xn.SelectSingleNode("//EventKey") != null?xn.SelectSingleNode("//EventKey").InnerText : String.Empty;

                        receiveMessageModel.Latitude = xn.SelectSingleNode("//Latitude") != null?ConvertUtil.ToDouble(xn.SelectSingleNode("//Latitude").InnerText) : 0;

                        receiveMessageModel.Longitude = xn.SelectSingleNode("//Longitude") != null?ConvertUtil.ToDouble(xn.SelectSingleNode("//Longitude").InnerText) : 0;

                        receiveMessageModel.Precision = xn.SelectSingleNode("//Precision") != null?ConvertUtil.ToDouble(xn.SelectSingleNode("//Precision").InnerText) : 0;

                        #region 硬件平台属性

                        receiveMessageModel.DeviceType = xn.SelectSingleNode("//DeviceType") != null?xn.SelectSingleNode("//DeviceType").InnerText : String.Empty;

                        receiveMessageModel.DeviceID = xn.SelectSingleNode("//DeviceID") != null?xn.SelectSingleNode("//DeviceID").InnerText : String.Empty;

                        receiveMessageModel.SessionID = xn.SelectSingleNode("//SessionID") != null?xn.SelectSingleNode("//SessionID").InnerText : String.Empty;

                        receiveMessageModel.MsgId = xn.SelectSingleNode("//MsgId") != null?xn.SelectSingleNode("//MsgId").InnerText : String.Empty;

                        receiveMessageModel.OpenID = xn.SelectSingleNode("//OpenID") != null?xn.SelectSingleNode("//OpenID").InnerText : String.Empty;

                        #endregion

                        Response.Write(DisposeWechatMessage(receiveMessageModel));
                        Response.End();
                    }
                }
            }
        }