public ActionResult CallBack(string code, string state) { if (code != null && Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthToken] != null) { var verifier = code; string token = Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthToken].ToString(); var qzone = new QConnectSDK.QOpenClient(verifier, token); Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthTokenSecret] = qzone; var currentQQUserWebbo = qzone.GetWeiboUserInfo(); var accessToken = qzone.OAuthToken != null ? qzone.OAuthToken.AccessToken : ""; var openId = qzone.OAuthToken != null ? qzone.OAuthToken.OpenId : ""; if (null != currentQQUserWebbo.Data && !string.IsNullOrEmpty(currentQQUserWebbo.Data.Nick)) { //是否存在一下用户 var qqLoginModel = userService.GetUserByQQ(openId); //如果存在 if (qqLoginModel != null && qqLoginModel.id > 0) { var currentUserDto = AutoMapper.Mapper.Map<Miaow.Infrastructure.Data.DataSys.Sys_AdminUser, Miaow.Service.SSO.Entity.User>(qqLoginModel); currentUserDto.LoginDomain = "http://sso.Miaow.cn"; currentUserDto.LoginIpAddress = Miaow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); //添加到SsoUserList中 //用户已登录 return UserLoginedAndRedirect(currentUserDto); } //不存在 else { #region 不存在 Miaow.Infrastructure.Data.DataSys.Sys_AdminUser user = new Infrastructure.Data.DataSys.Sys_AdminUser(); Miaow.Infrastructure.Data.DataSys.Sys_UserRoles userRole = new Infrastructure.Data.DataSys.Sys_UserRoles(); Miaow.Infrastructure.Data.DataSys.Sys_AdminUser perUser = new Infrastructure.Data.DataSys.Sys_AdminUser(); userRole.RoleID = 9; user.UserType = "tx"; user.username = currentQQUserWebbo.Data.Nick; user.truename = currentQQUserWebbo.Data.Nick; if (currentQQUserWebbo.Data.Sex == 1) { user.sex = "男"; } else if (currentQQUserWebbo.Data.Sex == 2) { user.sex = "女"; } else { user.sex = "未知"; } perUser.id = 1; userService.Add(user, userRole, perUser); if (user.id != 0) { //添加用户扩展信息 var userExtension = new Infrastructure.Data.DataSys.Sys_AdminUserExtension(); userExtension.AddTime = System.DateTime.Now; userExtension.QQId = openId; userExtension.QQScreenName = currentQQUserWebbo.Data.Nick; userExtension.TenecntAccessToken = accessToken; userExtension.TenecntAccessTokenSecret = ""; userExtension.SinaId = ""; userExtension.SinaScreenName = ""; userExtension.Sort = 0; userExtension.State = true; userExtension.UserId = user.id; userExtensionService.Add(userExtension, perUser); //end 添加用户扩展信息 var currentRegisterUserDto = AutoMapper.Mapper.Map<Miaow.Infrastructure.Data.DataSys.Sys_AdminUser, Miaow.Service.SSO.Entity.User>(user); if (currentRegisterUserDto.id > 0) { //用户登录后返回的地址 currentRegisterUserDto.LoginDomain = "http://sso.Miaow.cn"; currentRegisterUserDto.LoginIpAddress = Miaow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); //添加到SsoUserList中 //用户已登录 return UserLoginedAndRedirect(currentRegisterUserDto); } else { ViewBag.message = "亲爱的用户,您是第一次用腾讯帐号登陆Miaow网站<br/>"; ViewBag.message += "但登陆过程中出了点小毛病,<a href='/tencent/logon/'>您愿意再试一次嘛</a>"; return View(); } } else { ViewBag.message = "亲爱的用户,您是第一次用腾讯帐号登陆Miaow网站<br/>"; ViewBag.message += "但登陆过程中出了点小毛病,<a href='/tencent/logon/'>您愿意再试一次嘛</a>"; return View(); } #endregion } } else { ViewBag.message = "在连接腾讯失败了,<a href='/tencent/logon/'>请再试试</a>"; return View(); } } else { ViewBag.message = "不正确的访问方式"; return View(); } }
public ActionResult CallBack(string code, string state) { if (code != null && Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthToken] != null) { var verifier = code; string token = Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthToken].ToString(); var qzone = new QConnectSDK.QOpenClient(verifier, token); Session[Infrastructure.Crosscutting.Comm.Service.ConstService.SessionNameTencentOauthTokenSecret] = qzone; var currentQQUserWebbo = qzone.GetWeiboUserInfo(); var accessToken = qzone.OAuthToken != null ? qzone.OAuthToken.AccessToken : ""; var openId = qzone.OAuthToken != null ? qzone.OAuthToken.OpenId : ""; if (null != currentQQUserWebbo.Data && !string.IsNullOrEmpty(currentQQUserWebbo.Data.Nick)) { //是否存在一下用户 var qqLoginModel = userService.GetUserByQQ(openId); //如果存在 if (qqLoginModel != null && qqLoginModel.id > 0) { var currentUserDto = AutoMapper.Mapper.Map <iPow.Infrastructure.Data.DataSys.Sys_AdminUser, iPow.Service.SSO.Entity.User>(qqLoginModel); currentUserDto.LoginDomain = "http://sso.ipow.cn"; currentUserDto.LoginIpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); //添加到SsoUserList中 //用户已登录 return(UserLoginedAndRedirect(currentUserDto)); } //不存在 else { #region 存在 iPow.Infrastructure.Data.DataSys.Sys_AdminUser user = new Infrastructure.Data.DataSys.Sys_AdminUser(); iPow.Infrastructure.Data.DataSys.Sys_UserRoles userRole = new Infrastructure.Data.DataSys.Sys_UserRoles(); iPow.Infrastructure.Data.DataSys.Sys_AdminUser perUser = new Infrastructure.Data.DataSys.Sys_AdminUser(); userRole.RoleID = 9; user.UserType = "tx"; user.username = currentQQUserWebbo.Data.Nick; user.truename = currentQQUserWebbo.Data.Nick; if (currentQQUserWebbo.Data.Sex == 1) { user.sex = "男"; } else if (currentQQUserWebbo.Data.Sex == 2) { user.sex = "女"; } else { user.sex = "未知"; } perUser.id = 1; userService.Add(user, userRole, perUser); if (user.id != 0) { //添加用户扩展信息 var userExtension = new Infrastructure.Data.DataSys.Sys_AdminUserExtension(); userExtension.AddTime = System.DateTime.Now; userExtension.QQId = openId; userExtension.QQScreenName = currentQQUserWebbo.Data.Nick; userExtension.TenecntAccessToken = accessToken; userExtension.TenecntAccessTokenSecret = ""; userExtension.SinaId = ""; userExtension.SinaScreenName = ""; userExtension.Sort = 0; userExtension.State = true; userExtension.UserId = user.id; userExtensionService.Add(userExtension, perUser); //end 添加用户扩展信息 var currentRegisterUserDto = AutoMapper.Mapper.Map <iPow.Infrastructure.Data.DataSys.Sys_AdminUser, iPow.Service.SSO.Entity.User>(user); if (currentRegisterUserDto.id > 0) { //用户登录后返回的地址 currentRegisterUserDto.LoginDomain = "http://sso.ipow.cn"; currentRegisterUserDto.LoginIpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); //添加到SsoUserList中 //用户已登录 return(UserLoginedAndRedirect(currentRegisterUserDto)); } else { ViewBag.message = "亲爱的用户,您是第一次用腾讯帐号登陆IPOW网站<br/>"; ViewBag.message += "但登陆过程中出了点小毛病,<a href='/tencent/logon/'>您愿意再试一次嘛</a>"; return(View()); } } else { ViewBag.message = "亲爱的用户,您是第一次用腾讯帐号登陆IPOW网站<br/>"; ViewBag.message += "但登陆过程中出了点小毛病,<a href='/tencent/logon/'>您愿意再试一次嘛</a>"; return(View()); } #endregion } } else { ViewBag.message = "在连接腾讯失败了,<a href='/tencent/logon/'>请再试试</a>"; return(View()); } } else { ViewBag.message = "不正确的访问方式"; return(View()); } }