This repository was archived by the owner on Sep 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (59 loc) · 2.4 KB
/
Program.cs
File metadata and controls
69 lines (59 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
namespace SmzdmCheckin
{
class Program
{
static Conf _conf;
static HttpClient _scClient;
static async Task Main()
{
_conf = Deserialize<Conf>(GetEnvValue("CONF"));
if (!string.IsNullOrWhiteSpace(_conf.ScKey))
{
_scClient = new HttpClient();
}
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36");
client.DefaultRequestHeaders.Referrer = new Uri("https://www.smzdm.com/");
client.DefaultRequestHeaders.Add("Cookie", _conf.Cookie);
string result = await client.GetStringAsync($"https://zhiyou.smzdm.com/user/checkin/jsonp_checkin?_={DateTimeOffset.Now.ToUnixTimeMilliseconds()}");
using JsonDocument doc = JsonDocument.Parse(result);
JsonElement root = doc.RootElement;
if (root.GetProperty("error_code").GetInt32() != 0)
{//Cookie失效
await Notify($"smzdm Cookie失效,请及时更新!", true);
await Notify($"{result}");
}
else
{
await Notify($"smzdm 签到成功,签到天数: {root.GetProperty("data").GetProperty("checkin_num").GetRawText()}");
}
}
static async Task Notify(string msg, bool isFailed = false)
{
Console.WriteLine(msg);
if (_conf.ScType == "Always" || (isFailed && _conf.ScType == "Failed"))
{
await _scClient?.GetAsync($"https://sc.ftqq.com/{_conf.ScKey}.send?text={msg}");
}
}
static readonly JsonSerializerOptions _options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
ReadCommentHandling = JsonCommentHandling.Skip
};
static T Deserialize<T>(string json) => JsonSerializer.Deserialize<T>(json, _options);
static string GetEnvValue(string key) => Environment.GetEnvironmentVariable(key);
}
#region Conf
public class Conf
{
public string Cookie { get; set; }
public string ScKey { get; set; }
public string ScType { get; set; }
}
#endregion
}