protected void Page_Load(object sender, EventArgs e) { if (!IsCallback) { Oauthkey2 oauthKey = new Oauthkey2( StringParserHelper.GetConfig("AppKey"), StringParserHelper.GetConfig("AppSercet")); oauthKey.ParseToken(this.Request.Url.ToString()); oauthKey.callbackUrl = StringParserHelper.GetConfig("CallbackUrl"); var oauth2 = new Oauth(oauthKey); var accessToken = oauth2.GetAccessToken(); if (string.IsNullOrWhiteSpace(accessToken)) { this.Response.Write("获取Access_Token失败"); } this.Session["accessToken"] = accessToken; txtMsg.Text = "授权成功,accessToken:" + accessToken; var user = new user(oauthKey, "UTF-8").info(); txtUserInfo.Text = "账户信息:\r\n" + user; } }
public platforminfo SavePlatforminfo(OAuth2Base oa, long userId) { platforminfo platformInfo = new platforminfo(); var userJson = new user(oauthKey, "json").info(); if (string.IsNullOrWhiteSpace(userJson) || (!string.IsNullOrWhiteSpace(Helper.StringParserHelper.GetJosnValue(userJson, "errcode ")) && Helper.StringParserHelper.GetJosnValue(userJson, "errcode ") != "0")) { throw new ArgumentNullException("获取用户信息失败"); } platformInfo.Nick = Helper.StringParserHelper.GetJosnValue(userJson, "nick"); platformInfo.PlatformUserId = Helper.StringParserHelper.GetJosnValue(userJson, "name"); platformInfo.UserId = userId; platformInfo.Platform = Helper.Mappings.PlatForm.QQWeiBo.ToString("G"); //新浪微博 platformInfo.SessionKey = oa.AccessToken; platformInfo.AuthDate = DateTime.Now; platformInfo.OpenId = (oa as QQWeiboOAuth2).OpenID; platformInfo.ExpireDate = oa.ExpireTime; platformInfo.Refresh_token = oa.RefreshToken; return accessor.AddEntity(platformInfo); //保存 }