private AdvancedResult <string> Login(string username, string password, ref AdUser loginUser) { UserServiceClient client = new UserServiceClient(); AdvancedResult <string> response = new AdvancedResult <string>(); if (string.IsNullOrEmpty(username) || username.Length < 4 || username.Length > 16) { response.Error = AppError.ERROR_FAILED; response.ExMessage = "登陆失败!用户名长度不合法!"; return(response); } if (string.IsNullOrEmpty(password) || password.Length < 6 || password.Length > 18) { response.Error = AppError.ERROR_FAILED; response.ExMessage = "登陆失败!密码长度不合法!"; return(response); } response = client.Login(username, SecurityHelper.MD5(password)); if (response.Error == AppError.ERROR_SUCCESS) { WriteAuthCookie(username, response.Data); AdvancedResult <AdUser> aduser = client.GetUserInfo(response.Data); loginUser = aduser.Data; //绑定第三方账号 //object su = Session[sKey_SocialUserKey]; //SocialUser socialUser = su != null ? su as SocialUser : null; SocialUser socialUser = SecurityHelper.DecryptObject <SocialUser>(CookieHelper.Get(sKey_SocialUserKey), null); if (socialUser != null) { AdvancedResult <string> result = client.IsBindSocialUser(socialUser); if (result.Error != AppError.ERROR_SUCCESS) { socialUser.UserId = aduser.Data.AdUserId; AdvancedResult <string> bindresponse = client.BindSocialUserAfterLogin(response.Data, socialUser); if (bindresponse.Error == AppError.ERROR_SUCCESS) { switch (socialUser.SocialUserType) { case SocialUserTypeEnum.QQ: try { OAuthToken oToken = new OAuthToken(); oToken.AccessToken = socialUser.AccessToken; oToken.OpenId = socialUser.Uid; QOpenClient qclient = new QOpenClient(oToken); var postresult = qclient.AddTopic(Config.Instance.RegisteredTwitter, "2", SiteUrl); } catch { } break; case SocialUserTypeEnum.Sina: try { OAuthAccessToken stoken = new OAuthAccessToken(); stoken.Token = socialUser.AccessToken; stoken.UserID = socialUser.Uid; UpdateStatusInfo statusInfo = new UpdateStatusInfo(); statusInfo.Status = Config.Instance.RegisteredTwitter + SiteUrl; var postresult = AMicroblog.PostStatus(statusInfo, stoken); } catch { } break; } //绑定成功 response.ExMessage = "绑定成功!"; //Session[sKey_SocialUserKey] = null; CookieHelper.Remove(sKey_SocialUserKey); } else { //绑定失败 response.ExMessage = "绑定失败!请确认该第三方账号未与本站已注册账户绑定!"; } } else { response.ExMessage = "绑定失败!该第三方账号已经于本站现有账号绑定!"; } } } client.Close(); client = null; return(response); }