예제 #1
0
        /// <summary>
        /// 添加微信自定义菜单
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string AddWeixinMenu(HttpContext context)
        {
            string     jsonData = context.Request["JsonData"];
            WeixinMenu menuInfo = ZentCloud.Common.JSONHelper.JsonToModel <WeixinMenu>(jsonData);

            if (menuInfo.PreID == 0)//添加的是一级菜单
            {
                if (bllWeixin.GetCount <WeixinMenu>(string.Format("UserID='{0}'and PreID=0", currentUserInfo.UserID)) >= 3)
                {
                    return("最多可以添加3个一级菜单");
                }
            }
            else//添加是二级菜单
            {
                //var parentmenu = weixinBll.Get<WeixinMenu>(string.Format("MenuID='{0}'",menuInfo.PreID));
                var topMenu = bllWeixin.Get <WeixinMenu>(string.Format("MenuID='{0}'", menuInfo.PreID));
                if (topMenu != null)
                {
                    if (topMenu.PreID != 0)
                    {
                        return("只能添加二级菜单");
                    }
                }

                if (bllWeixin.GetCount <WeixinMenu>(string.Format("UserID='{0}'and PreID='{1}'", currentUserInfo.UserID, menuInfo.PreID)) >= 5)
                {
                    return("最多可以添加5个二级菜单");
                }
            }

            if (menuInfo.PreID == 0)//添加一级菜单
            {
                List <WeixinMenu> firstLevelMenu = bllWeixin.GetList <WeixinMenu>(string.Format("UserID='{0}' And PreID=0", currentUserInfo.UserID)).OrderBy(p => p.MenuSort).ToList();
                if (firstLevelMenu.Count == 0)
                {
                    menuInfo.MenuSort = 1;
                }
                else
                {
                    menuInfo.MenuSort = firstLevelMenu[firstLevelMenu.Count - 1].MenuSort + 1;
                }
            }
            else//添加二级菜单
            {
                List <WeixinMenu> secondLevelMenu = bllWeixin.GetList <WeixinMenu>(string.Format("UserID='{0}' And PreID={1}", currentUserInfo.UserID, menuInfo.PreID)).OrderBy(p => p.MenuSort).ToList();
                if (secondLevelMenu.Count == 0)
                {
                    menuInfo.MenuSort = 1;
                }
                else
                {
                    menuInfo.MenuSort = secondLevelMenu[secondLevelMenu.Count - 1].MenuSort + 1;
                }
            }

            menuInfo.MenuID = long.Parse(bllWeixin.GetGUID(ZentCloud.BLLJIMP.TransacType.WeixinMenuAdd));
            menuInfo.UserID = currentUserInfo.UserID;
            bool result = bllWeixin.Add(menuInfo);

            return(result.ToString().ToLower());
        }
예제 #2
0
        /// <summary>
        ///注册微信会员(添加了微信认证机制的检查)
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string WXRegWithWeixinVerify(HttpContext context)
        {
            ZentCloud.BLLJIMP.Model.UserInfo userInfo;
            WXMemberInfo model     = new WXMemberInfo();
            string       userIDHex = context.Request[systemSet.UserAutoIDHexKey];

            userInfo = this.userBll.GetUserInfoByAutoIDHex(userIDHex);

            if (userInfo == null)
            {
                resp.Status = 0;
                resp.Msg    = "用户名不存在!";
                return(Common.JSONHelper.ObjectToJson(resp));
            }

            model.UserID = userInfo.UserID;

            model.Name         = context.Request["Name"];
            model.Company      = context.Request["Company"];
            model.Postion      = context.Request["Postion"];
            model.WeixinNumber = context.Request["WeixinNumber"];
            model.WeixinOpenID = context.Request[systemSet.WXCurrOpenerOpenIDKey];

            //判断是否是认证的微信,并且是否有微信号存在授权的Session里
            if (userInfo.IsWeixinVerify == 1 && context.Session[systemSet.WXCurrOpenerOpenIDKey] != null)
            {
                //如果是微信认证用户而且认证取到的openID也存在,则会忽略浏览器url上的openid
                model.WeixinOpenID = context.Session[systemSet.WXCurrOpenerOpenIDKey].ToString();
            }

            //判断是否有拉去到的微信信息,如有则存储下来
            if (context.Session[systemSet.WXOAuthAccessTokenEntityKey] != null)
            {
                //存储授权信息
                BLLWXOAuthModule.WXOAuthAccessTokenEntity acModel = (BLLWXOAuthModule.WXOAuthAccessTokenEntity)context.Session[systemSet.WXOAuthAccessTokenEntityKey];
                model.AccessToken  = acModel.AccessToken;
                model.RefreshToken = acModel.RefreshToken;
                model.Scope        = acModel.Scope;
            }
            if (context.Session[systemSet.WXCurrOpenerUserInfoKey] != null)
            {
                //存储拉取到的用户信息
                BLLJIMP.Model.Weixin.WeixinUserInfo usModel = (BLLJIMP.Model.Weixin.WeixinUserInfo)context.Session[systemSet.WXCurrOpenerUserInfoKey];
                model.WXCity       = usModel.City;
                model.WXCountry    = usModel.Country;
                model.WXHeadimgurl = usModel.HeadImgUrl;
                model.WXNickname   = usModel.NickName;
                model.WXPrivilege  = usModel.Privilege == null ? "" : Common.JSONHelper.ObjectToJson(usModel.Privilege);
                model.WXProvince   = usModel.Province;
                model.WXSex        = usModel.Sex;
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                resp.Status = 0;
                resp.Msg    = "请输入姓名";
                return(Common.JSONHelper.ObjectToJson(resp));
            }
            model.Phone = context.Request["Phone"];
            if (string.IsNullOrEmpty(model.Phone))
            {
                resp.Status = 0;
                resp.Msg    = "请输入手机号码";
                return(Common.JSONHelper.ObjectToJson(resp));
            }
            if (!Common.ValidatorHelper.PhoneNumLogicJudge(model.Phone))
            {
                resp.Status = 0;
                resp.Msg    = "手机号码格式不正确";
                return(Common.JSONHelper.ObjectToJson(resp));
            }
            model.Email = context.Request["Email"];
            if (!string.IsNullOrEmpty(model.Email))
            {
                if (!Common.ValidatorHelper.EmailLogicJudge(model.Email))
                {
                    resp.Status = 0;
                    resp.Msg    = "Email格式不正确";
                    return(Common.JSONHelper.ObjectToJson(resp));
                }
            }
            if (weixinBll.GetCount <WXMemberInfo>(string.Format("UserID='{0}' and WeixinOpenID='{1}'", userInfo.UserID, model.WeixinOpenID)) > 0)
            {
                resp.Status = 0;
                resp.Msg    = "您已经注册过了!";
                return(Common.JSONHelper.ObjectToJson(resp));
            }

            model.MemberID = long.Parse(weixinBll.GetGUID(ZentCloud.BLLJIMP.TransacType.WXMemberInfoAdd));
            if (weixinBll.Add(model))
            {
                resp.Status = 1;
                resp.Msg    = "注册成功!";
            }
            else
            {
                resp.Status = 0;
                resp.Msg    = "注册失败!请重试或联系管理员";
            }
            return(Common.JSONHelper.ObjectToJson(resp));
        }