{"record":{"id":"acfc5775ef8a70b3","repo":"RayWangQvQ/BiliBiliToolPro","slug":"re-tojsonstr","errorCode":null,"errorMessage":"获取二维码失败：{re.ToJsonStr()}","messagePattern":"获取二维码失败：(.+?)","errorType":"exception","errorClass":"BiliBusinessException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.DomainService/LoginDomainService.cs","lineNumber":46,"sourceCode":"    ILogger<LoginDomainService> logger,\n    IPassportApi passportApi,\n    IHostEnvironment hostingEnvironment,\n    IQingLongApi qingLongApi,\n    IBaihuApi baihuApi,\n    IHomeApi homeApi,\n    IConfiguration configuration,\n    IOptions<QingLongOptions> qingLongOptions,\n    IOptions<BaihuOptions> baihuOptions\n) : ILoginDomainService\n{\n    public async Task<BiliCookie> LoginByQrCodeAsync(CancellationToken cancellationToken)\n    {\n        BiliCookie? cookieInfo = null;\n\n        var re = await passportApi.GenerateQrCode();\n        if (re.Code != 0)\n        {\n            throw new BiliBusinessException($\"获取二维码失败：{re.ToJsonStr()}\");\n        }\n\n        var url = re.Data.Url;\n        GenerateQrCode(url);\n\n        var online = GetOnlinePic(url);\n        logger.LogInformation(Environment.NewLine + Environment.NewLine);\n        logger.LogInformation(\n            \"如果上方二维码显示异常，或扫描失败，请使用浏览器访问如下链接，查看高清二维码：\"\n        );\n        logger.LogInformation(online + Environment.NewLine + Environment.NewLine);\n\n        var waitTimes = 10;\n        logger.LogInformation(\"我数到{num}，动作快点\", waitTimes);\n        for (int i = 0; i < waitTimes; i++)\n        {\n            logger.LogInformation(\"[{num}]等待扫描...\", i + 1);\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.DomainService/LoginDomainService.cs#L28-L64","documentation":"Thrown by LoginByQrCodeAsync when the passport API's GenerateQrCode call returns a non-zero code, meaning Bilibili refused to issue a login QR code. The library wraps the whole serialized response in BiliBusinessException so the caller can see the exact API error.","triggerScenarios":"passportApi.GenerateQrCode returns re.Code != 0 — e.g. request throttled by Bilibili (too many QR generations), network/proxy interception, or a Bilibili-side passport API outage.","commonSituations":"Running the login flow repeatedly in a short period; corporate proxy or VPN returning error responses; Bilibili changing the qrcode generation endpoint (old clients get non-zero codes).","solutions":["Inspect the serialized response in the exception message to read the specific code and message.","Wait a few minutes and retry — QR generation is rate-limited by Bilibili.","Check proxy/VPN settings that may interfere with the passport API.","Upgrade Ray.BiliBiliTool in case the passport qrcode endpoint changed."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var cookie = await loginDomainService.LoginByQrCodeAsync();\n}\ncatch (BiliBusinessException ex) when (ex.Message.Contains(\"获取二维码失败\"))\n{\n    logger.LogWarning(\"二维码生成失败，稍后重试：{msg}\", ex.Message);\n    await Task.Delay(TimeSpan.FromMinutes(2));\n    // retry once\n}","preventionTips":["Don't run the QR login flow repeatedly in quick succession — it is rate-limited.","Avoid proxies/VPNs during login.","Keep the library updated for passport API endpoint changes."],"tags":["bilibili-login","qrcode","passport-api","rate-limit"],"backgroundTag":"api-error-response","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"}