public async Task <ActionResult> DetailContent(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var site_Article = await db.Site_Articles.FindAsync(id);

            if (site_Article == null)
            {
                return(HttpNotFound());
            }
            if (site_Article.UserGroups == "0")
            {
                if (site_Article.OriginalUrl != null && site_Article.OriginalUrl.ToString().Trim() != "")
                {
                    return(Redirect(site_Article.OriginalUrl));
                }
                else
                {
                    return(PartialView(site_Article));
                }
            }
            else
            {
                string str = WeiChatApplicationContext.Current.WeiChatUser.OpenId;

                WeiChat_User us = db.WeiChat_Users.Find(str);
                if (us != null)
                {
                    if (us.GroupIds.ToString() == site_Article.UserGroups)
                    {
                        if (site_Article.OriginalUrl != null && site_Article.OriginalUrl.ToString().Trim() != "")
                        {
                            return(Redirect(site_Article.OriginalUrl));
                        }
                        else
                        {
                            return(PartialView(site_Article));
                        }
                    }
                }
                return(Content("没有权限查看"));
            }
        }
Beispiel #2
0
        public ActionResult MemberlLogin(User_Info model, string returnUrl)
        {
            string OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId;
            var    open   = db.User_Infos.Find(OpenId);

            if (open != null)
            {
                // return View("~/App/Personal?tenantId=1");
                return(RedirectToAction("Index", "Personal", new { TenantId = 1 }));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    string userid = model.Userid;
                    string pew    = model.Pwd;
                    var    user   = db.User_Infos.Where(a => a.Userid == userid && a.Pwd == pew).ToList();

                    if (user.Count == 1)
                    {
                        try
                        {
                            var          weichar = db.WeiChat_Users.Where(q => q.Remark == userid).ToList();
                            WeiChat_User wei     = new WeiChat_User();
                            wei.OpenId = weichar[0].OpenId;
                            var weiChat_User = db.WeiChat_Users.Find(wei.OpenId);
                            //删除
                            db.WeiChat_Users.Remove(weiChat_User);
                            db.SaveChanges();
                            //新增
                            wei        = weichar[0];
                            wei.OpenId = weichar[0].OpenId = OpenId;

                            // wei.Subscribe = weichar[0].Subscribe;
                            // wei.NickName = weichar[0].NickName;
                            // wei.Sex = weichar[0].Sex;
                            // wei.City = weichar[0].City;
                            // wei.Country = weichar[0].Country;
                            // wei.Province = weichar[0].Province;
                            // wei.Language = weichar[0].Language;
                            // wei.HeadImgUrl = weichar[0].HeadImgUrl;
                            // wei.SubscribeTime = weichar[0].SubscribeTime;
                            //// wei.UnionId = weichar[0].UnionId;
                            // wei.Remark = weichar[0].Remark;
                            // wei.GroupId = weichar[0].GroupId;
                            // wei.AllowTest = weichar[0].AllowTest;
                            // wei.TenantId = weichar[0].TenantId;
                            db.WeiChat_Users.Add(wei);
                            db.SaveChanges();
                            //userinfo 删除
                            var info = db.User_Infos.Where(w => w.Userid == userid).ToList();
                            model.OpenId = info[0].OpenId;
                            var user_info = db.User_Infos.Find(model.OpenId);
                            db.User_Infos.Remove(user_info);
                            db.SaveChanges();
                            //新增
                            model.OpenId = info[0].OpenId = OpenId;
                            db.User_Infos.Add(info[0]);
                            db.SaveChanges();

                            // model.Userid = info[0].Userid;
                            // model.Pwd = info[0].Pwd;
                            // model.Email = info[0].Email;
                            // model.Mobile = info[0].Mobile;
                            // model.NickName = info[0].NickName;
                            // model.TrueName = info[0].TrueName;
                            // model.IdCard = info[0].IdCard;
                            // model.Address = info[0].Address;
                            // model.WorkPlace_1 = info[0].WorkPlace_1;



                            // info.WorkPlace_1 = model.Userinfo.WorkPlace_1;
                            // info.WorkPlace_2 = model.Userinfo.WorkPlace_2;
                            // info.WorkPlace_3 = model.Userinfo.WorkPlace_3;
                            // info.Business_scope_1 = model.Userinfo.Business_scope_1;
                            // info.Business_scope_2 = model.Userinfo.Business_scope_2;
                            // info.Business_scope_3 = model.Userinfo.Business_scope_3;
                            // info.Tel_1 = model.Userinfo.Tel_1;
                            // info.Tel_2 = model.Userinfo.Tel_2;
                            // info.Tel_3 = model.Userinfo.Tel_3;
                            // weichat.OpenId = info.Userid;
                            // info.CreateTime = DateTime.Now;
                            // info.State = 0;
                            // info.Integral = 0;
                            // info.Balance = 0;
                            // info.LastLoginOn = DateTime.Now;
                            //db.User_Infos.Add(model);
                            //db.SaveChanges();
                            //await SignInAsync(model, model.RememberMe);
                            //    //登陆日志
                            //LoginSuccess(model.Userid, model.Pwd, model.TenantId);
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", ex.Message);
                            //登陆日志,失败
                            // LoginFail(model.Userid, model.Pwd);
                            return(View(model));
                        }
                        return(RedirectToAction("Index", "Personal", new { TenantId = 1 }));
                        // return View("~/App/Personal?tenantId=1");
                    }
                    else
                    {
                        //登陆日志,失败
                        LoginFail(model.Userid, model.Pwd);

                        ModelState.AddModelError("", "用户名或密码错误!");
                    }
                }
            }
            return(View(model));
        }
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            var httpContextBase = filterContext.HttpContext;
            var request         = httpContextBase.Request;

            _logger.Log(LoggerLevels.Trace, string.Format("正在获取授权...{0}", request.Url));
            //如果用户已经验证或者已经获取微信信息,则不再验证(提高效率)
            //if (WeiChatApplicationContext.Current.WeiChatUser != null)
            //{
            //    _logger.Log(LoggerLevels.Trace, string.Format("用户已经验证或者已经获取微信信息,不再验证...{0}", request.Url));
            //    return;
            //}
            var tenantId = WeiChatApplicationContext.Current.TenantId;
            //为了防止遇到用户关注多个租户的多个公众号的问题,因此此处添加租户Id参数
            var cookieName       = string.Format("{0}_{1}", WeiChatApplicationContext.OpenIdCookieName, tenantId);
            var userSesstionName = string.Format("{0}_{1}", WeiChatApplicationContext.UserSessionName, tenantId);
            //用户的OPENID
            var openIdCookie = request.Cookies[cookieName];

            openIdCookie = new HttpCookie(cookieName)
            {
                Value = "o3Q4xv9pXYCBk-pdpvgqWTbs8aLY"
            };
            var code  = request.QueryString["code"];
            var state = request.QueryString["state"];

            #region 如果是从微信验证页面跳转回来

            if (!string.IsNullOrEmpty(code) && !string.IsNullOrEmpty(state))
            {
                _logger.Log(LoggerLevels.Trace,
                            string.Format("从微信验证页面跳转回来...{2}\ncode:{0}\tstate:{1}", code, state, request.Url));
                //TODO:判断是否来自open.weixin.qq.com/connect/oauth2/authorize
                //if (request.)
                //{

                //}
                //通过code换取access_token,Code只能用一次
                //网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同
                var result = WeChatApisContext.Current.OAuthApi.Get(code);
                if (!result.IsSuccess())
                {
                    _logger.Log(LoggerLevels.Error, string.Format("授权出错,获取access_token失败...Url:{0};code:{1};DetailResult:{2}", request.Url, code, result.DetailResult));
                    throw new Exception("授权出错,获取access_token失败!");
                }
                openIdCookie = new HttpCookie(cookieName)
                {
                    Value = result.OpenId
                };

                httpContextBase.Response.Cookies.Add(openIdCookie);

                #region 获取微信用户信息

                var userInfo = WeChatApisContext.Current.OAuthApi.GetUserInfo(result.AccessToken, result.OpenId);
                if (!userInfo.IsSuccess())
                {
                    _logger.Log(LoggerLevels.Error, string.Format("授权出错,获取粉丝信息失败...Url:{0};DetailResult:{1}", request.Url, userInfo.DetailResult));
                    throw new Exception("授权出错,获取粉丝信息失败!");
                }
                WeiChat_User user;
                try
                {
                    using (var db = new AppDbContext())
                    {
                        user = db.WeiChat_Users.FirstOrDefault(p => p.OpenId == userInfo.OpenId);
                        if (user == null)
                        {
                            var currentUserInfo = db.User_Infos.FirstOrDefault(p => p.OpenId == userInfo.OpenId);
                            if (currentUserInfo == null)
                            {
                                currentUserInfo = new User_Info
                                {
                                    OpenId      = userInfo.OpenId,
                                    Balance     = 0,
                                    Integral    = 0,
                                    State       = EnumUserState.Normal,
                                    TenantId    = tenantId,
                                    CreateTime  = DateTime.Now,
                                    LastLoginOn = DateTime.Now,
                                    LoginCount  = 0
                                };
                                _logger.Log(LoggerLevels.Trace, "新增userinfo对象");
                                db.User_Infos.Add(currentUserInfo);
                            }
                            user = new WeiChat_User
                            {
                                City    = userInfo.City,
                                Country = userInfo.Country,
                                //GroupId = userInfo.groupid,
                                HeadImgUrl = userInfo.Headimgurl,
                                //Language = userInfo.language,
                                NickName = userInfo.NickName,
                                OpenId   = userInfo.OpenId,
                                Province = userInfo.Province,
                                //Remark = userInfo.remark,
                                Sex           = userInfo.Sex,
                                Subscribe     = false,
                                SubscribeTime = DateTime.Now,
                                UnionId       = userInfo.Unionid,
                                TenantId      = tenantId
                            };
                            db.WeiChat_Users.Add(user);
                            db.SaveChanges();
                        }
                        else
                        {
                            _logger.Log(LoggerLevels.Trace,
                                        string.Format("用户信息已存在...\n{0}\n{1}", request.Url, JsonConvert.SerializeObject(user)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.Log(LoggerLevels.Error, string.Format("{0}\n{1}\n{2}", request.Url, ex.Message, ex));
                    //filterContext.Result = new ContentResult { Content = "授权出错:" + code + "     具体错误:" + ex.Message };
                    throw new Exception("授权出错:" + code + "     具体错误:" + ex.Message);
                }
                if (!HttpContext.Current.Items.Contains(userSesstionName))
                {
                    HttpContext.Current.Items.Add(userSesstionName, user);
                }
                HttpContext.Current.Session[userSesstionName] = user;
                _logger.Log(LoggerLevels.Trace, string.Format("已成功赋值...\n{0}", request.Url));
                var redirectUrlCookie = request.Cookies[RedirectUrlCookieName];
                if (redirectUrlCookie != null)
                {
                    var redirectUrl = redirectUrlCookie.Value;
                    if (httpContextBase.Response.Cookies[RedirectUrlCookieName] != null)
                    {
                        httpContextBase.Response.Cookies.Remove(RedirectUrlCookieName);
                    }
                    filterContext.Result = new RedirectResult(redirectUrl);
                }

                #endregion
            }
            #endregion
            #region 如果没有验证,则进行验证

            //else if (string.IsNullOrEmpty(openIdCookie?.Value))
            //{
            //    var redirectUrl = request.Url.ToString();

            //    var cookie = new HttpCookie(RedirectUrlCookieName) { Value = redirectUrl };
            //    httpContextBase.Response.Cookies.Add(cookie);
            //    //获取授权Url
            //    var url = WeChatApisContext.Current.OAuthApi.GetAuthorizeUrl(redirectUrl, _state,WeChat.SDK.Apis.OAuth.OAuthScopes.snsapi_base);
            //    _logger.Log(LoggerLevels.Trace, string.Format("跳转至微信服务器获取授权...\n{0}\n{1}", redirectUrl, url));
            //    filterContext.Result = new RedirectResult(url);
            //}
            #endregion
            #region 如果已验证

            else if ((openIdCookie != null) && !string.IsNullOrEmpty(openIdCookie.Value))
            {
                var openId = openIdCookie.Value;
                _logger.Log(LoggerLevels.Trace, string.Format("从openIdCookie获取openId...{0}", openId));
                using (var db = new AppDbContext())
                {
                    var user = db.WeiChat_Users.FirstOrDefault(p => p.OpenId == openId);
                    if (user != null)
                    {
                        _logger.Log(LoggerLevels.Trace, string.Format("已从数据库获取到粉丝信息...{0}", openId));
                        HttpContext.Current.Items.Add(userSesstionName, user);
                        HttpContext.Current.Session[userSesstionName] = user;
                    }
                    else
                    {
                        try
                        {
                            var redirectUrl = request.Url.ToString();
                            _logger.Log(LoggerLevels.Trace, string.Format("准备跳转至微信服务器获取授权...\n{0}", redirectUrl));
                            var cookie = new HttpCookie(RedirectUrlCookieName);
                            cookie.Value = redirectUrl;
                            httpContextBase.Response.Cookies.Add(cookie);
                            //获取授权Url
                            var url = WeChatApisContext.Current.OAuthApi.GetAuthorizeUrl(redirectUrl, _state);
                            _logger.Log(LoggerLevels.Trace, string.Format("跳转至微信服务器获取授权...\n{0}\n{1}", redirectUrl, url));
                            //注意修改授权回调页面域名
                            filterContext.Result = new RedirectResult(url);
                        }
                        catch (Exception ex)
                        {
                            _logger.Log(LoggerLevels.Error, ex);
                            throw ex;
                        }
                    }
                }
            }
            #endregion

            else
            {
                _logger.Log(LoggerLevels.Error, string.Format("授权出错,请检查...{0}", request.Url));
                filterContext.Result = new ContentResult {
                    Content = "授权出错,请检查!"
                };
            }
        }
Beispiel #4
0
        /// <summary>
        ///     订阅(关注)事件
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            IResponseMessageBase responseMessage = null;
            {
                #region 获取并更新新关注用户的信息

                try
                {
                    //由于这里是基于微信服务器事件,故不能使用WeChatApisContext.Current.UserApi方式获取到UserApi接口,请new一个然后通过SetKey进行赋值
                    var userApi = new UserApi();
                    userApi.SetKey(TenantId);
                    //获取新关注用户的用户信息
                    var userInfoResult = userApi.Get(requestMessage.FromUserName);
                    if (userInfoResult.IsSuccess())
                    {
                        var user     = db.WeiChat_Users.FirstOrDefault(p => p.OpenId == userInfoResult.OpenId);
                        var userinfo = db.User_Infos.FirstOrDefault(p => p.OpenId == userInfoResult.OpenId);
                        if (userinfo == null)
                        {
                            userinfo = new User_Info
                            {
                                OpenId      = userInfoResult.OpenId,
                                Balance     = 0,
                                Integral    = 0,
                                State       = EnumUserState.Normal,
                                TenantId    = TenantId,
                                CreateTime  = DateTime.Now,
                                LastLoginOn = DateTime.Now,
                                LoginCount  = 0
                            };
                            db.User_Infos.Add(userinfo);
                        }

                        if (user == null)
                        {
                            user = new WeiChat_User
                            {
                                City          = userInfoResult.City,
                                Country       = userInfoResult.Country,
                                GroupIds      = userInfoResult.GroupIds,
                                HeadImgUrl    = userInfoResult.Headimgurl,
                                Language      = userInfoResult.Language,
                                NickName      = userInfoResult.NickName,
                                OpenId        = userInfoResult.OpenId,
                                Province      = userInfoResult.Province,
                                Remark        = userInfoResult.Remark,
                                Sex           = userInfoResult.Sex,
                                Subscribe     = true,
                                SubscribeTime = userInfoResult.SubscribeTime,
                                UnionId       = userInfoResult.Unionid,
                                TenantId      = TenantId
                            };
                            db.WeiChat_Users.Add(user);
                        }
                        else
                        {
                            user.City       = userInfoResult.City;
                            user.Country    = userInfoResult.Country;
                            user.GroupIds   = userInfoResult.GroupIds;
                            user.HeadImgUrl = userInfoResult.Headimgurl;
                            user.Language   = userInfoResult.Language;
                            user.NickName   = userInfoResult.NickName;
                            //user.OpenId=userInfoResult.OpenId
                            user.Province      = userInfoResult.Province;
                            user.Remark        = userInfoResult.Remark;
                            user.Sex           = userInfoResult.Sex;
                            user.Subscribe     = true;
                            user.SubscribeTime = userInfoResult.SubscribeTime;
                            user.TenantId      = TenantId;
                            user.UnionId       = userInfoResult.Unionid;
                        }
                        db.SaveChanges();
                    }
                    else
                    {
                        logger.Log(LoggerLevels.Error, userInfoResult.GetFriendlyMessage() + "\n\r详细错误:" + userInfoResult.DetailResult);
                    }
                }
                catch (Exception ex)
                {
                    logger.Log(LoggerLevels.Error, "MessageId:" + requestMessage.MsgId + Environment.NewLine + "具体错误信息:" + ex);
                }

                #endregion

                var keyword = string.Format("{0}[系统关注事件]", requestMessage.EventKey);

                //回复日志
                var replylog = new WeiChat_KeyWordReplyLog
                {
                    ReceiveWords = keyword,
                    CreateTime   = DateTime.Now,
                    TenantId     = TenantId,
                    From         = requestMessage.FromUserName,
                    To           = requestMessage.ToUserName,
                    EventKey     = requestMessage.EventKey,
                    MsgId        = requestMessage.MsgId
                };
                try
                {
                    var subscribeReplies = db.WeiChat_SubscribeReplies.FirstOrDefault();
                    if (subscribeReplies != null)
                    {
                        replylog.ContentId = subscribeReplies.ContentId;
                        replylog.KeyWord   = "";
                        replylog.WeiChat_KeyWordAutoReplyId = subscribeReplies.Id;

                        responseMessage = this.ReplyResponseMessage(db, keyword, subscribeReplies.ContentId,
                                                                    subscribeReplies.KeyWordContentType,
                                                                    (key, contentId, type) => { replylog.IsSuccess = true; });
                    }
                }
                catch (Exception ex)
                {
                    replylog.Error  = ex.ToString();
                    responseMessage = CreateResponseMessage <ResponseMessageText>();
                    ((ResponseMessageText)responseMessage).Content = HttpContext.Current.IsDebuggingEnabled
                        ? ex.ToString()
                        : "出现错误,无法处理请求,具体信息请查看回复日志!";
                }
                //记录日志
                db.WeiChat_KeyWordReplyLogs.Add(replylog);
                db.SaveChanges();
            }
            if (responseMessage == null)
            {
                responseMessage = ResponseMessageBase.CreateFromRequestMessage <ResponseMessageText>(requestMessage);
                ((ResponseMessageText)responseMessage).Content = "欢迎您关注Magicodes.WeiChat!";
                return(responseMessage);
            }
            return(responseMessage);
        }
Beispiel #5
0
        protected override void Seed(AppDbContext context)
        {
            var tenant = context.Admin_Tenants.FirstOrDefault(p => p.IsSystemTenant);

            if (tenant == null)
            {
                tenant = new Admin_Tenant {
                    IsSystemTenant = true, Name = "系统租户", Remark = "系统租户,勿删!"
                };
                context.Admin_Tenants.Add(tenant);
                context.SaveChanges();
            }

            #region 添加用户和角色

            //全局管理员多租户Id为1
            var store = new AppUserStore(context)
            {
                TenantId = tenant.Id
            };
            var userManager = new UserManager <AppUser, string>(store);
            var roleManager = new RoleManager <AppRole>(new AppRoleStore(context));
            //系统管理员
            var adminRole = new AppRole
            {
                Id          = "{74ABBD8D-ED32-4C3A-9B2A-EB134BFF5D91}",
                Name        = "Admin",
                Description = "超级管理员,拥有最大权限"
            };
            if (!roleManager.RoleExists(adminRole.Name))
            {
                roleManager.Create(adminRole);
            }
            //租户管理员
            var tenantManager = new AppRole
            {
                Id          = "{EB715DD5-1EEF-4131-B6B1-0DAE2FAA8861}",
                Name        = "TenantManager",
                Description = "租户管理员"
            };
            if (!roleManager.RoleExists(tenantManager.Name))
            {
                roleManager.Create(tenantManager);
            }
            //店铺管理员
            var shopManager = new AppRole
            {
                Id          = "{80BAB54E-856E-4DBE-85E1-A5F819BF9622}",
                Name        = "ShopManager",
                Description = "店铺管理员"
            };
            if (!roleManager.RoleExists(shopManager.Name))
            {
                roleManager.Create(shopManager);
            }
            //店铺小二
            var shopWater = new AppRole
            {
                Id          = "{F77E3025-026F-44DA-8565-18B1018E88F8}",
                Name        = "ShopWater",
                Description = "店铺小二"
            };
            if (!roleManager.RoleExists(shopWater.Name))
            {
                roleManager.Create(shopWater);
            }

            var user = new AppUser
            {
                Id             = "{B0FBB2AC-3174-4E5A-B772-98CF776BD4B9}",
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                TenantId       = tenant.Id
            };
            if (!userManager.Users.Any(p => p.Id == user.Id))
            {
                var result = userManager.Create(user, "123456abcD");
                if (result.Succeeded)
                {
                    userManager.AddToRole(user.Id, adminRole.Name);
                }
            }

            #endregion

            #region 初始化菜单

            if (!context.Site_Menus.Any())
            {
                var menus      = new List <Site_Menu>();
                var menuWeChat = MenuDataSeedHelper.CreateRootMenu("微信功能管理", "", "", "", "fa fa-weixin");
                menus.Add(menuWeChat);

                #region 自定义菜单

                var menu1 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "菜单管理", "", "", "", "fa fa-th-large");
                menus.Add(menu1);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu1.Id, "自定义菜单", "Index", "Menus", "/Menus", ""));

                #endregion

                #region 粉丝管理

                var menu2 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "粉丝管理", "", "", "", "fa fa-users");
                menus.Add(menu2);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu2.Id, "粉丝管理", "Index", "WeiChat_User", "/WeiChat_User",
                                                             ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu2.Id, "用户组管理", "Index", "WeiChat_UserGroup",
                                                             "/WeiChat_UserGroup", ""));

                #endregion

                #region  材管理

                var menu3 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "素材管理", "", "", "", "fa fa-file-image-o");
                menus.Add(menu3);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "图片管理", "Index", "Site_Resources",
                                                             "/Site_Resources?resourceType=0", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "语音管理", "Index", "Site_Resources",
                                                             "/Site_Resources?resourceType=1", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "视频管理", "Index", "Site_Resources",
                                                             "/Site_Resources?resourceType=2", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "图文消息管理", "Index", "Site_News", "/Site_News", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu3.Id, "文章管理", "Index", "Site_Article", "/Site_Article",
                                                             ""));

                #endregion

                #region 消息管理

                var menu4 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "消息管理", "", "", "", "fa  fa-comments-o");
                menus.Add(menu4);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "文本推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=0", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "图片推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=1", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "语音推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=3", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "视频推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=4", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "图文推送", "Send", "GroupMessage",
                                                             "/GroupMessage/Send?type=5", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu4.Id, "模板消息", "Index", "WeiChat_MessagesTemplate",
                                                             "/WeiChat_MessagesTemplate", ""));

                #endregion

                #region 场景二维码

                var menu5 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "场景二维码", "", "", "", "fa fa-qrcode");
                menus.Add(menu5);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu5.Id, "二维码管理", "Index", "WeiChat_QRCode",
                                                             "/WeiChat_QRCode", ""));

                #endregion

                #region 客服管理

                var menu6 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "客服管理", "", "", "", "fa fa-users");
                menus.Add(menu6);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu6.Id, "客服管理", "Index", "WeiChat_KFCInfo",
                                                             "/WeiChat_KFCInfo", ""));

                #endregion

                #region 智能回复

                var menu7 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "智能回复", "", "", "", "fa fa-slack");
                menus.Add(menu7);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu7.Id, "关键字回复", "Index", "WeiChat_KeyWordAutoReply",
                                                             "/WeiChat_KeyWordAutoReply", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu7.Id, "关注时回复", "Index", "WeiChat_SubscribeReply",
                                                             "/WeiChat_SubscribeReply", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu7.Id, "答不上来配置", "Index", "WeiChat_NotAnswerReply",
                                                             "/WeiChat_NotAnswerReply", ""));

                #endregion

                #region 数据与统计

                var menu8 = MenuDataSeedHelper.CreateChildMenu(menuWeChat.Id, "数据与统计", "", "", "", "fa fa-line-chart");
                menus.Add(menu8);
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu8.Id, "关键字回复统计", "Index", "WeiChat_KeyWordReplyLog",
                                                             "/WeiChat_KeyWordReplyLog", ""));
                menus.Add(MenuDataSeedHelper.CreateChildMenu(menu8.Id, "位置统计", "Index", "WeiChat_LocationEventLog",
                                                             "/WeiChat_LocationEventLog", ""));

                #endregion

                //var menu1 = MenuDataSeedHelper.CreateRootMenu(title: "菜单管理", action: "", controller: "", url: "", iconCls: "fa fa-th-large");
                //menus.Add(menu1);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu1.Id, title: "自定义菜单", action: "Index", controller: "Menus", url: "/Menus", iconCls: ""));

                //var menu2 = MenuDataSeedHelper.CreateRootMenu(title: "粉丝管理", action: "", controller: "", url: "", iconCls: "fa fa-users");
                //menus.Add(menu2);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu2.Id, title: "粉丝管理", action: "Index", controller: "WeiChat_User", url: "/WeiChat_User", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu2.Id, title: "用户组管理", action: "Index", controller: "WeiChat_UserGroup", url: "/WeiChat_UserGroup", iconCls: ""));

                //var menu3 = MenuDataSeedHelper.CreateRootMenu(title: "素材管理", action: "", controller: "", url: "", iconCls: "fa fa-file-image-o");
                //menus.Add(menu3);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "图片管理", action: "Index", controller: "Site_Resources", url: "/Site_Resources?resourceType=0", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "语音管理", action: "Index", controller: "Site_Resources", url: "/Site_Resources?resourceType=1", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "视频管理", action: "Index", controller: "Site_Resources", url: "/Site_Resources?resourceType=2", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "图文消息管理", action: "Index", controller: "Site_News", url: "/Site_News", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu3.Id, title: "文章管理", action: "Index", controller: "Site_Article", url: "/Site_Article", iconCls: ""));

                //var menu4 = MenuDataSeedHelper.CreateRootMenu(title: "消息管理", action: "", controller: "", url: "", iconCls: "fa  fa-comments-o");
                //menus.Add(menu4);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "文本推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=0", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "图片推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=1", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "语音推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=3", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "视频推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=4", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "图文推送", action: "Send", controller: "GroupMessage", url: "/GroupMessage/Send?type=5", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu4.Id, title: "模板消息", action: "Index", controller: "WeiChat_MessagesTemplate", url: "/WeiChat_MessagesTemplate", iconCls: ""));

                //var menu5 = MenuDataSeedHelper.CreateRootMenu(title: "场景二维码", action: "", controller: "", url: "", iconCls: "fa fa-qrcode");
                //menus.Add(menu5);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu5.Id, title: "二维码管理", action: "Index", controller: "WeiChat_QRCode", url: "/WeiChat_QRCode", iconCls: ""));

                //var menu6 = MenuDataSeedHelper.CreateRootMenu(title: "客服管理", action: "", controller: "", url: "", iconCls: "fa fa-users");
                //menus.Add(menu6);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu6.Id, title: "客服管理", action: "Index", controller: "WeiChat_KFCInfo", url: "/WeiChat_KFCInfo", iconCls: ""));

                //var menu7 = MenuDataSeedHelper.CreateRootMenu(title: "智能回复", action: "", controller: "", url: "", iconCls: "fa fa-slack");
                //menus.Add(menu7);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu7.Id, title: "关键字回复", action: "Index", controller: "WeiChat_KeyWordAutoReply", url: "/WeiChat_KeyWordAutoReply", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu7.Id, title: "关注时回复", action: "Index", controller: "WeiChat_SubscribeReply", url: "/WeiChat_SubscribeReply", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu7.Id, title: "答不上来配置", action: "Index", controller: "WeiChat_NotAnswerReply", url: "/WeiChat_NotAnswerReply", iconCls: ""));

                //var menu8 = MenuDataSeedHelper.CreateRootMenu(title: "数据与统计", action: "", controller: "", url: "", iconCls: "fa fa-line-chart");
                //menus.Add(menu8);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu8.Id, title: "关键字回复统计", action: "Index", controller: "WeiChat_KeyWordReplyLog", url: "/WeiChat_KeyWordReplyLog", iconCls: ""));
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu8.Id, title: "位置统计", action: "Index", controller: "WeiChat_LocationEventLog", url: "/WeiChat_LocationEventLog", iconCls: ""));

                //var menu9 = MenuDataSeedHelper.CreateRootMenu(title: "系统设置", action: "", controller: "", url: "", iconCls: "fa fa-cogs");
                //menus.Add(menu9);
                //menus.Add(MenuDataSeedHelper.CreateChildMenu(parentId: menu9.Id, title: "微信支付设置", action: "Index", controller: "WeiChat_PayConfig", url: "/WeiChat_PayConfig", iconCls: ""));


                context.Site_Menus.AddRange(menus);
                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    var str = "";
                    foreach (var item in ex.EntityValidationErrors)
                    {
                        foreach (var eitem in item.ValidationErrors)
                        {
                            str += eitem.PropertyName + ":" + eitem.ErrorMessage;
                        }
                    }
                    throw new Exception(str);
                }
                //初始化角色菜单
                if (!context.Role_Menus.Any(p => p.RoleId == adminRole.Id))
                {
                    foreach (var item in menus)
                    {
                        context.Role_Menus.Add(new Role_Menu
                        {
                            MenuId = item.Id,
                            RoleId = adminRole.Id
                        });
                    }
                    context.SaveChanges();
                }
            }

            #endregion

            #region 初始化默认相册
            if (context.Site_PhotoGallerys.Find(new Guid("6FAC25BF-DBE1-423D-93C8-FB31D98D8F72")) == null)
            {
                var photoGallery = new Site_PhotoGallery
                {
                    Id         = new Guid("6FAC25BF-DBE1-423D-93C8-FB31D98D8F72"),
                    Title      = "首页滚动图片相册",
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Site_PhotoGallerys.Add(photoGallery);
                context.SaveChanges();
            }
            #endregion

            #region 初始化商品标签
            //精品排行标签
            if (context.Product_Tags.Find(new Guid("527BD456-2411-4BAB-A67B-4760752D7198")) == null)
            {
                var jpphTag = new Product_Tag
                {
                    Id         = new Guid("527BD456-2411-4BAB-A67B-4760752D7198"),
                    Name       = "精品排行",
                    IsSystem   = true,
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Product_Tags.Add(jpphTag);
            }
            //新品促销标签
            if (context.Product_Tags.Find(new Guid("A2587E2F-B1ED-4F24-A089-4201E40780C5")) == null)
            {
                var xpcxTag = new Product_Tag
                {
                    Id         = new Guid("A2587E2F-B1ED-4F24-A089-4201E40780C5"),
                    Name       = "新品促销",
                    IsSystem   = true,
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Product_Tags.Add(xpcxTag);
            }
            //热门推荐标签
            if (context.Product_Tags.Find(new Guid("D8970F09-6C1B-429D-8E33-EC16AC90BC11")) == null)
            {
                var rmtjTag = new Product_Tag
                {
                    Id         = new Guid("D8970F09-6C1B-429D-8E33-EC16AC90BC11"),
                    Name       = "热门推荐",
                    IsSystem   = true,
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Product_Tags.Add(rmtjTag);
            }
            #endregion
            #region 初始化默认广告位
            if (context.Advert_Types.Find(new Guid("6FAC25BF-DBE1-423D-93C8-FB31D98D8F72")) == null)
            {
                var advertType = new Advert_Type
                {
                    Id         = new Guid("6FAC25BF-DBE1-423D-93C8-FB31D98D8F72"),
                    Name       = "首页滚动图片广告位置",
                    IsSystem   = true,
                    CreateTime = DateTime.Now,
                    CreateBy   = user.Id,
                    TenantId   = 1
                };
                context.Advert_Types.Add(advertType);
                context.SaveChanges();
            }
            #endregion
            #region 添加WeiChat_User
            if (!context.WeiChat_Users.Any())
            {
                var weichatuser = new WeiChat_User
                {
                    OpenId        = "o3Q4xv9pXYCBk-pdpvgqWTbs8aLY",
                    Subscribe     = true,
                    NickName      = "差不多先生",
                    Sex           = WeChat.SDK.Apis.User.WeChatSexTypes.Man,
                    City          = "linfen",
                    Country       = "中国",
                    Province      = "山西",
                    Language      = "zh_CN",
                    HeadImgUrl    = "http://wx.qlogo.cn/mmopen/rycTXpWzibw2l9v7TNN0uFGcjQzHCic6tcOy8dLLnkPTZdP7rZxsSXXQCRJRjoXpKWhkRXnOol544kE6S5Of6uRg/0",
                    UnionId       = "1",
                    Remark        = "9054",
                    GroupIds      = "102",
                    AllowTest     = false,
                    TenantId      = 1,
                    SubscribeTime = DateTime.Parse("2016 - 11 - 24 08:58:56.000")
                };
                context.WeiChat_Users.Add(weichatuser);
                context.SaveChanges();
            }
            #endregion
            #region 添加AppUserInfo
            if (!context.AppUserInfos.Any(p => p.OpenId == "o3Q4xv9pXYCBk - pdpvgqWTbs8aLY"))
            {
                var appUserInfo = new AppUserInfo
                {
                    //Id = new Guid(),
                    UserNo           = 1,
                    OpenId           = "o3Q4xv9pXYCBk - pdpvgqWTbs8aLY",
                    Member_loginname = "bb",
                    Member_password  = "******",
                    Nick_name        = "bb",
                    Member_ID        = 5,
                    Real_Name        = "我靠",
                    Empiric_Num      = 1,
                    Gold_Num         = 100,
                    Balance          = 100,
                    ServiceShop_ID   = 5,
                    Member_img       = new Guid(),
                    Sex        = Enumusersexs.男,
                    School_ID  = 2,
                    Birth_Date = DateTime.Now,
                    Status     = EnumUserStates.Normal,
                    TenantId   = 0,
                    CreateTime = DateTime.Now
                };
                context.AppUserInfos.Add(appUserInfo);
                context.SaveChanges();
            }
            #endregion
            #region 创建学校跟学院
            if (!context.User_Schools.Any())
            {
                var user_School1 = new User_School
                {
                    School_Name    = "中北大学",
                    ParentID       = 0,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_School2 = new User_School
                {
                    School_Name    = "山西大学",
                    ParentID       = 0,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_School3 = new User_School
                {
                    School_Name    = "太原理工大学",
                    ParentID       = 0,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_campus1 = new User_School
                {
                    School_Name    = "土木工程学院",
                    ParentID       = user_School1.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_campus2 = new User_School
                {
                    School_Name    = "软件工程学院",
                    ParentID       = user_School1.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_campus3 = new User_School
                {
                    School_Name    = "环境工程学院",
                    ParentID       = user_School1.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                var user_campus4 = new User_School
                {
                    School_Name    = "人文学院",
                    ParentID       = user_School1.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };

                var user_campus5 = new User_School
                {
                    School_Name    = "软件学院",
                    ParentID       = user_School2.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                context.User_Schools.Add(user_campus5);
                var user_campus6 = new User_School
                {
                    School_Name    = "土木工程学院",
                    ParentID       = user_School2.ID,
                    School_Address = "太原",
                    CreateDate     = DateTime.Now
                };
                context.User_Schools.Add(user_campus1); context.User_Schools.Add(user_campus2); context.User_Schools.Add(user_campus3); context.User_Schools.Add(user_campus4); context.User_Schools.Add(user_campus5); context.User_Schools.Add(user_campus6); context.User_Schools.Add(user_School3); context.User_Schools.Add(user_School2); context.User_Schools.Add(user_School1);
                context.SaveChanges();
            }
            #endregion
        }