Esempio n. 1
0
        public void BindMember(long userId, string serviceProvider, string openId, MemberOpenIdInfo.AppIdTypeEnum AppidType, string headImage = null, string unionid = null)
        {
            CheckOpenIdHasBeenUsed(serviceProvider, openId, userId);
            MemberOpenIdInfo memberOpenIdInfo = new MemberOpenIdInfo()
            {
                UserId          = userId,
                OpenId          = openId,
                ServiceProvider = serviceProvider,
                AppIdType       = AppidType,
                UnionId         = (string.IsNullOrWhiteSpace(unionid) ? string.Empty : unionid)
            };
            MemberOpenIdInfo memberOpenIdInfo1 = memberOpenIdInfo;
            UserMemberInfo   userMemberInfo    = context.UserMemberInfo.FirstOrDefault((UserMemberInfo item) => item.Id == userId);

            if (!string.IsNullOrWhiteSpace(headImage) && string.IsNullOrWhiteSpace(userMemberInfo.Photo))
            {
                userMemberInfo.Photo = TransferHeadImage(headImage, userId);
            }
            context.MemberOpenIdInfo.Add(memberOpenIdInfo1);
            context.SaveChanges();
            Instance <IBonusService> .Create.DepositToRegister(userMemberInfo.Id);

            if (serviceProvider.ToLower() == "ChemCloud.Plugin.OAuth.WeiXin".ToLower())
            {
                AddBindInergral(userMemberInfo);
            }
            Cache.Remove(CacheKeyCollection.Member(userId));
        }
Esempio n. 2
0
        public UserMemberInfo QuickRegister(string username, string realName, string nickName, string serviceProvider, string openId, string headImage = null, MemberOpenIdInfo.AppIdTypeEnum appidtype = (MemberOpenIdInfo.AppIdTypeEnum) 1, string unionid = null, string unionopenid = null)
        {
            username = GetNewUserName();
            CheckInputIsValidWhenQuickRegister(username, serviceProvider, openId);
            CheckOpenIdHasBeenUsed(serviceProvider, openId, 0);
            if (string.IsNullOrWhiteSpace(nickName))
            {
                nickName = username;
            }
            Guid           guid = Guid.NewGuid();
            string         str  = string.Concat("o", guid.ToString("N").Substring(12));
            string         passwrodWithTwiceEncode = GetPasswrodWithTwiceEncode("", str);
            UserMemberInfo userMemberInfo          = new UserMemberInfo()
            {
                UserName      = username,
                PasswordSalt  = str,
                CreateDate    = DateTime.Now,
                LastLoginDate = DateTime.Now,
                Nick          = nickName,
                RealName      = realName
            };
            UserMemberInfo userMemberInfo1 = userMemberInfo;

            if (context.UserMemberInfo.Any((UserMemberInfo d) => d.UserName == userMemberInfo1.UserName))
            {
                throw new HimallException("用户名被占用");
            }
            using (TransactionScope transactionScope = new TransactionScope())
            {
                userMemberInfo1.Password = passwrodWithTwiceEncode;
                userMemberInfo1          = context.UserMemberInfo.Add(userMemberInfo1);
                context.SaveChanges();
                MemberOpenIdInfo memberOpenIdInfo = new MemberOpenIdInfo()
                {
                    UserId          = userMemberInfo1.Id,
                    OpenId          = openId,
                    ServiceProvider = serviceProvider,
                    AppIdType       = appidtype,
                    UnionId         = (string.IsNullOrWhiteSpace(unionid) ? string.Empty : unionid),
                    UnionOpenId     = (string.IsNullOrWhiteSpace(unionopenid) ? string.Empty : unionopenid)
                };
                context.MemberOpenIdInfo.Add(memberOpenIdInfo);
                context.SaveChanges();
                if (!string.IsNullOrWhiteSpace(headImage))
                {
                    userMemberInfo1.Photo = TransferHeadImage(headImage, userMemberInfo1.Id);
                }
                context.SaveChanges();
                transactionScope.Complete();
            }
            return(userMemberInfo1);
        }
Esempio n. 3
0
 /// <summary>
 /// 快速注册
 /// </summary>
 /// <param name="username">用户名</param>
 /// <param name="openId">OpenId</param>
 /// <param name="nickName">昵称</param>
 /// <param name="realName">真实姓名</param>
 /// <param name="serviceProvider">服务提供商</param>
 /// <returns></returns>
 public static UserMemberInfo QuickRegister(string username, string realName, string nickName, string serviceProvider, string openId, string unionid, string sex = null, string headImage = null, MemberOpenIdInfo.AppIdTypeEnum appidtype = MemberOpenIdInfo.AppIdTypeEnum.Normal, string unionopenid = null, string city = null, string province = null)
 {
     return(_iMemberService.QuickRegister(username, realName, nickName, serviceProvider, openId, unionid, sex = null, headImage = null, appidtype, unionopenid, city, province));
 }
Esempio n. 4
0
        /// <summary>
        /// 根据用户id和类型获取会员openid信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="appIdType"></param>
        /// <returns></returns>
        public static DTO.MemberOpenId GetMemberOpenIdInfoByuserId(long userId, MemberOpenIdInfo.AppIdTypeEnum appIdType, string serviceProvider = "")
        {
            var model = _iMemberService.GetMemberOpenIdInfoByuserId(userId, appIdType, serviceProvider);

            return(AutoMapper.Mapper.Map <DTO.MemberOpenId>(model));
        }
Esempio n. 5
0
        public JsonResult BindUser(string username, string password, string headimgurl, string serviceProvider, string openId, MemberOpenIdInfo.AppIdTypeEnum appidtype = (MemberOpenIdInfo.AppIdTypeEnum) 1, string unionid = null)
        {
            IMemberService memberService  = ServiceHelper.Create <IMemberService>();
            UserMemberInfo userMemberInfo = memberService.Login(username, password);

            if (userMemberInfo == null)
            {
                throw new HimallException("用户名和密码不匹配");
            }
            headimgurl = HttpUtility.UrlDecode(headimgurl);
            memberService.BindMember(userMemberInfo.Id, serviceProvider, openId, appidtype, headimgurl, unionid);
            string str = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "Mobile");

            WebHelper.SetCookie("Himall-User", str);
            return(Json(new { success = true }));
        }
        public JsonResult Skip(string serviceProvider, string openId, string nickName, string realName, string headimgurl, MemberOpenIdInfo.AppIdTypeEnum appidtype = MemberOpenIdInfo.AppIdTypeEnum.Normal, string unionid = null, string sex = null, string city = null, string province = null)
        {
            int    num      = 0;
            string username = DateTime.Now.ToString("yyMMddHHmmssffffff");   //TODO:DZY[150916]未使用,在方法内会重新生成

            nickName   = System.Web.HttpUtility.UrlDecode(nickName);
            realName   = System.Web.HttpUtility.UrlDecode(realName);
            headimgurl = System.Web.HttpUtility.UrlDecode(headimgurl);
            province   = System.Web.HttpUtility.UrlDecode(province);
            city       = System.Web.HttpUtility.UrlDecode(city);
            UserMemberInfo memberInfo = _iMemberService.GetMemberByUnionId(openId);

            if (memberInfo == null)
            {
                memberInfo = _iMemberService.QuickRegister(username, realName, nickName, serviceProvider, openId, unionid, sex, headimgurl, appidtype, null, city, province);
                //TODO:ZJT  在用户注册的时候,检查此用户是否存在OpenId是否存在红包,存在则添加到用户预存款里
                _iBonusService.DepositToRegister(memberInfo.Id);
                //用户注册的时候,检查是否开启注册领取优惠券活动,存在自动添加到用户预存款里
                num = CouponApplication.RegisterSendCoupon(memberInfo.Id, memberInfo.UserName);
            }

            base.SetUserLoginCookie(memberInfo.Id);
            Application.MemberApplication.UpdateLastLoginDate(memberInfo.Id);
            WebHelper.SetCookie(CookieKeysCollection.HIMALL_ACTIVELOGOUT, "0", DateTime.MaxValue);
            return(Json(new { success = true, num = num }));
        }
        private bool BindOpenIdToUser(ActionExecutingContext filterContext)
        {
            string       str;
            bool         flag        = true;
            IMobileOAuth weixinOAuth = null;

            if (base.PlatformType == ChemCloud.Core.PlatformType.WeiXin)
            {
                weixinOAuth = new WeixinOAuth();
            }
            string.Format("/m-{0}/Login/Entrance?returnUrl={1}", base.PlatformType.ToString(), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()));
            if (weixinOAuth == null || GetRequestType(filterContext.HttpContext.Request) != ChemCloud.Core.PlatformType.WeiXin)
            {
                flag = false;
            }
            else
            {
                WXShopInfo wXShopInfo = new WXShopInfo();
                string     item       = filterContext.HttpContext.Request["shop"];
                MemberOpenIdInfo.AppIdTypeEnum appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Normal;
                if (!string.IsNullOrEmpty(item))
                {
                    long num = 0;
                    long.TryParse(item, out num);
                    if (num > 0)
                    {
                        wXShopInfo = ServiceHelper.Create <IVShopService>().GetVShopSetting(num);
                    }
                }
                if (string.IsNullOrEmpty(wXShopInfo.AppId) || string.IsNullOrEmpty(wXShopInfo.AppSecret))
                {
                    WXShopInfo wXShopInfo1 = new WXShopInfo()
                    {
                        AppId     = base.CurrentSiteSetting.WeixinAppId,
                        AppSecret = base.CurrentSiteSetting.WeixinAppSecret,
                        Token     = base.CurrentSiteSetting.WeixinToken
                    };
                    wXShopInfo    = wXShopInfo1;
                    appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Payment;
                }
                MobileOAuthUserInfo userInfoBequiet = weixinOAuth.GetUserInfo_bequiet(filterContext, out str, wXShopInfo);
                if (!string.IsNullOrWhiteSpace(str))
                {
                    filterContext.Result = Redirect(str);
                }
                else
                {
                    flag = false;
                    if (userInfoBequiet != null && !string.IsNullOrWhiteSpace(userInfoBequiet.OpenId))
                    {
                        if (appIdTypeEnum == MemberOpenIdInfo.AppIdTypeEnum.Payment)
                        {
                            string str1 = SecureHelper.AESEncrypt(userInfoBequiet.OpenId, "Mobile");
                            WebHelper.SetCookie("Himall-User_OpenId", str1);
                        }
                        IMemberService memberService  = ServiceHelper.Create <IMemberService>();
                        UserMemberInfo memberByOpenId = null;
                        if (memberByOpenId == null)
                        {
                            memberByOpenId = memberService.GetMemberByOpenId(userInfoBequiet.LoginProvider, userInfoBequiet.OpenId);
                        }
                        if (memberByOpenId == null)
                        {
                            memberService.BindMember(base.CurrentUser.Id, "ChemCloud.Plugin.OAuth.WeiXin", userInfoBequiet.OpenId, appIdTypeEnum, null, userInfoBequiet.UnionId);
                        }
                        else
                        {
                            string str2 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile");
                            WebHelper.SetCookie("ChemCloud-User", str2);
                        }
                    }
                }
            }
            return(flag);
        }
        private bool ProcessInvalidUser_NormalRequest(ActionExecutingContext filterContext)
        {
            string       str;
            bool         flag        = true;
            IMobileOAuth weixinOAuth = null;

            if (base.PlatformType == ChemCloud.Core.PlatformType.WeiXin)
            {
                weixinOAuth = new WeixinOAuth();
            }
            string str1 = string.Format("/m-{0}/Login/Entrance?returnUrl={1}", base.PlatformType.ToString(), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()));

            if (weixinOAuth == null || GetRequestType(filterContext.HttpContext.Request) != ChemCloud.Core.PlatformType.WeiXin)
            {
                filterContext.Result = Redirect(str1);
            }
            else
            {
                WXShopInfo wXShopInfo = new WXShopInfo();
                string     item       = filterContext.HttpContext.Request["shop"];
                MemberOpenIdInfo.AppIdTypeEnum appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Normal;
                if (!string.IsNullOrEmpty(item))
                {
                    long num = 0;
                    long.TryParse(item, out num);
                    if (num > 0)
                    {
                        wXShopInfo = ServiceHelper.Create <IVShopService>().GetVShopSetting(num);
                    }
                }
                if (string.IsNullOrEmpty(wXShopInfo.AppId) || string.IsNullOrEmpty(wXShopInfo.AppSecret))
                {
                    WXShopInfo wXShopInfo1 = new WXShopInfo()
                    {
                        AppId     = base.CurrentSiteSetting.WeixinAppId,
                        AppSecret = base.CurrentSiteSetting.WeixinAppSecret,
                        Token     = base.CurrentSiteSetting.WeixinToken
                    };
                    wXShopInfo    = wXShopInfo1;
                    appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Payment;
                }
                MobileOAuthUserInfo userInfo = weixinOAuth.GetUserInfo(filterContext, out str, wXShopInfo);
                if (!string.IsNullOrWhiteSpace(str))
                {
                    filterContext.Result = Redirect(str);
                }
                else if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.OpenId))
                {
                    filterContext.Result = Redirect(str1);
                }
                else
                {
                    if (appIdTypeEnum == MemberOpenIdInfo.AppIdTypeEnum.Payment)
                    {
                        string str2 = SecureHelper.AESEncrypt(userInfo.OpenId, "Mobile");
                        WebHelper.SetCookie("Himall-User_OpenId", str2);
                    }
                    UserMemberInfo memberByOpenId = null;
                    if (memberByOpenId == null)
                    {
                        memberByOpenId = ServiceHelper.Create <IMemberService>().GetMemberByOpenId(userInfo.LoginProvider, userInfo.OpenId);
                    }
                    if (memberByOpenId == null)
                    {
                        object[] objArray = new object[] { base.PlatformType.ToString(), userInfo.OpenId, "ChemCloud.Plugin.OAuth.WeiXin", HttpUtility.UrlEncode(userInfo.NickName), HttpUtility.UrlEncode(userInfo.RealName), HttpUtility.UrlEncode(userInfo.Headimgurl), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()), appIdTypeEnum, userInfo.UnionId };
                        str1 = string.Format("/m-{0}/Login/Entrance?openId={1}&serviceProvider={2}&nickName={3}&realName={4}&headimgurl={5}&returnUrl={6}&AppidType={7}&unionid={8}", objArray);
                        filterContext.Result = Redirect(str1);
                    }
                    else
                    {
                        string str3 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile");
                        WebHelper.SetCookie("ChemCloud-User", str3);
                    }
                }
            }
            return(flag);
        }
Esempio n. 9
0
        public JsonResult Skip(string serviceProvider, string openId, string nickName, string realName, string headimgurl, MemberOpenIdInfo.AppIdTypeEnum appidtype = (MemberOpenIdInfo.AppIdTypeEnum) 1, string unionid = null)
        {
            string str = DateTime.Now.ToString("yyMMddHHmmssffffff");

            nickName   = HttpUtility.UrlDecode(nickName);
            realName   = HttpUtility.UrlDecode(realName);
            headimgurl = HttpUtility.UrlDecode(headimgurl);
            UserMemberInfo userMemberInfo = ServiceHelper.Create <IMemberService>().QuickRegister(str, realName, nickName, serviceProvider, openId, headimgurl, appidtype, unionid, null);

            ServiceHelper.Create <IBonusService>().DepositToRegister(userMemberInfo.Id);
            string str1 = UserCookieEncryptHelper.Encrypt(userMemberInfo.Id, "Mobile");

            WebHelper.SetCookie("ChemCloud-User", str1);
            return(Json(new { success = true }));
        }