示例#1
0
        public ActionResult VerifyUser(string code, string state, string backUrl = "")
        {
            if (string.IsNullOrEmpty(code) || code == "authdeny" || state != WeixinCommon.State)
            {
                return(new RedirectResult(WeixinCommon.GetAuthorizeUserInfoUrl(Url.RetechAction("BindingAccount", "WeiXin", new { area = "Mobile" }) + "?msg=您还未绑定用户信息!&backUrl=" + Url.Encode(backUrl), Senparc.Weixin.MP.AdvancedAPIs.OAuthScope.snsapi_userinfo)));
            }
            var openID = WeixinCommon.GetOpenidByCode(code);
            var user   = new UserManager().GetUserByOpenID(openID);

            if (user == null)
            {
                return(new RedirectResult(Url.RetechAction("BindingAccount", "WeiXin", new { area = "Mobile" }) + "?openID=" + openID + "&code=" + code + "&state=" + state + "&msg=您还未绑定用户信息!&backUrl=" + Url.Encode(backUrl)));
            }
            user.OpenID = openID;
            this.SessionExt()["currentUser"]   = user;
            this.SessionExt()["currentTenant"] = new TenantManager().GetTenantById(user.TenantId);
            return(new RedirectResult(backUrl));
        }
示例#2
0
        public ActionResult UnBindingAccount(string code, string state, int isFirst = 0)
        {
            string openID = "";

            if (this.SessionExt()["currentUser"] == null)
            {
                if (string.IsNullOrEmpty(code) || code == "authdeny")
                {
                    if (isFirst == 1)
                    {
                        return(Content("您拒绝了授权!"));
                    }
                    else
                    {
                        return(new RedirectResult(WeixinCommon.GetAuthorizeUserInfoUrl(Url.RetechAction("UnBindingAccount", "WeiXin", new { area = "Mobile" }) + "?isFirst=1", Senparc.Weixin.MP.AdvancedAPIs.OAuthScope.snsapi_userinfo)));
                    }
                }
                if (state != WeixinCommon.State)
                {
                    if (isFirst == 1)
                    {
                        return(Content("验证失败!请从正规途径进入!"));
                    }
                    else
                    {
                        return(new RedirectResult(WeixinCommon.GetAuthorizeUserInfoUrl(Url.RetechAction("UnBindingAccount", "WeiXin", new { area = "Mobile" }) + "?isFirst=1", Senparc.Weixin.MP.AdvancedAPIs.OAuthScope.snsapi_userinfo)));
                    }
                }
                openID = WeixinCommon.GetOpenidByCode(code);
            }
            else
            {
                var user = this.SessionExt()["currentUser"] as SysUser;
                openID = user.OpenID;
            }
            ViewBag.openID = openID;
            return(View());
        }
示例#3
0
        public ActionResult BindingAccount(string code, string state, string msg = "", string backUrl = "", int isFirst = 0, string openID = "")
        {
            if (string.IsNullOrEmpty(code) || code == "authdeny")
            {
                if (isFirst == 1)
                {
                    return(Content("您拒绝了授权!"));
                }
                else
                {
                    return(new RedirectResult(WeixinCommon.GetAuthorizeUserInfoUrl(Url.RetechAction("BindingAccount", "WeiXin", new { area = "Mobile" }) + "?isFirst=1&msg=" + msg + "&backUrl=" + Url.Encode(backUrl), Senparc.Weixin.MP.AdvancedAPIs.OAuthScope.snsapi_userinfo)));
                }
            }
            if (state != WeixinCommon.State)
            {
                if (isFirst == 1)
                {
                    return(Content("验证失败!请从正规途径进入!"));
                }
                else
                {
                    return(new RedirectResult(WeixinCommon.GetAuthorizeUserInfoUrl(Url.RetechAction("BindingAccount", "WeiXin", new { area = "Mobile" }) + "?isFirst=1&msg=" + msg + "&backUrl=" + Url.Encode(backUrl), Senparc.Weixin.MP.AdvancedAPIs.OAuthScope.snsapi_userinfo)));
                }
            }

            if (string.IsNullOrWhiteSpace(openID))
            {
                openID = WeixinCommon.GetOpenidByCode(code);
            }
            var user = new UserManager().GetUserByOpenID(openID);

            if (!string.IsNullOrWhiteSpace(backUrl))
            {
                if (backUrl.Contains("?"))
                {
                    if (!backUrl.ToLower().Contains("openid"))
                    {
                        backUrl = backUrl + "&openID=" + openID;
                    }
                }
                else
                {
                    backUrl = backUrl + "?openID=" + openID;
                }
            }

            if (user == null)
            {
                ViewBag.openID  = openID;
                ViewBag.msg     = msg;
                ViewBag.backUrl = backUrl;
                return(View());
            }

            user.OpenID = openID;
            this.SessionExt()["currentUser"]   = user;
            this.SessionExt()["currentTenant"] = new TenantManager().GetTenantById(user.TenantId);
            if (!string.IsNullOrWhiteSpace(backUrl))
            {
                return(new RedirectResult(backUrl));
            }
            return(new RedirectResult(Url.RetechAction("Index", "WeixinLearning", new { area = "Course" })));
        }