{"record":{"id":"d5af5d3151357e43","repo":"RayWangQvQ/BiliBiliToolPro","slug":"cookie-accountdomainservice","errorCode":null,"errorMessage":"登录失败，请检查Cookie","messagePattern":"登录失败，请检查Cookie","errorType":"exception","errorClass":"BiliBusinessException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.DomainService/AccountDomainService.cs","lineNumber":42,"sourceCode":"    IOptionsMonitor<UnfollowBatchedTaskOptions> unfollowBatchedTaskOptions,\n    IOptionsMonitor<DailyTaskOptions> dailyTaskOptions\n) : IAccountDomainService\n{\n    private readonly UnfollowBatchedTaskOptions _unfollowBatchedTaskOptions =\n        unfollowBatchedTaskOptions.CurrentValue;\n    private readonly DailyTaskOptions _dailyTaskOptions = dailyTaskOptions.CurrentValue;\n\n    /// <summary>\n    /// 登录\n    /// </summary>\n    /// <returns></returns>\n    public async Task<UserInfo> LoginByCookie(BiliCookie cookie)\n    {\n        BiliApiResponse<UserInfo> apiResponse = await navApi.GetNavAsync(cookie.ToString());\n\n        if (apiResponse.Code != 0 || !apiResponse.Data!.IsLogin)\n        {\n            throw new BiliBusinessException(\"登录失败，请检查Cookie\");\n        }\n\n        UserInfo useInfo = apiResponse.Data;\n\n        logger.LogInformation(\"【用户名】{0}\", useInfo.GetFuzzyUname());\n        logger.LogInformation(\"【会员类型】{0}\", useInfo.VipType.Description());\n        logger.LogInformation(\"【会员状态】{0}\", useInfo.VipStatus.Description());\n        logger.LogInformation(\"【硬币余额】{0}\", useInfo.Money ?? 0);\n\n        if (useInfo.Level_info?.Current_level < 6)\n        {\n            logger.LogInformation(\n                \"【距升级Lv{0}】预计{1}天\",\n                useInfo.Level_info.Current_level + 1,\n                CalculateUpgradeTime(useInfo)\n            );\n        }\n        else","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.DomainService/AccountDomainService.cs#L24-L60","documentation":"AccountDomainService.LoginByCookie calls the nav (nav/get) API with the cookie and throws BiliBusinessException when the API returns a non-zero code or IsLogin is false — meaning the cookie did not authenticate a valid session.","triggerScenarios":"Calling LoginByCookie with an expired, revoked, or malformed SESSDATA/bili_jct; the nav API responding with code != 0 or Data.IsLogin == false.","commonSituations":"Cookie expired (Bili rotates SESSDATA periodically); user logged out or changed password after copying the cookie; cookie copied from a different/mismatched account fields; environment where cookies were partially sanitized.","solutions":["Re-export a fresh cookie from a logged-in browser and update your config.","Confirm SESSDATA and bili_jct are copied completely and unencoded from devtools.","Log back into bilibili if the session was invalidated (logout, password change, risk control).","Run BiliCookie.Check() first to catch structural problems before hitting the API."],"exampleFix":"// before (stale cookie in config)\n\"BiliCookie\": \"DedeUserID=12345; SESSDATA=expired...; bili_jct=old\"\n// after (freshly exported cookie)\n\"BiliCookie\": \"DedeUserID=12345; SESSDATA=fresh%2Cvalue; bili_jct=newtoken\"","handlingStrategy":"try-catch","validationCode":"// validate structure first, then verify login non-destructively\ntry { cookie.Check(); } catch (BiliValidationException) { /* fix config before calling LoginByCookie */ }","typeGuard":null,"tryCatchPattern":"try { var user = await accountDomainService.LoginByCookie(cookie); }\ncatch (BiliBusinessException ex)\n{\n    logger.LogError(\"登录失败，Cookie 已失效或无效: {Msg}\", ex.Message);\n    // prompt for cookie re-export and abort run\n}","preventionTips":["Re-export the cookie periodically; SESSDATA expires.","Never reuse cookies after logout or password change.","Call Check() before LoginByCookie to separate config errors from auth errors."],"tags":["csharp","auth","cookie-expired","api"],"backgroundTag":"authentication-required","analyzedSha":"c599b2c0da964e16ea8c454397aa07bb16212628","analyzedAt":"2026-09-12T09:48:04.090Z","contentChangedAt":"2026-09-12T09:48:04.090Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}