/// <summary>
        /// 测试用群发消息
        /// </summary>
        /// <param name="text"></param>
        public void Send()
        {
            var                 news       = new WX_MediaManager().Where(m => m.MediaType.Equals("news"))[0];
            List <string>       openIdList = WXAPP.WX_User.ToList().GetOpenIdList();
            string              result     = new MessageService(WXAPP.AppId, WXAPP.AppSecret).Send(news);
            WX_CustomMsgManager manager    = new WX_CustomMsgManager();
            JObject             json       = JObject.Parse(result);

            if (json["errcode"].ToString().Equals("0"))
            {
                foreach (var i in openIdList)
                {
                    WX_CustomMsg msg = new WX_CustomMsg()
                    {
                        MsgId      = json["msg_id"].ToString(),
                        OpenID     = i,
                        AppId      = WXAPP.AppId,
                        CreateTime = DateTime.Now,
                        Content    = news.MediaContent,
                        MsgSource  = "客服",
                        MsgType    = "text",
                    };
                    manager.Add(msg);
                }
            }
        }
        /// <summary>
        /// 聊天队列
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="AppId"></param>
        /// <returns></returns>
        public ActionResult SelCustom(int UserId, string AppId)
        {
            //var dic = new Dictionary<string,dynamic>();
            //var userList = new WX_CustomMsgManager().Where(x => x.UserId == UserId && x.AppId == AppId).OrderByDescending(s=>s.CreateTime);
            //foreach (var item in userList)
            //{
            //    if (!dic.ContainsKey(item.OpenID))
            //    {
            //        var msgs = new List<object>();
            //        msgs.Add(new
            //        {
            //            item.OpenID,
            //            item.WX_User.HeadImageUrl,
            //            item.Content,
            //            item.WX_User.UserName,
            //            item.WX_User.UserNick,
            //            CreateTime = DateTimeUtility.DATE(Convert.ToDateTime(item.CreateTime))

            //        });
            //        dic.Add(item.OpenID, new { msgs });
            //    }else
            //    {
            //        var msg = dic[item.OpenID];
            //        msg.msgs.Add(new
            //        {
            //            item.OpenID,
            //            item.WX_User.HeadImageUrl,
            //            item.Content,
            //            item.WX_User.UserName,
            //            item.WX_User.UserNick,
            //            CreateTime = DateTimeUtility.DATE(Convert.ToDateTime(item.CreateTime))
            //        });
            //    }
            //}
            //var result = dic.ToList();
            var userList = new WX_CustomMsgManager().Where(x => x.UserId == UserId && x.AppId == AppId).OrderByDescending(s => s.CreateTime);
            var result   = userList.GroupBy(s => s.OpenID).Select(x => new
            {
                Count = 0,
                info  = x.Select(s => new {
                    s.OpenID,
                    s.WX_User.HeadImageUrl,
                    s.Content,
                    s.WX_User.UserName,
                    s.WX_User.UserNick,
                    CreateTime = DateTimeUtility.DATE(Convert.ToDateTime(s.CreateTime))
                }).FirstOrDefault()
            });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 发送消息给用户
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public ActionResult TaleToUser(WX_CustomMsg msg)
        {
            msg.MsgId      = Guid.NewGuid().ToString();
            msg.CreateTime = DateTime.Now;
            msg.MsgSource  = "客服";
            var Ap = new WX_AppManager().GetByPK(msg.AppId);

            //发送到微信
            CustomService customSvr = new CustomService(Ap.AppId, Ap.AppSecret);

            customSvr.SendText(msg.OpenID, msg.Content);
            bool IsTrue = new WX_CustomMsgManager().Add(msg);

            return(Json(IsTrue, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="AppId"></param>
        /// <param name="OpenID"></param>
        /// <returns></returns>
        public ActionResult FansMsg(int UserId, string AppId, string OpenID)
        {
            List <WX_Queue> list = new WX_QueueManager().Where(s => s.MsgState == 1 && s.OpenID.Equals(OpenID));
            var             msg  = new List <object>();

            foreach (WX_Queue item in list)
            {
                WX_CustomMsg CM = new WX_CustomMsg();
                CM.MsgId      = item.MsgId;
                CM.OpenID     = item.OpenID;
                CM.UserId     = UserId;
                CM.AppId      = AppId;
                CM.CreateTime = item.CreateTime;
                switch (item.MsgType)
                {
                case "text":
                    CM.Content = XmlUtility.GetSingleNodeInnerText(item.XmlContent, "/xml/Content");
                    break;

                case "image":
                    CM.Content = XmlUtility.GetSingleNodeInnerText(item.XmlContent, "/xml/PicUrl");
                    break;

                case "voice":
                    CM.Content = XmlUtility.GetSingleNodeInnerText(item.XmlContent, "/xml/MediaId");
                    break;

                default:
                    break;
                }
                CM.MsgSource  = "粉丝";
                CM.MsgType    = item.MsgType;
                CM.XmlContent = item.XmlContent;
                new WX_QueueManager().Delete(item.MsgId); //删除
                new WX_CustomMsgManager().Add(CM);        //添加到数据库
                var info = new WX_CustomMsgManager().Where(s => s.MsgId == CM.MsgId).Select(s => new {
                    content = s.Content,
                    s.WX_User.HeadImageUrl,
                    s.MsgType
                });
                msg.Add(info);//添加到集合
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }