Beispiel #1
0
        private bool BindOpenIdToUser(ActionExecutingContext filterContext)
        {
            string       str;
            bool         flag        = true;
            IMobileOAuth weixinOAuth = null;

            if (base.PlatformType == Himall.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) != Himall.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, "Himall.Plugin.OAuth.WeiXin", userInfoBequiet.OpenId, appIdTypeEnum, null, userInfoBequiet.UnionId);
                        }
                        else
                        {
                            string str2 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile");
                            WebHelper.SetCookie("Himall-User", str2);
                        }
                    }
                }
            }
            return(flag);
        }
        /// <summary>
        /// 跳转到手机URL
        /// </summary>
        /// <param name="JumpUrl">为空表示自动处理</param>
        //TODO:DZY[150730] 统一跳转

        /* zjt
         * Url请改为小写 【参数命名规范】
         */
        protected void JumpMobileUrl(ActionExecutingContext filterContext, string url = "")
        {
            string curUrl  = Request.Url.PathAndQuery;
            string jumpUrl = curUrl;
            var    route   = filterContext.RouteData;

            //无路由信息不跳转
            if (route == null)
            {
                return;
            }

            //路由处理
            string controller = route.Values["controller"].ToString().ToLower();
            string action     = route.Values["action"].ToString().ToLower();
            string area       = (route.DataTokens["area"] == null ? "" : route.DataTokens["area"].ToString().ToLower());

            if (area == "mobile" || area == "admin")
            {
                return;  //在移动端跳出
            }
            //Web区域跳转移动端
            if (area == "web")
            {
                IsAutoJumpMobile = true;
            }

            if (this.IsAutoJumpMobile && IsMobileTerminal)
            {
                if (Regex.Match(curUrl, @"\/m(\-.*)?").Length < 1)
                {
                    JumpUrlRoute jurdata = GetRouteUrl(controller, action, area, curUrl);
                    //非手机端跳转
                    switch (visitorTerminalInfo.Terminal)
                    {
                    case EnumVisitorTerminal.WeiXin:
                        if (jurdata != null)
                        {
                            jumpUrl = jurdata.WX;
                        }
                        jumpUrl = @"/m-WeiXin" + jumpUrl;
                        break;

                    case EnumVisitorTerminal.IOS:
                        if (jurdata != null)
                        {
                            jumpUrl = jurdata.WAP;
                        }
                        jumpUrl = @"/m-ios" + jumpUrl;
                        break;

                    default:
                        if (jurdata != null)
                        {
                            jumpUrl = jurdata.WAP;
                        }
                        jumpUrl = @"/m-wap" + jumpUrl;
                        break;
                    }

                    #region 参数特殊处理
                    if (jurdata.IsSpecial)
                    {
                        #region 店铺参数转换
                        if (jurdata.PC.ToLower() == @"/shop")
                        {
                            //商家首页参数处理
                            string strid   = route.Values["id"].ToString();
                            long   shopId  = 0;
                            long   vshopId = 0;
                            if (!long.TryParse(strid, out shopId))
                            {
                                shopId = 0;
                            }
                            if (shopId > 0)
                            {
                                var vshop = ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopId);
                                if (vshop != null)
                                {
                                    vshopId = vshop.Id;
                                }
                            }
                            jumpUrl = jumpUrl + "/" + vshopId.ToString();
                        }
                        #endregion

                        //TODO:LRL 订单页面参数转换

                        /* zjt
                         * TODO可移除,保留注释即可
                         */
                        #region  单页面参数转换
                        if (jurdata.PC.ToLower() == @"/order/submit")
                        {
                            //商家首页参数处理
                            var strcartid = string.Empty;
                            var arg       = route.Values["cartitemids"];
                            if (arg == null)
                            {
                                strcartid = Request.QueryString["cartitemids"];
                            }
                            else
                            {
                                strcartid = arg.ToString();
                            }
                            jumpUrl = jumpUrl + "/?cartItemIds=" + strcartid;
                        }
                        #endregion
                    }
                    #endregion

                    if (!string.IsNullOrWhiteSpace(url))
                    {
                        jumpUrl = url;
                    }
                    string testurl = jumpUrl;
                    testurl = Request.Url.Scheme + "://" + Request.Url.Authority + testurl;
                    //页面不存在
                    if (!IsExistPage(testurl))
                    {
                        if (visitorTerminalInfo.Terminal == EnumVisitorTerminal.WeiXin)
                        {
                            jumpUrl = @"/m-WeiXin/";
                        }
                        else
                        {
                            jumpUrl = @"/m-wap/";
                        }
                    }

                    filterContext.Result = Redirect(jumpUrl);
                }
            }
        }
Beispiel #3
0
        private bool ProcessInvalidUser_NormalRequest(ActionExecutingContext filterContext)
        {
            string       str;
            bool         flag        = true;
            IMobileOAuth weixinOAuth = null;

            if (base.PlatformType == Himall.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) != Himall.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, "Himall.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("Himall-User", str3);
                    }
                }
            }
            return(flag);
        }