Skip to content

Commit

Permalink
Upgrade:升级到net8;
Browse files Browse the repository at this point in the history
Fix:修复自动登录;
Add:支持配置每个账号的cookie;
  • Loading branch information
BlueHtml committed Jan 26, 2024
1 parent d0cdf45 commit 9a2057a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
6 changes: 3 additions & 3 deletions Note163Checkin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PuppeteerSharp" Version="9.0.2" />
<PackageReference Include="StackExchange.Redis" Version="2.6.104" />
<PackageReference Include="PuppeteerSharp" Version="14.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.7.17" />
</ItemGroup>

</Project>
55 changes: 34 additions & 21 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,44 @@
string cookie = string.Empty;
bool isInvalid = true; string result = string.Empty;

string redisKey = $"Note163_{user.Username}";
if (isRedis)
if (!string.IsNullOrWhiteSpace(user.Cookie))
{
var redisValue = await db.StringGetAsync(redisKey);
if (redisValue.HasValue)
{
cookie = redisValue.ToString();
(isInvalid, result) = await IsInvalid(cookie);
Console.WriteLine("redis获取cookie,状态:{0}", isInvalid ? "无效" : "有效");
}
Console.WriteLine("json-cookie存在,开始验证...");
cookie = user.Cookie;
(isInvalid, result) = await IsInvalid(cookie);
Console.WriteLine("json-cookie状态:{0}", isInvalid ? "无效" : "有效");
}

if (isInvalid)
{
cookie = await GetCookie(user);
(isInvalid, result) = await IsInvalid(cookie);
Console.WriteLine("login获取cookie,状态:{0}", isInvalid ? "无效" : "有效");
string redisKey = $"Note163_{user.Username}";
if (isRedis)
{
var redisValue = await db.StringGetAsync(redisKey);
if (redisValue.HasValue)
{
cookie = redisValue.ToString();
(isInvalid, result) = await IsInvalid(cookie);
Console.WriteLine("redis获取cookie,状态:{0}", isInvalid ? "无效" : "有效");
}
}

if (isInvalid)
{//Cookie失效
await Notify($"{title}Cookie失效,请检查登录状态!", true);
continue;
{
cookie = await GetCookie(user);
(isInvalid, result) = await IsInvalid(cookie);
Console.WriteLine("login获取cookie,状态:{0}", isInvalid ? "无效" : "有效");
if (isInvalid)
{//Cookie失效
await Notify($"{title}Cookie失效,请检查登录状态!", true);
continue;
}
}
}

if (isRedis)
{
Console.WriteLine($"redis更新cookie:{await db.StringSetAsync(redisKey, cookie)}");
if (isRedis)
{
Console.WriteLine($"redis更新cookie:{await db.StringSetAsync(redisKey, cookie)}");
}
}

#endregion
Expand Down Expand Up @@ -114,7 +125,7 @@ async Task<string> GetCookie(User user)
var browser = await Puppeteer.LaunchAsync(launchOptions);
IPage page = await browser.DefaultContext.NewPageAsync();

await page.GoToAsync("https://note.youdao.com/web", TIMEOUT_MS);
await page.GoToAsync(_conf.LoginUrl, TIMEOUT_MS);

bool isLogin = false;
string cookie = "fail";
Expand Down Expand Up @@ -202,15 +213,17 @@ class Conf
public string ScType { get; set; }
public string RdsServer { get; set; }
public string RdsPwd { get; set; }
public string JsUrl { get; set; } = "https://github.com/BlueHtml/pub/raw/main/code/js/note163login.js";
public string LoginUrl { get; set; } = "https://note.youdao.com/mobileSignIn/login_mobile.html?&back_url=https://note.youdao.com/web/&from=web";
public string LoginStr { get; set; } = "signIn";
public string JsUrl { get; set; } = "https://github.com/BlueHtml/pub/raw/main/code/js/note163login.js";
}

class User
{
public string Task { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Cookie { get; set; }
}

#endregion
Expand Down

0 comments on commit 9a2057a

Please sign in to comment.