public ReturnValue <USR_CustomerMaintain> WeiboLoginAlt(string token, long expires) { //新浪微博回调 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Container.ConfigService.GetAppSetting <string>("ThirdLoginFilePath", "")); XmlNode node = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//AppID"); XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//Key"); var oauth = new NetDimension.Weibo.OAuth(node.InnerText, node1.InnerText, Container.ConfigService.GetAppSetting <string>("HomeUrl", "") + "Passport/ThirdLogin.aspx"); var uid = ""; if (!string.IsNullOrEmpty(token)) { var Sina = new NetDimension.Weibo.Client(oauth); uid = Sina.API.Account.GetUID(); //调用API中获取UID的方法 } USR_CustomerMod m_customer = USR_CustomerBll.GetInstance().GetUserByThirdID(uid); if (m_customer != null && m_customer.SysNo != AppConst.IntNull) { m_customer.LastLoginTime = DateTime.Now; USR_CustomerBll.GetInstance().Update(m_customer); USR_CustomerMaintain ret = new USR_CustomerMaintain(); m_customer.MemberwiseCopy(ret); return(ReturnValue <USR_CustomerMaintain> .Get200OK(ret)); } USR_ThirdLoginMod m_third = new USR_ThirdLoginMod(); m_third.OpenID = uid; m_third.AccessKey = token; m_third.ThirdType = (int)AppEnum.ThirdLoginType.weibo; USR_CustomerMod m_user = new USR_CustomerMod(); try { m_user.Email = ""; m_user.FateType = (int)AppEnum.FateType.astro; m_user.GradeSysNo = AppConst.OriginalGrade;; m_user.NickName = uid; m_user.Password = ""; m_user.RegTime = DateTime.Now; m_user.Point = AppConst.OriginalPoint; m_user.Photo = AppConst.OriginalPhoto; m_user.LastLoginTime = DateTime.Now; if (Container.ConfigService.GetAppSetting <string>("RegisterEmailCheck", "false").ToLower() == "true") { m_user.Status = (int)AppEnum.State.prepare; } else { m_user.Status = (int)AppEnum.State.normal; } m_user.Credit = 0; m_user.Birth = AppConst.DateTimeNull; m_user.IsShowBirth = 1; m_user.IsStar = 0; m_user.BestAnswer = 0; m_user.TotalAnswer = 0; m_user.TotalQuest = 0; m_user.HomeTown = AppConst.IntNull; m_user.Intro = AppConst.OriginalIntro; m_user.Signature = AppConst.OriginalSign; m_user.Exp = 0; m_user.TotalReply = 0; m_user.SysNo = USR_CustomerBll.GetInstance().Add(m_user); m_third.CustomerSysNo = m_user.SysNo; USR_ThirdLoginBll.GetInstance().Add(m_third); } catch (Exception ex) { throw new Exception(ex.Message); } USR_CustomerMaintain rett = new USR_CustomerMaintain(); m_customer.MemberwiseCopy(rett); return(ReturnValue <USR_CustomerMaintain> .Get200OK(rett)); }
public ReturnValue <USR_CustomerMaintain> QQLogin(string code) { //QQ回调 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Container.ConfigService.GetAppSetting <string>("ThirdLoginFilePath", "")); XmlNode node = xmlDoc.SelectSingleNode("//ThirdLogin//QQ//AppID"); XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//QQ//Key"); //获取Access Token System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=" + node.InnerText + "&client_secret=" + node1.InnerText + "&code=" + code + "&redirect_uri=" + Container.ConfigService.GetAppSetting <string>("HomeUrl", "") + "Passport/ThirdLogin.aspx"); System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse(); Encoding encoding = Encoding.UTF8; StreamReader reader = new StreamReader(res.GetResponseStream(), encoding); string ret = reader.ReadToEnd(); string retcode = ""; int timespan = 0; try { retcode = ret.Split(new char[] { '&' })[0].Split(new char[] { '=' })[1]; timespan = int.Parse(ret.Split(new char[] { '&' })[1].Split(new char[] { '=' })[1]); } catch (Exception ex) { throw new Exception(ex.Message); } //获取OpenID req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("https://graph.qq.com/oauth2.0/me?access_token=" + retcode); res = (System.Net.HttpWebResponse)req.GetResponse(); reader = new StreamReader(res.GetResponseStream(), encoding); ret = reader.ReadToEnd(); string openid = ""; try { openid = ret.Split(new char[] { '"' })[7]; } catch (Exception ex) { throw new Exception(ex.Message); } USR_CustomerMod m_customer = USR_CustomerBll.GetInstance().GetUserByThirdID(openid); if (m_customer != null && m_customer.SysNo != AppConst.IntNull) { m_customer.LastLoginTime = DateTime.Now; USR_CustomerBll.GetInstance().Update(m_customer); USR_CustomerMaintain rett = new USR_CustomerMaintain(); m_customer.MemberwiseCopy(rett); return(ReturnValue <USR_CustomerMaintain> .Get200OK(rett)); } m_customer = new USR_CustomerMod(); //获取用户信息 req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(@"https://graph.qq.com/user/get_user_info?access_token=" + retcode + "&oauth_consumer_key=" + node.InnerXml + "&openid=" + openid); res = (System.Net.HttpWebResponse)req.GetResponse(); reader = new StreamReader(res.GetResponseStream(), encoding); ret = reader.ReadToEnd(); try { m_customer.NickName = ret.Split(new char[] { ':', ',' })[7].Replace(@"""", "").DoTrim(); m_customer.Photo = ret.Split(new string[] { @""":", "," }, StringSplitOptions.None)[19].Replace(@"""", "").Replace(@"\", "").DoTrim(); if (USR_CustomerBll.GetInstance().CheckNickName(m_customer.NickName).SysNo != AppConst.IntNull) { m_customer.NickName += "-" + openid.Substring(0, 6); } } catch (Exception ex) { throw new Exception(ex.Message); } #region 保存数据 USR_ThirdLoginMod m_third = new USR_ThirdLoginMod(); m_third.OpenID = openid; m_third.AccessKey = retcode; m_third.ExpireTime = DateTime.Now.AddSeconds(timespan); m_third.ThirdType = (int)AppEnum.ThirdLoginType.qq; USR_CustomerMod m_user = new USR_CustomerMod(); try { m_user.Email = ""; m_user.FateType = (int)AppEnum.FateType.astro; m_user.GradeSysNo = AppConst.OriginalGrade;; m_user.Password = ""; m_user.RegTime = DateTime.Now; m_user.Point = AppConst.OriginalPoint; m_user.LastLoginTime = DateTime.Now; if (Container.ConfigService.GetAppSetting <string>("RegisterEmailCheck", "false").ToLower() == "true") { m_user.Status = (int)AppEnum.State.prepare; } else { m_user.Status = (int)AppEnum.State.normal; } m_user.Credit = 0; m_user.Birth = AppConst.DateTimeNull; m_user.IsShowBirth = 1; m_user.IsStar = 0; m_user.BestAnswer = 0; m_user.TotalAnswer = 0; m_user.TotalQuest = 0; m_user.HomeTown = AppConst.IntNull; m_user.Intro = AppConst.OriginalIntro; m_user.Signature = AppConst.OriginalSign; m_user.Exp = 0; m_user.TotalReply = 0; m_user.SysNo = USR_CustomerBll.GetInstance().Add(m_user); m_third.CustomerSysNo = m_user.SysNo; USR_ThirdLoginBll.GetInstance().Add(m_third); } catch (Exception ex) { throw new Exception(ex.Message); } #endregion USR_CustomerMaintain rettt = new USR_CustomerMaintain(); m_customer.MemberwiseCopy(rettt); return(ReturnValue <USR_CustomerMaintain> .Get200OK(rettt)); }
protected void LinkButton1_Click(object sender, EventArgs e) { //if (!ValidateEmail()) //{ // return; //} if (!ValidateNickName()) { return; } #region 获取用户第三方数据 USR_ThirdLoginMod m_third = new USR_ThirdLoginMod(); switch (ViewState["type"].ToString()) { case "qq": m_third.OpenID = ViewState["openid"].ToString(); m_third.AccessKey = ViewState["code"].ToString(); m_third.ExpireTime = DateTime.Now.AddSeconds(int.Parse(ViewState["expire"].ToString())); m_third.ThirdType = (int)AppEnum.ThirdLoginType.qq; break; case "weibo": m_third.OpenID = ViewState["openid"].ToString(); m_third.AccessKey = ViewState["code"].ToString(); m_third.ThirdType = (int)AppEnum.ThirdLoginType.weibo; break; default: ShowError("系统故障,请联系管理员"); break; } #endregion #region 保存数据 USR_CustomerMod m_user = new USR_CustomerMod(); try { m_user.Email = ""; m_user.FateType = int.Parse(drpType.SelectedValue); m_user.GradeSysNo = AppConst.OriginalGrade;; m_user.NickName = ViewState["nickname"].ToString(); m_user.Password = ""; m_user.RegTime = DateTime.Now; m_user.Point = AppConst.OriginalPoint; m_user.Photo = ViewState["photo"].ToString(); m_user.LastLoginTime = DateTime.Now; if (AppConfig.RegisterEmailCheck.ToLower() == "true") { m_user.Status = (int)AppEnum.State.prepare; } else { m_user.Status = (int)AppEnum.State.normal; } m_user.Credit = 0; m_user.Birth = AppConst.DateTimeNull; m_user.IsShowBirth = 1; m_user.IsStar = 0; m_user.BestAnswer = 0; m_user.TotalAnswer = 0; m_user.TotalQuest = 0; m_user.HomeTown = AppConst.IntNull; m_user.Intro = AppConst.OriginalIntro; m_user.Signature = AppConst.OriginalSign; m_user.Exp = 0; m_user.TotalReply = 0; m_user.SysNo = USR_CustomerBll.GetInstance().Add(m_user); m_third.CustomerSysNo = m_user.SysNo; USR_ThirdLoginBll.GetInstance().Add(m_third); } catch (Exception ex) { LogManagement.getInstance().WriteException(ex, "WebForMain.Register", Request.UserHostAddress); return; } #endregion #region 登陆状态设置 if (!(AppConfig.RegisterEmailCheck.ToLower() == "true")) { SessionInfo m_session = new SessionInfo(); m_session.CustomerEntity = m_user; m_session.GradeEntity = USR_GradeBll.GetInstance().GetModel(m_user.SysNo); Session[AppConfig.CustomerSession] = m_session; } #endregion if (Request.QueryString["url"] != null && Request.QueryString["url"] != "") { Response.Redirect("RegisterSucc.aspx?url=" + Request.QueryString["url"]); } else { Response.Redirect("RegisterSucc.aspx"); } }