public static Characters SignCharcher() { Characters characters = new Characters(); string authCode = ESI.GetAuthorizationToken(); if (string.IsNullOrEmpty(authCode)) { return(null); } ESITokenData etd = ESI.GetESITokenData(authCode, TokenType.AuthorizationCode); // 若是无法获取 ESIToken 则返回空 if (etd == null) { return(null); } // 将AccessToken过期时间提前5s, 防止细微时间错位 characters.AccessTokenExpiredTime = DateTime.Now.AddSeconds(etd.ExpiresIn - 5); characters.AccessToken = etd.AccessToken; characters.RefreshToken = etd.RefreshToken; ESICharacterVerificationData cvd = ESI.GetESICharacterVerificationData(characters.AccessToken); characters.CharacterID = cvd.CharacterID; ESICharacterPublicData cpd = ESI.GetCharacterPublicData(characters.CharacterID); characters.CharacterName = cpd.CharacterName; characters.CorporationID = cpd.CorporationID; return(characters); }
/// <summary> /// 更新 AccessToken /// </summary> public string GetAccessToken() { if (DateTime.Now > AccessTokenExpiredTime) { // 更新 AccessToken ESITokenData etd = ESI.GetESITokenData(RefreshToken); // 将AccessToken过期时间提前5s, 防止细微时间错位 AccessTokenExpiredTime = DateTime.Now.AddSeconds(etd.ExpiresIn - 5); AccessToken = etd.AccessToken; } return(AccessToken); }