Exemple #1
0
        public void AlipayLoginAction(SiteSettings site)
        {
            if (string.IsNullOrEmpty(AlipayFuwuConfig.appId) && !AlipayFuwuConfig.CommSetConfig(site.AlipayAppid, this.Page.Server.MapPath("~/"), "GBK"))
            {
                this.WriteFuwuError(this.Page.Request.QueryString.ToString(), "服务窗口参数配置不准确!");
                this.Page.Response.Redirect(Globals.ApplicationPath + "/UserLogin.aspx");
            }
            string text  = this.Page.Request.QueryString["auth_code"];
            string value = this.Page.Request.QueryString["scope"];

            if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(text))
            {
                this.WriteFuwuError(this.Page.Request.QueryString.ToString(), "已授权");
                AlipaySystemOauthTokenResponse oauthTokenResponse = AliOHHelper.GetOauthTokenResponse(text);
                this.WriteFuwuError(AliOHHelper.SerializeObject(oauthTokenResponse, true), "获取AccessToken");
                if (oauthTokenResponse == null || oauthTokenResponse.IsError || oauthTokenResponse.AccessToken == null)
                {
                    this.Page.Response.Redirect(Globals.ApplicationPath + "/UserLogin.aspx?returnUrl=" + Globals.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri.ToString()));
                    return;
                }
                string  text2   = oauthTokenResponse.AlipayUserId;
                string  text3   = "";
                JObject jObject = JsonConvert.DeserializeObject(oauthTokenResponse.Body) as JObject;
                if (jObject["alipay_system_oauth_token_response"]["user_id"] != null)
                {
                    text3 = jObject["alipay_system_oauth_token_response"]["user_id"].ToString();
                }
                if (this.HasLogin(text3, "fuwu") || this.HasLogin(text2, "fuwu"))
                {
                    MemberInfo openIdMember = MemberProcessor.GetOpenIdMember(text3, "fuwu");
                    if (openIdMember == null || openIdMember.Status == Convert.ToInt32(UserStatus.DEL))
                    {
                        this.Page.Response.Redirect(Globals.ApplicationPath + "/logout.aspx");
                    }
                    string alipayOpenid = openIdMember.AlipayOpenid;
                    if ((text2 != "" && text2 != alipayOpenid) || string.IsNullOrEmpty(alipayOpenid))
                    {
                        openIdMember.AlipayOpenid = text2;
                        MemberProcessor.SetAlipayInfos(openIdMember);
                    }
                    this.setLogin(openIdMember.UserId);
                    this.WriteFuwuError("已存在用户登入!", text3);
                    return;
                }
                string accessToken = oauthTokenResponse.AccessToken;
                AlipayUserUserinfoShareResponse alipayUserUserinfo = AliOHHelper.GetAlipayUserUserinfo(accessToken);
                this.WriteFuwuError(AliOHHelper.SerializeObject(alipayUserUserinfo, true), "获取用户信息");
                string alipayUsername = "";
                string text4          = "";
                if (alipayUserUserinfo != null && !alipayUserUserinfo.IsError)
                {
                    text4 = alipayUserUserinfo.Avatar;
                    if (alipayUserUserinfo.RealName != null)
                    {
                        alipayUsername = alipayUserUserinfo.RealName;
                    }
                    if (string.IsNullOrEmpty(text2))
                    {
                        text2 = alipayUserUserinfo.UserId;
                    }
                    if (string.IsNullOrEmpty(text3))
                    {
                        JObject jObject2 = JsonConvert.DeserializeObject(alipayUserUserinfo.Body) as JObject;
                        if (jObject2["alipay_user_id"] != null)
                        {
                            text3 = jObject2["alipay_user_id"].ToString();
                        }
                    }
                }
                string     text5      = "FW*" + text3.Substring(10);
                string     generateId = Globals.GetGenerateId();
                MemberInfo memberInfo = new MemberInfo();
                memberInfo.GradeId        = MemberProcessor.GetDefaultMemberGrade();
                memberInfo.UserName       = text5;
                memberInfo.CreateDate     = DateTime.Now;
                memberInfo.SessionId      = generateId;
                memberInfo.SessionEndTime = DateTime.Now.AddYears(10);
                memberInfo.UserHead       = text4;
                memberInfo.AlipayAvatar   = text4;
                memberInfo.AlipayLoginId  = text5;
                memberInfo.AlipayOpenid   = text2;
                memberInfo.AlipayUserId   = text3;
                memberInfo.AlipayUsername = alipayUsername;
                HttpCookie httpCookie = HttpContext.Current.Request.Cookies["Vshop-ReferralId"];
                if (httpCookie != null)
                {
                    memberInfo.ReferralUserId = Convert.ToInt32(httpCookie.Value);
                }
                else
                {
                    memberInfo.ReferralUserId = 0;
                }
                memberInfo.Password = HiCryptographer.Md5Encrypt("888888");
                MemberProcessor.CreateMember(memberInfo);
                MemberInfo member = MemberProcessor.GetMember(generateId);
                this.setLogin(member.UserId);
                return;
            }
            else
            {
                if (!string.IsNullOrEmpty(value))
                {
                    this.WriteFuwuError(this.Page.Request.QueryString.ToString(), "拒绝授权");
                    this.Page.Response.Redirect(Globals.ApplicationPath + "/UserLogin.aspx");
                    return;
                }
                string text6 = AliOHHelper.AlipayAuthUrl(HttpContext.Current.Request.Url.ToString().Replace(":" + HttpContext.Current.Request.Url.Port, ""), site.AlipayAppid, "auth_userinfo");
                this.WriteFuwuError(text6, "用户登入授权的路径");
                this.Page.Response.Redirect(text6);
                return;
            }
        }
        public void AlipayLoginAction(SiteSettings site)
        {
            if (string.IsNullOrEmpty(AlipayFuwuConfig.appId) && !AlipayFuwuConfig.CommSetConfig(site.AlipayAppid, this.Page.Server.MapPath("~/"), "GBK"))
            {
                this.WriteFuwuError(this.Page.Request.QueryString.ToString(), "服务窗口参数配置不准确!");
                this.Page.Response.Redirect(Globals.ApplicationPath + "/UserLogin.aspx");
            }
            string str  = this.Page.Request.QueryString["auth_code"];
            string str2 = this.Page.Request.QueryString["scope"];

            if (!string.IsNullOrEmpty(str2) && !string.IsNullOrEmpty(str))
            {
                this.WriteFuwuError(this.Page.Request.QueryString.ToString(), "已授权");
                AlipaySystemOauthTokenResponse oauthTokenResponse = AliOHHelper.GetOauthTokenResponse(str);
                this.WriteFuwuError(AliOHHelper.SerializeObject(oauthTokenResponse, true), "获取AccessToken");
                if (((oauthTokenResponse != null) && !oauthTokenResponse.IsError) && (oauthTokenResponse.AccessToken != null))
                {
                    string  alipayUserId = oauthTokenResponse.AlipayUserId;
                    string  openId       = "";
                    JObject obj2         = JsonConvert.DeserializeObject(oauthTokenResponse.Body) as JObject;
                    if (obj2["alipay_system_oauth_token_response"]["user_id"] != null)
                    {
                        openId = obj2["alipay_system_oauth_token_response"]["user_id"].ToString();
                    }
                    if (this.HasLogin(openId, "fuwu") || this.HasLogin(alipayUserId, "fuwu"))
                    {
                        MemberInfo openIdMember = MemberProcessor.GetOpenIdMember(openId, "fuwu");
                        if ((openIdMember == null) || (openIdMember.Status == Convert.ToInt32(UserStatus.DEL)))
                        {
                            this.Page.Response.Redirect(Globals.ApplicationPath + "/logout.aspx");
                        }
                        string alipayOpenid = openIdMember.AlipayOpenid;
                        if (((alipayUserId != "") && (alipayUserId != alipayOpenid)) || string.IsNullOrEmpty(alipayOpenid))
                        {
                            openIdMember.AlipayOpenid = alipayUserId;
                            MemberProcessor.SetAlipayInfos(openIdMember);
                        }
                        this.setLogin(openIdMember.UserId);
                        this.WriteFuwuError("已存在用户登入!", openId);
                    }
                    else
                    {
                        AlipayUserUserinfoShareResponse alipayUserUserinfo = AliOHHelper.GetAlipayUserUserinfo(oauthTokenResponse.AccessToken);
                        this.WriteFuwuError(AliOHHelper.SerializeObject(alipayUserUserinfo, true), "获取用户信息");
                        string str7     = "";
                        string realName = "";
                        string avatar   = "";
                        if ((alipayUserUserinfo != null) && !alipayUserUserinfo.IsError)
                        {
                            avatar = alipayUserUserinfo.Avatar;
                            if (alipayUserUserinfo.RealName != null)
                            {
                                realName = alipayUserUserinfo.RealName;
                            }
                            if (string.IsNullOrEmpty(alipayUserId))
                            {
                                alipayUserId = alipayUserUserinfo.UserId;
                            }
                            if (string.IsNullOrEmpty(openId))
                            {
                                JObject obj3 = JsonConvert.DeserializeObject(alipayUserUserinfo.Body) as JObject;
                                if (obj3["alipay_user_id"] != null)
                                {
                                    openId = obj3["alipay_user_id"].ToString();
                                }
                            }
                        }
                        str7 = "FW*" + openId.Substring(10);
                        string     generateId = Globals.GetGenerateId();
                        MemberInfo member     = new MemberInfo {
                            GradeId        = MemberProcessor.GetDefaultMemberGrade(),
                            UserName       = str7,
                            CreateDate     = DateTime.Now,
                            SessionId      = generateId,
                            SessionEndTime = DateTime.Now.AddYears(10),
                            UserHead       = avatar,
                            AlipayAvatar   = avatar,
                            AlipayLoginId  = str7,
                            AlipayOpenid   = alipayUserId,
                            AlipayUserId   = openId,
                            AlipayUsername = realName
                        };
                        HttpCookie cookie = HttpContext.Current.Request.Cookies["Vshop-ReferralId"];
                        if (cookie != null)
                        {
                            member.ReferralUserId = Convert.ToInt32(cookie.Value);
                        }
                        else
                        {
                            member.ReferralUserId = 0;
                        }
                        member.Password = HiCryptographer.Md5Encrypt("888888");
                        MemberProcessor.CreateMember(member);
                        MemberInfo info3 = MemberProcessor.GetMember(generateId);
                        this.setLogin(info3.UserId);
                    }
                }
                else
                {
                    this.Page.Response.Redirect(Globals.ApplicationPath + "/UserLogin.aspx?returnUrl=" + Globals.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri.ToString()));
                }
            }
            else if (!string.IsNullOrEmpty(str2))
            {
                this.WriteFuwuError(this.Page.Request.QueryString.ToString(), "拒绝授权");
                this.Page.Response.Redirect(Globals.ApplicationPath + "/UserLogin.aspx");
            }
            else
            {
                string msg = AliOHHelper.AlipayAuthUrl(HttpContext.Current.Request.Url.ToString().Replace(":" + HttpContext.Current.Request.Url.Port, ""), site.AlipayAppid, "auth_userinfo");
                this.WriteFuwuError(msg, "用户登入授权的路径");
                this.Page.Response.Redirect(msg);
            }
        }