├── Cloud189Checkin ├── appsettings.Development.json ├── Properties │ └── launchSettings.json ├── appsettings.json ├── Program.cs ├── Cloud189Checkin.csproj ├── Config.cs ├── Worker.cs └── CheckinApi.cs ├── .dockerignore ├── .github └── workflows │ └── docker-image.yml ├── Dockerfile ├── Cloud189Checkin.sln ├── aot.sh ├── README.md └── .gitignore /Cloud189Checkin/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Cloud189Checkin/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Cloud189Checkin": { 4 | "commandName": "Project", 5 | "environmentVariables": { 6 | "DOTNET_ENVIRONMENT": "Development" 7 | } 8 | }, 9 | "Docker": { 10 | "commandName": "Docker" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /Cloud189Checkin/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Config": { 3 | "Times": [ "07:10:00", "22:30:00" ], 4 | "Accounts": [ 5 | { 6 | "UserName": "189xxxx", 7 | "Password": "p@ssw0rd" 8 | } 9 | ] 10 | }, 11 | "Logging": { 12 | "LogLevel": { 13 | "Cloud189Checkin": "Information", 14 | "Default": "Warning", 15 | "Microsoft": "Warning", 16 | "Microsoft.Hosting.Lifetime": "Warning", 17 | "Hangfire": "Warning" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Docker Image CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | 11 | build: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Docker Login 17 | # You may pin to the exact commit or the version. 18 | # uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 19 | uses: docker/login-action@v3.3.0 20 | with: 21 | username: ${{ secrets.DOCKER_USERNAME }} # Docker Hub 用户名 22 | password: ${{ secrets.DOCKER_PASSWORD }} # Docker Hub 密码 23 | 24 | - uses: actions/checkout@v4 25 | - name: Build the Docker image 26 | run: bash build.sh 27 | -------------------------------------------------------------------------------- /Cloud189Checkin/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Hosting; 5 | using Microsoft.Extensions.Options; 6 | 7 | namespace Cloud189Checkin 8 | { 9 | public class Program 10 | { 11 | public static void Main(string[] args) 12 | { 13 | //注册编码 14 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 15 | 16 | var builder = Host.CreateApplicationBuilder(args); 17 | builder.Services.AddTransient(); 18 | builder.Services.AddHostedService(); 19 | IConfigurationSection section = builder.Configuration.GetSection("Config"); 20 | builder.Services.Configure(section); 21 | var host = builder.Build(); 22 | host.Run(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Cloud189Checkin/Cloud189Checkin.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | Linux 5 | . 6 | https://github.com/hetaoos/Cloud189Checkin 7 | Git 8 | Null 9 | Null 10 | true 11 | true 12 | true 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build 2 | ARG TARGETARCH 3 | RUN arch=$TARGETARCH \ 4 | && if [ "$TARGETARCH" = "amd64" ]; then arch="x64"; fi \ 5 | && echo $arch > /tmp/arch 6 | 7 | WORKDIR /src 8 | ENV TZ=Asia/Shanghai 9 | RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone 10 | 11 | COPY . . 12 | 13 | RUN bash aot.sh 14 | RUN find /app -name "*.pdb" | xargs rm -f 15 | RUN find /app -name "*.dbg" | xargs rm -f 16 | RUN rm -f /app/appsettings.Development.json 17 | RUN rm -f /app/Cloud189Checkin.xml 18 | 19 | #移除 OSX Windows 下的库 20 | RUN rm -rf /app/runtimes/osx* /app/runtimes/win* /app/runtimes/*x86 /app/runtimes/linux-armel /app/runtimes/unix 21 | 22 | FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS final 23 | ARG TARGETARCH 24 | RUN arch=$TARGETARCH \ 25 | && if [ "$TARGETARCH" = "amd64" ]; then arch="x64"; fi \ 26 | && echo $arch > /tmp/arch 27 | RUN echo $arch $ $TARGETARCH 28 | WORKDIR /app 29 | EXPOSE 80 30 | ENV TZ=Asia/Shanghai 31 | RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone 32 | 33 | COPY --from=build /app . 34 | 35 | #指定IPv4优先 36 | RUN echo precedence ::ffff:0:0/96 100 >> /etc/gai.conf 37 | 38 | ENTRYPOINT ["./Cloud189Checkin"] 39 | -------------------------------------------------------------------------------- /Cloud189Checkin/Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Cloud189Checkin 4 | { 5 | /// 6 | /// 配置 7 | /// 8 | public class Config 9 | { 10 | /// 11 | /// 每日签到时间 12 | /// 13 | public TimeSpan[] Times { get; set; } 14 | 15 | /// 16 | /// 账号列表 17 | /// 18 | public Account[] Accounts { get; set; } 19 | 20 | /// 21 | /// 启动后执行的操作:默认为2,0:不执行操作;1,尝试登录;2,尝试签到 22 | /// 23 | public int? RestartAction { get; set; } = 2; 24 | } 25 | 26 | /// 27 | /// 账号 28 | /// 29 | public class Account 30 | { 31 | /// 32 | /// 是否启用,默认为启用 33 | /// 34 | public bool? Enable { get; set; } = true; 35 | 36 | /// 37 | /// 用户名 38 | /// 39 | public string UserName { get; set; } 40 | 41 | /// 42 | /// 密码 43 | /// 44 | public string Password { get; set; } 45 | 46 | /// 47 | /// 是否有效 48 | /// 49 | /// 50 | public bool IsValid() 51 | => !(Enable == false || string.IsNullOrWhiteSpace(UserName) || string.IsNullOrWhiteSpace(Password)); 52 | 53 | public override string ToString() 54 | => UserName; 55 | } 56 | } -------------------------------------------------------------------------------- /Cloud189Checkin.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34316.72 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cloud189Checkin", "Cloud189Checkin\Cloud189Checkin.csproj", "{E436074A-4C35-40BD-8712-5782933B455C}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{63C9242A-27D6-4B6D-9F46-41AA417F5781}" 9 | ProjectSection(SolutionItems) = preProject 10 | build.sh = build.sh 11 | Dockerfile = Dockerfile 12 | README.md = README.md 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {E436074A-4C35-40BD-8712-5782933B455C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {E436074A-4C35-40BD-8712-5782933B455C}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {E436074A-4C35-40BD-8712-5782933B455C}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {E436074A-4C35-40BD-8712-5782933B455C}.Release|Any CPU.Build.0 = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | GlobalSection(ExtensibilityGlobals) = postSolution 30 | SolutionGuid = {CD4F2257-74E6-44C5-B066-318D90FA5454} 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /aot.sh: -------------------------------------------------------------------------------- 1 | sed -i s@/deb.debian.org/@/mirrors.ustc.edu.cn/@g /etc/apt/sources.list && \ 2 | sed -i s@/snapshot.debian.org/@/mirrors.ustc.edu.cn/@g /etc/apt/sources.list && \ 3 | sed -i s@/security.debian.org/@/mirrors.ustc.edu.cn/@g /etc/apt/sources.list && \ 4 | sed -i s/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g /etc/apt/sources.list && \ 5 | sed -i s/archive.ubuntu.com/mirrors.ustc.edu.cn/g /etc/apt/sources.list && \ 6 | sed -i s/security.ubuntu.com/mirrors.ustc.edu.cn/g /etc/apt/sources.list && \ 7 | sed -i s/ports.ubuntu.com/mirrors.ustc.edu.cn/g /etc/apt/sources.list 8 | 9 | apt-get update -y || true 10 | apt-get install clang zlib1g-dev -y 11 | 12 | if [ "$TARGETARCH" = "arm64" ]; then 13 | . /etc/os-release 14 | apt-get install gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu libc6-dev-arm64-cross -y 15 | dpkg --add-architecture arm64 16 | echo deb [arch=arm64] https://mirrors.ustc.edu.cn/ubuntu-ports/ $VERSION_CODENAME main restricted >> /etc/apt/sources.list.d/arm64.list 17 | echo deb [arch=arm64] https://mirrors.ustc.edu.cn/ubuntu-ports/ $VERSION_CODENAME-updates main restricted >> /etc/apt/sources.list.d/arm64.list 18 | echo deb [arch=arm64] https://mirrors.ustc.edu.cn/ubuntu-ports/ $VERSION_CODENAME-backports main restricted universe multiverse >> /etc/apt/sources.list.d/arm64.list 19 | apt-get update -y || true 20 | apt-get install zlib1g-dev:arm64 -y 21 | fi; 22 | 23 | dotnet restore Cloud189Checkin/Cloud189Checkin.csproj -s https://nuget.cdn.azure.cn/v3/index.json -a $TARGETARCH 24 | 25 | if [ "$TARGETARCH" = "arm64" ]; then 26 | export OBJCOPY=aarch64-linux-gnu-objcopy 27 | else 28 | export OBJCOPY=objcopy 29 | fi; 30 | 31 | dotnet publish Cloud189Checkin/Cloud189Checkin.csproj -c Release -a $TARGETARCH -o /app -p:ObjCopyName=$OBJCOPY -p:ShouldUnsetParentConfigurationAndPlatform=false -nowarn:cs0168,cs0105 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cloud189Checkin 2 | 天翼云盘自动签到服务 3 | 4 | ## 配置说明 5 | 6 | 编辑 `appsettings.json` 文件内的以下配置 7 | ```json 8 | { 9 | "Config": { 10 | "Times": [ "07:10:00", "22:30:00" ], 11 | "Accounts": [ 12 | { 13 | "Enable": true, 14 | "UserName": "13800138000", 15 | "Password": "p@ssw0rd" 16 | } 17 | ] 18 | } 19 | } 20 | ``` 21 | ## 安装*docker-compose* 22 | 23 | * docker-compose[官网安装教程](https://docs.docker.com/compose/install/#install-compose-on-linux-systems) 24 | * 默认centos7 `yum install docker-compose`为1.18.0版本;当运行`docker-compose up -d`会提示版本不匹配(docker-compose.yml "3.7") 25 | ## 以Linux为例 26 | 27 | >要安装不同版本的 Compose,请替换1.29.2 为您要使用的 Compose 版本。 28 | 29 | 1. `sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose` 30 | 2. `sudo chmod +x /usr/local/bin/docker-compose` 31 | 3. `sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose` 32 | 4. `docker-compose --version` 33 | 34 | ``` 35 | [root@build Cloud189Checkin]# docker-compose --version 36 | docker-compose version 1.29.2, build 5becea4c 37 | ``` 38 | 39 | 字段说明: 40 | - `Times` 执行签到时间列表,`"07:10:00"` 表示在 7点10分执行一次,秒部分无效,但不能省略。 41 | - `Accounts` 账号列表, 42 | 43 | ## Docker 部署 44 | 45 | ### 创建目录 46 | ``` 47 | mkdir Cloud189Checkin/Cookies -p && cd Cloud189Checkin 48 | ``` 49 | 50 | ### 创建 `appsettings.json` 配置文件 51 | 52 | ```json 53 | { 54 | "Config": { 55 | "Times": [ "07:10:00", "22:30:00" ], 56 | "Accounts": [ 57 | { 58 | "UserName": "189xxxx", 59 | "Password": "p@ssw0rd" 60 | } 61 | ] 62 | }, 63 | "Logging": { 64 | "LogLevel": { 65 | "Default": "Information", 66 | "Microsoft": "Warning", 67 | "Microsoft.Hosting.Lifetime": "Warning", 68 | "Hangfire": "Warning" 69 | } 70 | } 71 | } 72 | ``` 73 | 74 | ### 创建 `docker-compose.yaml` 配置文件 75 | ```yaml 76 | version: '3.7' 77 | 78 | services: 79 | cloud189checkin: 80 | image: hetaoos/cloud189checkin:latest 81 | container_name: cloud189checkin 82 | restart: always 83 | network_mode: bridge 84 | volumes: 85 | - ./Cookies:/app/Cookies 86 | - ./appsettings.json:/app/appsettings.json 87 | ``` 88 | 89 | ### 启动 90 | >docker-compose up -d 91 | -------------------------------------------------------------------------------- /Cloud189Checkin/Worker.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.Extensions.Hosting; 3 | using Microsoft.Extensions.Logging; 4 | using Microsoft.Extensions.Options; 5 | using System; 6 | using System.Collections.Concurrent; 7 | using System.Linq; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace Cloud189Checkin 12 | { 13 | public class Worker : BackgroundService 14 | { 15 | private readonly IServiceProvider _serviceProvider; 16 | private readonly IOptions _config; 17 | private readonly ILogger _logger; 18 | 19 | /// 20 | /// API 21 | /// 22 | private static ConcurrentDictionary apis = new ConcurrentDictionary(); 23 | 24 | public Worker(IServiceProvider serviceProvider, IOptions config, ILogger logger) 25 | { 26 | _serviceProvider = serviceProvider; 27 | _config = config; 28 | _logger = logger; 29 | } 30 | 31 | protected override async Task ExecuteAsync(CancellationToken stoppingToken) 32 | { 33 | var cfg = _config.Value; 34 | 35 | if (cfg.Times?.Any() != true) 36 | cfg.Times = new TimeSpan[] { new TimeSpan(7, 10, 0), new TimeSpan(22, 30, 0) }; 37 | 38 | var accounts = cfg.Accounts?.Where(o => o?.IsValid() == true).ToArray(); 39 | if (accounts?.Any() != true) 40 | { 41 | _logger.LogWarning("没有有效的账号。"); 42 | throw new Exception("没有有效的账号。"); 43 | } 44 | 45 | switch (cfg.RestartAction) 46 | { 47 | case 0: 48 | break; 49 | 50 | case 1: 51 | await DoAsync(1); 52 | break; 53 | 54 | default: 55 | await DoAsync(2); 56 | break; 57 | } 58 | 59 | _logger.LogInformation("Worker staring at: {time}", DateTimeOffset.Now); 60 | 61 | var times = cfg.Times.Select(o => new TimeSpan(o.Hours % 24, o.Minutes, 0)).Distinct().OrderBy(o => o).ToList(); 62 | 63 | (TimeSpan next, TimeSpan sleep) GetNext() 64 | { 65 | var now = DateTime.Now.TimeOfDay; 66 | now = new TimeSpan(now.Hours, now.Minutes, 0); 67 | 68 | if (times.Where(o => o > now).Any()) 69 | { 70 | var next = times.Where(o => o > now).First(); 71 | return (next, next - now); 72 | } 73 | else 74 | { 75 | var next = times.First(); 76 | return (next, times.First() + new TimeSpan(24, 0, 0) - now); 77 | } 78 | } 79 | while (!stoppingToken.IsCancellationRequested) 80 | { 81 | var sp = GetNext(); 82 | _logger.LogInformation($"the next time it will be executed at {sp.next}."); 83 | await Task.Delay(sp.sleep, stoppingToken); 84 | if (!stoppingToken.IsCancellationRequested) 85 | await DoAsync(2); 86 | } 87 | } 88 | 89 | /// 90 | /// 尝试登录或者签到 91 | /// 92 | /// 93 | /// 94 | public async Task DoAsync(int mode = 2) 95 | { 96 | var cfg = _config.Value; 97 | 98 | var accounts = cfg.Accounts?.Where(o => o?.IsValid() == true).ToArray(); 99 | 100 | if (accounts?.Any() != true) 101 | { 102 | _logger.LogWarning("没有有效的账号。"); 103 | return; 104 | } 105 | 106 | foreach (var account in accounts) 107 | { 108 | _logger.LogInformation($"account: {account.UserName}"); 109 | var api = apis.GetOrAdd(account.UserName, (_) => _serviceProvider.GetService()); 110 | api.SetAccount(account.UserName, account.Password); 111 | if (mode == 1) 112 | await api.TryLoginAsync(); 113 | else 114 | await api.DoAsync(); 115 | } 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | 352 | Cloud189Checkin/Cookies/ -------------------------------------------------------------------------------- /Cloud189Checkin/CheckinApi.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Collections.Specialized; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Net; 8 | using System.Net.Http; 9 | using System.Net.Http.Headers; 10 | using System.Security.Cryptography; 11 | using System.Text; 12 | using System.Text.Json; 13 | using System.Text.Json.Nodes; 14 | using System.Text.Json.Serialization; 15 | using System.Text.RegularExpressions; 16 | using System.Threading.Tasks; 17 | using System.Web; 18 | 19 | namespace Cloud189Checkin 20 | { 21 | /// 22 | /// 签到接口 23 | /// 24 | public class CheckinApi 25 | { 26 | private readonly ILogger _logger; 27 | 28 | private HttpClient client; 29 | private HttpClientHandler httpClientHandler; 30 | private string _username; 31 | private string _password; 32 | 33 | /// 34 | /// 加密公钥 35 | /// 36 | private static string rsa_public_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZLyV4gHNDUGJMZoOcYauxmNEsKrc0TlLeBEVVIIQNzG4WqjimceOj5R9ETwDeeSN3yejAKLGHgx83lyy2wBjvnbfm/nLObyWwQD/09CmpZdxoFYCH6rdDjRpwZOZ2nXSZpgkZXoOBkfNXNxnN74aXtho2dqBynTw3NFTWyQl8BQIDAQAB"; 37 | 38 | private static string app_conf_url = "https://open.e.189.cn/api/logbox/oauth2/appConf.do"; 39 | private static string redirect_url = "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https://cloud.189.cn/web/redirect.html?returnURL=/main.action"; 40 | private static string login_url = "https://open.e.189.cn/api/logbox/oauth2/loginSubmit.do"; 41 | 42 | public CheckinApi(ILogger logger) 43 | { 44 | _logger = logger; 45 | } 46 | 47 | private void CreateHttpClient() 48 | { 49 | if (client != null) 50 | client.Dispose(); 51 | 52 | if (httpClientHandler != null) 53 | httpClientHandler.Dispose(); 54 | 55 | httpClientHandler = new HttpClientHandler() 56 | { 57 | CookieContainer = TryLoadCookies() ?? new CookieContainer(), 58 | AutomaticDecompression = DecompressionMethods.All, 59 | UseCookies = true, 60 | ServerCertificateCustomValidationCallback = (_, _, _, _) => true, 61 | }; 62 | client = new HttpClient(httpClientHandler); 63 | client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; SM-G930K Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36 Ecloud/8.6.3 Android/22 clientId/355325117317828 clientModel/SM-G930K imsi/460071114317824 clientChannelId/qq proVersion/1.0.6"); 64 | client.DefaultRequestHeaders.Referrer = new Uri("https://m.cloud.189.cn/zhuanti/2016/sign/index.jsp?albumBackupOpened=1"); 65 | client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); 66 | client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate")); 67 | } 68 | 69 | public CheckinApi SetAccount(string username, string password) 70 | { 71 | _username = username; 72 | _password = password; 73 | CreateHttpClient(); 74 | return this; 75 | } 76 | 77 | public async Task TryLoginAsync() 78 | { 79 | var url = "https://cloud.189.cn/v2/getUserLevelInfo.action"; 80 | 81 | var d = await GetData(url); 82 | if (d != null && d["ret"]?.GetValue() == 1) 83 | { 84 | _logger.LogInformation("currently logged in."); 85 | return true; 86 | } 87 | 88 | _logger.LogInformation("start logging in."); 89 | try 90 | { 91 | var resp = await client.GetAsync(redirect_url); 92 | var nameValuePairs = HttpUtility.ParseQueryString(resp.RequestMessage.RequestUri.Query); 93 | 94 | var param = new NameValueCollection(nameValuePairs); 95 | param.Add("rsaKey", rsa_public_key); 96 | 97 | var urlEncodedContent = new FormUrlEncodedContent(new Dictionary() 98 | { 99 | ["version"] = "2.0", 100 | ["appKey"] = "cloud", 101 | }); 102 | urlEncodedContent.Headers.TryAddWithoutValidation("Referer", "https://open.e.189.cn/"); 103 | urlEncodedContent.Headers.TryAddWithoutValidation("lt", param["lt"]); 104 | urlEncodedContent.Headers.TryAddWithoutValidation("REQID", param["reqId"]); 105 | 106 | resp = await client.PostAsync(app_conf_url, urlEncodedContent); 107 | var json = await resp.Content.ReadAsStringAsync(); 108 | var obj = JsonNode.Parse(json)!; 109 | string returnUrl = obj["data"]["returnUrl"].GetValue(); 110 | string paramId = obj["data"]["paramId"].GetValue(); 111 | 112 | client.DefaultRequestHeaders.TryAddWithoutValidation("lt", param["lt"]); 113 | using var rsa = RSA.Create(); 114 | rsa.ImportSubjectPublicKeyInfo(Convert.FromBase64String(rsa_public_key), out var _); 115 | 116 | string Encrypt(string _s) 117 | => BitConverter.ToString(rsa.Encrypt(Encoding.UTF8.GetBytes(_s), RSAEncryptionPadding.Pkcs1)).Replace("-", "").ToLower(); 118 | 119 | var data = new Dictionary 120 | { 121 | ["appKey"] = "cloud", 122 | ["accountType"] = "01", 123 | ["userName"] = $"{{NRP}}{Encrypt(_username)}", 124 | ["password"] = $"{{NRP}}{Encrypt(_password)}", 125 | ["validateCode"] = "", 126 | ["captchaToken"] = "", 127 | ["returnUrl"] = returnUrl, 128 | ["mailSuffix"] = "@189.cn", 129 | ["paramId"] = paramId, 130 | }; 131 | 132 | var c = new FormUrlEncodedContent(data); 133 | var s = await c.ReadAsStringAsync(); 134 | resp = await client.PostAsync(login_url, c); 135 | json = await resp.Content.ReadAsStringAsync(); 136 | obj = JsonNode.Parse(json)!; 137 | var result = obj["result"].GetValue(); 138 | var msg = obj["msg"].GetValue(); 139 | 140 | if (result != 0) 141 | { 142 | _logger.LogError($"login failed: {msg}"); 143 | return false; 144 | } 145 | _logger.LogInformation(msg); 146 | 147 | url = obj["toUrl"].GetValue(); 148 | 149 | var html = await client.GetStringAsync(url); 150 | 151 | SaveCookies(); 152 | 153 | _logger.LogInformation("login successful."); 154 | return true; 155 | } 156 | catch (Exception ex) 157 | { 158 | _logger.LogError($"login failed: {ex.Message}"); 159 | return false; 160 | } 161 | } 162 | 163 | public async Task DoAsync() 164 | { 165 | if (await TryLoginAsync() == false) 166 | return false; 167 | 168 | var rand = DateTime.Now.Ticks % 1000000; 169 | var url = $"https://m.cloud.189.cn/mkt/userSign.action?rand={rand}&clientType=TELEANDROID&version=8.6.3&model=SM-G930K"; 170 | var d = await GetData(url); 171 | if (d == null) 172 | { 173 | _logger.LogWarning("check in failed."); 174 | return false; 175 | } 176 | _logger.LogInformation($"sign time: {d["signTime"]?.GetValue():yyyy-MM-dd HH:mm:ss}, netdiskBonus: {d["netdiskBonus"]}M."); 177 | 178 | url = "https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN&activityId=ACT_SIGNIN"; 179 | await DoCheckin(url); 180 | url = "https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN_PHOTOS&activityId=ACT_SIGNIN"; 181 | await DoCheckin(url); 182 | async Task DoCheckin(string _url) 183 | { 184 | d = await GetData(_url); 185 | if (d == null) 186 | { 187 | _logger.LogWarning("draw failed."); 188 | return; 189 | } 190 | var errorCode = d["errorCode"]?.GetValue(); 191 | if (errorCode == "User_Not_Chance") 192 | _logger.LogInformation("already draw."); 193 | else if (errorCode != null) 194 | _logger.LogWarning($"draw failed: {errorCode}"); 195 | else 196 | _logger.LogInformation($"draw successful: {d["description"]}"); 197 | } 198 | 199 | //重新保存下 200 | SaveCookies(); 201 | 202 | return true; 203 | } 204 | 205 | /// 206 | /// 获取Js环境变量 207 | /// 208 | /// 209 | /// 210 | private string GetJsVariableValue(string html, string name) 211 | { 212 | //var reqId = "0057c94596e646bf"; 213 | var reg = new Regex(@$" {name}.*=.*['""](?.*)['""]", RegexOptions.Compiled); 214 | var m = reg.Match(html); 215 | if (m.Success) 216 | return m.Groups["value"].Value; 217 | return string.Empty; 218 | } 219 | 220 | /// 221 | /// 获取Html Field Value 222 | /// 223 | /// 224 | /// 225 | private string GetFieldValue(string html, string name) 226 | { 227 | // 228 | 229 | var reg = new Regex(@$"{name}.+value.*=.*['""](?.*)['""]", RegexOptions.Compiled); 230 | var m = reg.Match(html); 231 | if (m.Success) 232 | return m.Groups["value"].Value; 233 | return string.Empty; 234 | } 235 | 236 | /// 237 | /// 获取数据 238 | /// 239 | /// 240 | /// 241 | private async Task GetData(string url) 242 | { 243 | if (client == null) 244 | return null; 245 | 246 | var resp = await client.GetAsync(url); 247 | if (resp.IsSuccessStatusCode == false) 248 | return null; 249 | var json = await resp.Content.ReadAsStringAsync(); 250 | try 251 | { 252 | var node = JsonNode.Parse(json); 253 | return node; 254 | } 255 | catch (Exception ex) 256 | { 257 | _logger.LogError($"get data failed: {ex.Message}"); 258 | } 259 | 260 | return null; 261 | } 262 | 263 | private string GetCookieFileName() 264 | => $"Cookies/{_username}.v2.cookies"; 265 | 266 | private CookieContainer TryLoadCookies() 267 | { 268 | var fn = GetCookieFileName(); 269 | if (File.Exists(fn) == false) 270 | return null; 271 | 272 | try 273 | { 274 | var cc = new CookieContainer(); 275 | using var fs = File.OpenRead(fn); 276 | var cookies = JsonSerializer.Deserialize(fs, MyJsonSerializerContext.Default.ListCookie); 277 | foreach (var cookie in cookies) 278 | cc.Add(cookie); 279 | 280 | return cc; 281 | } 282 | catch { } 283 | 284 | return null; 285 | } 286 | 287 | private void SaveCookies() 288 | { 289 | var fn = GetCookieFileName(); 290 | var dir = Path.GetDirectoryName(fn); 291 | try 292 | { 293 | if (Directory.Exists(dir) == false) 294 | Directory.CreateDirectory(dir); 295 | 296 | var cookies = httpClientHandler.CookieContainer.GetAllCookies().ToList(); 297 | var bytes = JsonSerializer.SerializeToUtf8Bytes(cookies, MyJsonSerializerContext.Default.ListCookie); 298 | File.WriteAllBytes(fn, bytes); 299 | } 300 | catch { } 301 | } 302 | } 303 | 304 | [JsonSerializable(typeof(List))] 305 | [JsonSerializable(typeof(Cookie))] 306 | [JsonSerializable(typeof(Config))] 307 | [JsonSerializable(typeof(Account))] 308 | internal partial class MyJsonSerializerContext : JsonSerializerContext 309 | { 310 | } 311 | } --------------------------------------------------------------------------------