├── .gitattributes
├── .github
└── workflows
│ └── async_project_files.yml
├── .gitignore
├── BiliAccount.Core31TestProject
├── BiliAccount.Core31TestProject.csproj
└── Program.cs
├── BiliAccount.Geetest.Controls
├── BiliAccount.Geetest.Controls.csproj
├── Properties
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ └── launchSettings.json
├── WPF
│ ├── GeetestBrowser.xaml
│ ├── GeetestBrowser.xaml.cs
│ ├── GeetestBrowserWindow.xaml
│ └── GeetestBrowserWindow.xaml.cs
├── Winforms
│ ├── GeetestBrowser.Designer.cs
│ ├── GeetestBrowser.cs
│ ├── GeetestBrowser.resx
│ ├── GeetestBrowserWindow.Designer.cs
│ ├── GeetestBrowserWindow.cs
│ └── GeetestBrowserWindow.resx
├── favicon_4.ico
└── favicon_4.png
├── BiliAccount.Geetest
├── BiliAccount.Geetest.csproj
├── Geetest.cs
├── Proxy.cs
└── favicon_4.png
├── BiliAccount.TestProject.WPF
├── App.config
├── App.xaml
├── App.xaml.cs
├── BiliAccount.TestProject.WPF.csproj
├── MainWindow.xaml
├── MainWindow.xaml.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── BiliAccount.TestProject.Winforms
├── App.config
├── BiliAccount.TestProject.Winforms.csproj
├── Form1.Designer.cs
├── Form1.cs
├── Form1.resx
├── Program.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── BiliAccount.TestProject
├── App.config
├── BiliAccount.TestProject.csproj
├── Program.cs
└── Properties
│ └── AssemblyInfo.cs
├── BiliAccount.sln
├── BiliAccount
├── Account.cs
├── BiliAccount.csproj
├── Core
│ ├── ByPassword.cs
│ ├── ByQRCode.cs
│ ├── BySMS.cs
│ ├── Config.cs
│ └── Device_Verify.cs
├── Exceptions
│ ├── GetAccount_Exception.cs
│ ├── InvalidColorValue.cs
│ ├── Revoke_Exception.cs
│ ├── SMS_NeedGeetest_Exception.cs
│ ├── SMS_Send_Exception.cs
│ └── Verify_Exception.cs
├── Framework4.0Methods
│ ├── Stream4Methods.cs
│ └── String4Methods.cs
├── Http.cs
├── Init.json
├── Linq
│ ├── ByPassword.cs
│ ├── ByQRCode.cs
│ ├── BySMS.cs
│ └── Device_Verify.cs
├── Properties
│ └── launchSettings.json
├── QRCode
│ ├── AbstractQRCode.cs
│ ├── PayloadGenerator.cs
│ ├── QRCode.cs
│ ├── QRCodeData.cs
│ └── QRCodeGenerator.cs
├── RSA.cs
└── favicon_4.png
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/workflows/async_project_files.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: async_project_files
4 |
5 | # Controls when the action will run. Triggers the workflow on push or pull request
6 | # events but only for the master branch
7 | on:
8 | pull_request_target:
9 | types: [ closed ]
10 | branches: [ master ]
11 |
12 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
13 | jobs:
14 | # This workflow contains a single job called "build"
15 | async_project_files:
16 | #ignore Bump braches created by bot
17 | if: contains(github.head_ref, 'Bump') == false
18 | # The type of runner that the job will run on
19 | runs-on: ubuntu-latest
20 |
21 | env:
22 | username: 'LeoChen98'
23 | pwd: ${{ secrets.password }}
24 | msg: -m "async project file from main repository by bot ${{ github.sha }}"
25 |
26 | # Steps represent a sequence of tasks that will be executed as part of the job
27 | steps:
28 | ## Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
29 | #- uses: actions/checkout@v2
30 |
31 | - name: checkout BiliAccount
32 | run: |
33 | #sudo apt-get install tree
34 | git config --global user.email "Leo@zhangbudademao.com"
35 | git config --global user.name "Leo Chen"
36 | mkdir 'BiliAccount'
37 | cd BiliAccount
38 | git init
39 | git clone -b master https://github.com/LeoChen98/BiliAccount.git
40 | cd ..
41 |
42 | # Runs a single command using the runners shell
43 | - name: async BiliAccount.Geetest
44 | run: |
45 | mkdir 'BiliAccount.Geetest'
46 | cd BiliAccount.Geetest
47 | git init
48 | git remote add origin https://$username:$pwd@github.com/LeoChen98/BiliAccount.Geetest.git
49 | git pull origin master
50 | cp -f ../BiliAccount/BiliAccount/BiliAccount.Geetest/BiliAccount.Geetest.csproj .
51 | #tree
52 | git add BiliAccount.Geetest.csproj
53 | git commit -m "async transfer project file from main repository by bot "${{ github.sha }} -n --allow-empty
54 | git push --set-upstream origin master
55 | cd ..
56 |
57 | # Runs a single command using the runners shell
58 | - name: async BiliAccount.Geetest.Controls
59 | run: |
60 | mkdir 'BiliAccount.Geetest.Controls'
61 | cd BiliAccount.Geetest.Controls
62 | git init
63 | git remote add origin https://$username:$pwd@github.com/LeoChen98/BiliAccount.Geetest.Controls.git
64 | git pull origin master
65 | cp -f ../BiliAccount/BiliAccount/BiliAccount.Geetest.Controls/BiliAccount.Geetest.Controls.csproj .
66 | #tree
67 | git add BiliAccount.Geetest.Controls.csproj
68 | git commit -m "async transfer project file from main repository by bot "${{ github.sha }} -n --allow-empty
69 | git push --set-upstream origin master
70 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
262 |
263 | # Nuget
264 | *.nuspec
265 | *.nupkg
266 | nuget.exe
267 | nuget_release.bat
268 |
269 | #Old files
270 | BiliAccount-StandardRebuild/
271 | BiliAccount-backup/
272 | BiliAccount.Geetest/Trace.cs
--------------------------------------------------------------------------------
/BiliAccount.Core31TestProject/BiliAccount.Core31TestProject.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/BiliAccount.Core31TestProject/Program.cs:
--------------------------------------------------------------------------------
1 | using BiliAccount.Linq;
2 | using System;
3 | using System.Drawing;
4 | using System.Reflection;
5 | using System.Text;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 |
9 | namespace BiliAccount.Core31TestProject
10 | {
11 | class Program
12 | {
13 | static bool q = false;
14 | [STAThread]
15 | static void Main(string[] args)
16 | {
17 | Task t = Task.Run(() =>
18 | {
19 | ByQRCode.QrCodeStatus_Changed += ByQRCode_QrCodeStatus_Changed;
20 | ByQRCode.QrCodeRefresh += ByQRCode_QrCodeRefresh;
21 | ByQRCode.LoginByQrCode().Save("tmp.jpg");
22 | while (true)
23 | {
24 |
25 | }
26 | });
27 | t.Wait();
28 | }
29 |
30 | private static void ByQRCode_QrCodeRefresh(Bitmap newQrCode)
31 | {
32 | newQrCode.Save("tmp.jpg");
33 | }
34 |
35 | private static void ByQRCode_QrCodeStatus_Changed(ByQRCode.QrCodeStatus status, Account account = null)
36 | {
37 | Console.WriteLine(status);
38 | if (account != null) { Console.WriteLine(var_dump(account)); q = true; }
39 | }
40 |
41 | ///
42 | /// equiv of PHP's var dump for an object’s properties because i cbf writing all the properties out.
43 | ///
44 | ///
45 | private static string var_dump(object info)
46 | {
47 | StringBuilder sb = new StringBuilder();
48 |
49 | Type t = info.GetType();
50 | FieldInfo[] props = t.GetFields();
51 | sb.AppendFormat("{0,-25} {1}", "Name", "Value");
52 | sb.AppendLine();
53 |
54 | foreach (FieldInfo prop in props)
55 | {
56 | try
57 | {
58 | if (prop.GetValue(info) != null)
59 | {
60 | sb.AppendFormat("{0,-25} {1}", prop.Name, prop.GetValue(info).ToString());
61 | sb.AppendLine();
62 | }
63 | }
64 | catch { }
65 | }
66 |
67 | return sb.ToString();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/BiliAccount.Geetest.Controls.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net48;net472;net471;net47;net462;net461;net46;net452
5 | $(LibraryFrameworks)
6 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
7 | false
8 | BiliAccount.Geetest.Controls
9 | true
10 | 1.0.3.3
11 | LeoChen
12 | zhangbudademao.com
13 | Copyright © 2020 zhangbudademao.com, all rights reserved.
14 | MIT
15 | https://github.com/LeoChen98/BiliAccount.Geetest.Controls
16 | https://github.com/LeoChen98/BiliAccount.Geetest.Controls
17 | git
18 | bilibili bililive bililogin biliaccount
19 | favicon_4.png
20 | 1. 更新Chromium内核版本到86。(安全更新)
21 |
22 | true
23 | snupkg
24 | true
25 | x64;x86
26 | f19de9f9-31de-4361-a4f5-1b6f6e1aa3ce
27 |
28 |
29 |
30 | BiliAccount.Geetest.Controls
31 | BiliAccount.Geetest.Controls
32 | 用于处理B站账号操作过程中的极验验证码的控件和窗体
33 |
34 |
35 |
36 | BiliAccount.Geetest.Controls.x64
37 | BiliAccount.Geetest.Controls.x64
38 | 用于处理B站账号操作过程中的极验验证码的控件和窗体(x64版本)
39 |
40 |
41 |
42 | BiliAccount.Geetest.Controls .NET 4.5.2
43 | NETFRAMEWORK;NET452;$(AdditionalConstants);X86
44 |
45 |
46 | BiliAccount.Geetest.Controls .NET 4.6
47 | NETFRAMEWORK;NET46;$(AdditionalConstants);X86
48 |
49 |
50 | BiliAccount.Geetest.Controls .NET 4.6.1
51 | NETFRAMEWORK;NET61;$(AdditionalConstants);X86
52 |
53 |
54 | BiliAccount.Geetest.Controls .NET 4.6.2
55 | NETFRAMEWORK;NET462;$(AdditionalConstants);X86
56 |
57 |
58 | BiliAccount.Geetest.Controls .NET 4.7
59 | NETFRAMEWORK;NET47;$(AdditionalConstants);X86
60 |
61 |
62 | BiliAccount.Geetest.Controls .NET 4.7.1
63 | NETFRAMEWORK;NET471;$(AdditionalConstants);X86
64 |
65 |
66 | BiliAccount.Geetest.Controls .NET 4.7.2
67 | NETFRAMEWORK;NET472;$(AdditionalConstants);X86
68 |
69 |
70 | BiliAccount.Geetest.Controls .NET 4.8
71 | NETFRAMEWORK;NET48;$(AdditionalConstants);X86
72 |
73 |
74 |
75 | BiliAccount.Geetest.Controls .NET 4.5.2 x64
76 | NETFRAMEWORK;NET452;$(AdditionalConstants);X64
77 |
78 |
79 | BiliAccount.Geetest.Controls .NET 4.6 x64
80 | NETFRAMEWORK;NET46;$(AdditionalConstants);X64
81 |
82 |
83 | BiliAccount.Geetest.Controls .NET 4.6.1 x64
84 | NETFRAMEWORK;NET61;$(AdditionalConstants);X64
85 |
86 |
87 | BiliAccount.Geetest.Controls .NET 4.6.2 x64
88 | NETFRAMEWORK;NET462;$(AdditionalConstants);X64
89 |
90 |
91 | BiliAccount.Geetest.Controls .NET 4.7 x64
92 | NETFRAMEWORK;NET47;$(AdditionalConstants);X64
93 |
94 |
95 | BiliAccount.Geetest.Controls .NET 4.7.1 x64
96 | NETFRAMEWORK;NET471;$(AdditionalConstants);X64
97 |
98 |
99 | BiliAccount.Geetest.Controls .NET 4.7.2 x64
100 | NETFRAMEWORK;NET472;$(AdditionalConstants);X64
101 |
102 |
103 | BiliAccount.Geetest.Controls .NET 4.8 x64
104 | NETFRAMEWORK;NET48;$(AdditionalConstants);X64
105 |
106 |
107 |
108 | portable
109 | true
110 | Auto
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 | True
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | True
160 | True
161 | Resources.resx
162 |
163 |
164 |
165 |
166 |
167 |
168 | GeetestBrowserWindow.xaml
169 |
170 |
171 | GeetestBrowser.xaml
172 |
173 |
174 | Designer
175 | MSBuild:Compile
176 |
177 |
178 | MSBuild:Compile
179 | Designer
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 | ResXFileCodeGenerator
190 | Resources.Designer.cs
191 |
192 |
193 |
194 |
195 |
196 |
197 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace BiliAccount.Geetest.Controls.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BiliAccount.Geetest.Controls.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 重写当前线程的 CurrentUICulture 属性
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | text/microsoft-resx
91 |
92 |
93 | 1.3
94 |
95 |
96 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
97 |
98 |
99 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
100 |
101 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "TestProject": {
4 | "commandName": "Executable"
5 | }
6 | }
7 | }
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/WPF/GeetestBrowser.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/WPF/GeetestBrowser.xaml.cs:
--------------------------------------------------------------------------------
1 | using CefSharp;
2 | using CefSharp.Wpf;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 |
6 | namespace BiliAccount.Geetest.Controls.WPF
7 | {
8 | ///
9 | /// DataViewer.xaml 的交互逻辑
10 | ///
11 | public partial class GeetestBrowser : UserControl
12 | {
13 | #region Private Fields
14 |
15 | private ChromiumWebBrowser browser;
16 |
17 | #endregion Private Fields
18 |
19 | #region Public Constructors
20 |
21 | ///
22 | /// 初始化GeetestBrowser
23 | ///
24 | public GeetestBrowser()
25 | {
26 | InitializeComponent();
27 | }
28 |
29 | #endregion Public Constructors
30 |
31 | #region Public Delegates
32 |
33 | ///
34 | /// 验证成功委托
35 | ///
36 | /// challenge
37 | /// key
38 | /// validate值
39 | public delegate void Vaildate_Success_Handler(string challenge, string key, string validate);
40 |
41 | #endregion Public Delegates
42 |
43 | #region Public Events
44 |
45 | ///
46 | /// 验证成功事件
47 | ///
48 | public event Vaildate_Success_Handler OnVaildate_Success;
49 |
50 | #endregion Public Events
51 |
52 | #region Public Properties
53 |
54 | ///
55 | /// 指示加载完毕后多少毫秒显示验证(建议不低于1500),在验证启动前修改有效,否则不会应用新的值。
56 | ///
57 | public int UIDelay { get; set; } = 3000;
58 |
59 | #endregion Public Properties
60 |
61 | #region Public Methods
62 |
63 | ///
64 | /// 刷新验证页
65 | ///
66 | public void Refresh()
67 | {
68 | browser.Reload();
69 | }
70 |
71 | ///
72 | /// 启动验证
73 | ///
74 | /// 验证地址
75 | public void StartVaildate(string url)
76 | {
77 | Geetest.OnValidate_Success += Geetest_OnValidate_Success;
78 |
79 | Geetest.StartValidate();
80 |
81 | var settings = new CefSettings();
82 |
83 | settings.CefCommandLineArgs.Add("proxy-server", $"127.0.0.1:{Geetest.Port}");
84 | settings.CefCommandLineArgs.Add("enable-media-stream", "1");
85 | settings.CefCommandLineArgs.Add("disable-gpu", "1");
86 |
87 | Cef.Initialize(settings);
88 |
89 | browser = new ChromiumWebBrowser() { Width = content.Width, Height = content.Height };
90 |
91 | content.Children.Add(browser);
92 |
93 | browser.Margin = new Thickness(0, 0, 0, 0);
94 | browser.Address = url;
95 | browser.FrameLoadEnd += Browser_FrameLoadEnd;
96 | }
97 |
98 | #endregion Public Methods
99 |
100 | #region Private Methods
101 |
102 | private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
103 | {
104 | browser.GetMainFrame().ExecuteJavaScriptAsync("document.body.style.display='none';" +
105 | "setTimeout(document.getElementById('app').style.display = 'none',100);" +
106 | "setTimeout(function(){" +
107 | "document.getElementById('send-btn').click();" +
108 | "document.getElementsByClassName('geetest_panel_ghost')[0].remove();" +
109 | "document.body.style.display='block'" +
110 | $"}},{UIDelay}); ");
111 | }
112 |
113 | private void Geetest_OnValidate_Success(string challenge, string key, string validate)
114 | {
115 | try
116 | {
117 | content.Children.Remove(browser);
118 | browser.Visibility = Visibility.Hidden;
119 | browser.Dispose();
120 | Cef.Shutdown();
121 | }
122 | catch { }
123 |
124 | OnVaildate_Success(challenge, key, validate);
125 | }
126 |
127 | #endregion Private Methods
128 | }
129 | }
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/WPF/GeetestBrowserWindow.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/WPF/GeetestBrowserWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using BiliAccount.Linq;
2 | using System.Windows;
3 |
4 | namespace BiliAccount.Geetest.Controls.WPF
5 | {
6 | ///
7 | /// DataViewer.xaml 的交互逻辑
8 | ///
9 | public partial class GeetestBrowserWindow : Window
10 | {
11 | #region Private Fields
12 |
13 | private Account account;
14 |
15 | private string tmp_token, challenge, key, validate;
16 |
17 | #endregion Private Fields
18 |
19 | #region Public Constructors
20 |
21 | ///
22 | /// 初始化GeetestBrowser
23 | ///
24 | /// 账号实例
25 | public GeetestBrowserWindow(ref Account account)
26 | {
27 | InitializeComponent();
28 |
29 | this.account = account;
30 | }
31 |
32 | #endregion Public Constructors
33 |
34 | #region Public Methods
35 |
36 | ///
37 | /// 显示验证窗体
38 | ///
39 | /// 验证url
40 | /// 账号实例
41 | /// 运行结果
42 | public static bool? ShowValidateWindowDialog(string url, ref Account account)
43 | {
44 | GeetestBrowserWindow window = new GeetestBrowserWindow(ref account);
45 |
46 | window.browser.OnVaildate_Success += window.Browser_OnVaildate_Success;
47 | window.tmp_token = Device_Verify.Url2TmpToken(url);
48 | window.browser.StartVaildate(url);
49 |
50 | return window.ShowDialog();
51 | }
52 |
53 | ///
54 | /// 显示验证窗体
55 | ///
56 | /// 账号实例
57 | /// 运行结果
58 | public static bool? ShowValidateWindowDialog(ref Account account)
59 | {
60 | return ShowValidateWindowDialog(account.Url, ref account);
61 | }
62 |
63 | #endregion Public Methods
64 |
65 | #region Private Methods
66 |
67 | private void Browser_OnVaildate_Success(string challenge, string key, string validate)
68 | {
69 | try
70 | {
71 | Device_Verify.Send_SMS(challenge, key, tmp_token, validate);
72 | this.challenge = challenge;
73 | this.key = key;
74 | this.validate = validate;
75 |
76 | Dispatcher.Invoke(() =>
77 | {
78 | CodeInputMask.Visibility = Visibility.Visible;
79 | browser.Visibility = Visibility.Hidden;
80 | });
81 | }
82 | catch (Exceptions.SMS_Send_Exception ex)
83 | {
84 | System.Windows.Forms.MessageBox.Show($"短信发送失败:{ex.Message}");
85 | Dispatcher.Invoke(() =>
86 | {
87 | CodeInputMask.Visibility = Visibility.Hidden;
88 | browser.Refresh();
89 | });
90 | throw ex;
91 | }
92 | }
93 |
94 | private void Btn_Confirm_Click(object sender, RoutedEventArgs e)
95 | {
96 | try
97 | {
98 | Device_Verify.GetAccount(Device_Verify.Verify(TB_Code.Text, tmp_token), ref account);
99 |
100 | DialogResult = true;
101 | Close();
102 | }
103 | catch (Exceptions.Verify_Exception ex)
104 | {
105 | System.Windows.Forms.MessageBox.Show($"验证码错误:{ex.Message}");
106 | }
107 | catch (Exceptions.GetAccount_Exception ex)
108 | {
109 | System.Windows.Forms.MessageBox.Show($"获取账号信息错误:{ex.Message}");
110 | }
111 | }
112 |
113 | private void Btn_Refresh_Click(object sender, RoutedEventArgs e)
114 | {
115 | browser.Refresh();
116 | }
117 |
118 | private void Btn_Resend_Click(object sender, RoutedEventArgs e)
119 | {
120 | Device_Verify.Send_SMS(challenge, key, tmp_token, validate);
121 | }
122 |
123 | #endregion Private Methods
124 | }
125 | }
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/Winforms/GeetestBrowser.Designer.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 |
3 | namespace BiliAccount.Geetest.Controls.Winforms
4 | {
5 | partial class GeetestBrowser:UserControl
6 | {
7 |
8 | ///
9 | /// 必需的设计器变量。
10 | ///
11 | private System.ComponentModel.IContainer components = null;
12 |
13 | ///
14 | /// 清理所有正在使用的资源。
15 | ///
16 | /// 如果应释放托管资源,为 true;否则为 false。
17 | protected override void Dispose(bool disposing)
18 | {
19 | if (disposing && (components != null))
20 | {
21 | components.Dispose();
22 | }
23 | base.Dispose(disposing);
24 | }
25 |
26 | #region 组件设计器生成的代码
27 |
28 | ///
29 | /// 设计器支持所需的方法 - 不要修改
30 | /// 使用代码编辑器修改此方法的内容。
31 | ///
32 | private void InitializeComponent()
33 | {
34 | this.SuspendLayout();
35 | //
36 | // GeetestBrowser
37 | //
38 | this.Name = "GeetestBrowser";
39 | this.Size = new System.Drawing.Size(175, 150);
40 | this.ResumeLayout(false);
41 |
42 | }
43 |
44 | #endregion
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/Winforms/GeetestBrowser.cs:
--------------------------------------------------------------------------------
1 | using CefSharp;
2 | using CefSharp.WinForms;
3 | using System.Windows.Forms;
4 |
5 | namespace BiliAccount.Geetest.Controls.Winforms
6 | {
7 | ///
8 | /// DataViewer.xaml 的交互逻辑
9 | ///
10 | public partial class GeetestBrowser : UserControl
11 | {
12 | #region Private Fields
13 |
14 | private ChromiumWebBrowser browser;
15 |
16 | #endregion Private Fields
17 |
18 | #region Public Constructors
19 |
20 | ///
21 | /// 初始化GeetestBrowser
22 | ///
23 | public GeetestBrowser()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | #endregion Public Constructors
29 |
30 | #region Public Delegates
31 |
32 | ///
33 | /// 验证成功委托
34 | ///
35 | /// challenge
36 | /// key
37 | /// validate值
38 | public delegate void Vaildate_Success_Handler(string challenge, string key, string validate);
39 |
40 | #endregion Public Delegates
41 |
42 | #region Public Events
43 |
44 | ///
45 | /// 验证成功事件
46 | ///
47 | public event Vaildate_Success_Handler OnVaildate_Success;
48 |
49 | #endregion Public Events
50 |
51 | #region Public Properties
52 |
53 | ///
54 | /// 指示加载完毕后多少毫秒显示验证(建议不低于1500),在验证启动前修改有效,否则不会应用新的值。
55 | ///
56 | public int UIDelay { get; set; } = 3000;
57 |
58 | #endregion Public Properties
59 |
60 | #region Public Methods
61 |
62 | ///
63 | /// 刷新验证页
64 | ///
65 | public new void Refresh()
66 | {
67 | browser.Reload();
68 | }
69 |
70 | ///
71 | /// 启动验证
72 | ///
73 | /// 验证地址
74 | public void StartVaildate(string url)
75 | {
76 | Geetest.OnValidate_Success += Geetest_OnValidate_Success;
77 |
78 | Geetest.StartValidate();
79 |
80 | var settings = new CefSettings();
81 |
82 | settings.CefCommandLineArgs.Add("--proxy-server", $"127.0.0.1:{Geetest.Port}");
83 | settings.CefCommandLineArgs.Add("enable-media-stream", "1");
84 | settings.CefCommandLineArgs.Add("disable-gpu", "1");
85 | settings.CefCommandLineArgs.Add("--ignore-urlfetcher-cert-requests", "1");
86 | settings.CefCommandLineArgs.Add("--ignore-certificate-errors", "1");
87 | settings.CefCommandLineArgs.Add("--disable-web-security", "1");
88 | Cef.Initialize(settings);
89 |
90 | browser = new ChromiumWebBrowser(url) { Width = Width, Height = Height };
91 |
92 | Controls.Add(browser);
93 |
94 | browser.Left = 0;
95 | browser.Top = 0;
96 | browser.FrameLoadEnd += Browser_FrameLoadEnd;
97 | }
98 |
99 | #endregion Public Methods
100 |
101 | #region Private Methods
102 |
103 | private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
104 | {
105 | browser.GetMainFrame().ExecuteJavaScriptAsync("document.body.style.display='none';" +
106 | "setTimeout(document.getElementById('app').style.display = 'none',100);" +
107 | "setTimeout(function(){" +
108 | "document.getElementById('send-btn').click();" +
109 | "document.getElementsByClassName('geetest_panel_ghost')[0].remove();" +
110 | "document.body.style.display='block'" +
111 | $"}},{UIDelay}); ");
112 | }
113 |
114 | private void Geetest_OnValidate_Success(string challenge, string key, string validate)
115 | {
116 | try
117 | {
118 | Controls.Remove(browser);
119 | browser.Visible = false;
120 | browser.Dispose();
121 | Cef.Shutdown();
122 | }
123 | catch { }
124 |
125 | OnVaildate_Success(challenge, key, validate);
126 | }
127 |
128 | #endregion Private Methods
129 | }
130 | }
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/Winforms/GeetestBrowser.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/Winforms/GeetestBrowserWindow.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 |
4 | namespace BiliAccount.Geetest.Controls.Winforms
5 | {
6 |
7 | partial class GeetestBrowserWindow
8 | {
9 | ///
10 | /// 必需的设计器变量。
11 | ///
12 | private System.ComponentModel.IContainer components = null;
13 |
14 | ///
15 | /// 清理所有正在使用的资源。
16 | ///
17 | /// 如果应释放托管资源,为 true;否则为 false。
18 | protected override void Dispose(bool disposing)
19 | {
20 | if (disposing && (components != null))
21 | {
22 | components.Dispose();
23 | }
24 | base.Dispose(disposing);
25 | }
26 |
27 |
28 | private void InitializeComponent()
29 | {
30 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GeetestBrowserWindow));
31 | this.browser = new BiliAccount.Geetest.Controls.Winforms.GeetestBrowser();
32 | this.CodeInputMask = new System.Windows.Forms.Panel();
33 | this.Btn_Confirm = new System.Windows.Forms.Button();
34 | this.Btn_Refresh = new System.Windows.Forms.Button();
35 | this.Btn_Resend = new System.Windows.Forms.Button();
36 | this.label1 = new System.Windows.Forms.Label();
37 | this.TB_Code = new System.Windows.Forms.TextBox();
38 | this.CodeInputMask.SuspendLayout();
39 | this.SuspendLayout();
40 | //
41 | // browser
42 | //
43 | this.browser.Location = new System.Drawing.Point(0, 0);
44 | this.browser.Name = "browser";
45 | this.browser.Size = new System.Drawing.Size(283, 310);
46 | this.browser.TabIndex = 0;
47 | this.browser.UIDelay = 3000;
48 | //
49 | // CodeInputMask
50 | //
51 | this.CodeInputMask.Controls.Add(this.TB_Code);
52 | this.CodeInputMask.Controls.Add(this.label1);
53 | this.CodeInputMask.Controls.Add(this.Btn_Resend);
54 | this.CodeInputMask.Controls.Add(this.Btn_Confirm);
55 | this.CodeInputMask.Location = new System.Drawing.Point(0, 0);
56 | this.CodeInputMask.Name = "CodeInputMask";
57 | this.CodeInputMask.Size = new System.Drawing.Size(283, 310);
58 | this.CodeInputMask.TabIndex = 1;
59 | this.CodeInputMask.Visible = false;
60 | //
61 | // Btn_Confirm
62 | //
63 | this.Btn_Confirm.Location = new System.Drawing.Point(60, 161);
64 | this.Btn_Confirm.Name = "Btn_Confirm";
65 | this.Btn_Confirm.Size = new System.Drawing.Size(75, 23);
66 | this.Btn_Confirm.TabIndex = 1;
67 | this.Btn_Confirm.Text = "确定";
68 | this.Btn_Confirm.UseVisualStyleBackColor = true;
69 | this.Btn_Confirm.Click += new System.EventHandler(this.Btn_Confirm_Click);
70 | //
71 | // Btn_Refresh
72 | //
73 | this.Btn_Refresh.Location = new System.Drawing.Point(205, 284);
74 | this.Btn_Refresh.Name = "Btn_Refresh";
75 | this.Btn_Refresh.Size = new System.Drawing.Size(75, 23);
76 | this.Btn_Refresh.TabIndex = 0;
77 | this.Btn_Refresh.Text = "刷新";
78 | this.Btn_Refresh.UseVisualStyleBackColor = true;
79 | this.Btn_Refresh.Click += new System.EventHandler(this.Btn_Refresh_Click);
80 | //
81 | // Btn_Resend
82 | //
83 | this.Btn_Resend.Location = new System.Drawing.Point(141, 161);
84 | this.Btn_Resend.Name = "Btn_Resend";
85 | this.Btn_Resend.Size = new System.Drawing.Size(75, 23);
86 | this.Btn_Resend.TabIndex = 1;
87 | this.Btn_Resend.Text = "重新发送";
88 | this.Btn_Resend.UseVisualStyleBackColor = true;
89 | this.Btn_Resend.Click += new System.EventHandler(this.Btn_Resend_Click);
90 | //
91 | // label1
92 | //
93 | this.label1.AutoSize = true;
94 | this.label1.Location = new System.Drawing.Point(100, 71);
95 | this.label1.Name = "label1";
96 | this.label1.Size = new System.Drawing.Size(77, 12);
97 | this.label1.TabIndex = 2;
98 | this.label1.Text = "请输入验证码";
99 | //
100 | // TB_Code
101 | //
102 | this.TB_Code.Location = new System.Drawing.Point(60, 110);
103 | this.TB_Code.Name = "TB_Code";
104 | this.TB_Code.Size = new System.Drawing.Size(156, 21);
105 | this.TB_Code.TabIndex = 3;
106 | this.TB_Code.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
107 | //
108 | // GeetestBrowserWindow
109 | //
110 | this.ClientSize = new System.Drawing.Size(284, 311);
111 | this.Controls.Add(this.CodeInputMask);
112 | this.Controls.Add(this.browser);
113 | this.Controls.Add(this.Btn_Refresh);
114 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
115 | this.MaximizeBox = false;
116 | this.MinimizeBox = false;
117 | this.Name = "GeetestBrowserWindow";
118 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
119 | this.Text = "极验验证";
120 | this.CodeInputMask.ResumeLayout(false);
121 | this.CodeInputMask.PerformLayout();
122 | this.ResumeLayout(false);
123 |
124 | }
125 |
126 | private GeetestBrowser browser;
127 | private System.Windows.Forms.Panel CodeInputMask;
128 | private System.Windows.Forms.Button Btn_Refresh;
129 | private System.Windows.Forms.Button Btn_Confirm;
130 | private System.Windows.Forms.Button Btn_Resend;
131 | private System.Windows.Forms.TextBox TB_Code;
132 | private System.Windows.Forms.Label label1;
133 | }
134 |
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/Winforms/GeetestBrowserWindow.cs:
--------------------------------------------------------------------------------
1 | using BiliAccount.Linq;
2 | using System;
3 | using System.Windows.Forms;
4 |
5 | namespace BiliAccount.Geetest.Controls.Winforms
6 | {
7 | ///
8 | /// DataViewer.xaml 的交互逻辑
9 | ///
10 | public partial class GeetestBrowserWindow : Form
11 | {
12 | #region Private Fields
13 |
14 | private Account account;
15 | private string tmp_token, challenge, key, validate;
16 |
17 | #endregion Private Fields
18 |
19 | #region Public Constructors
20 |
21 | ///
22 | /// 初始化GeetestBrowser
23 | ///
24 | public GeetestBrowserWindow(ref Account account)
25 | {
26 | InitializeComponent();
27 |
28 | this.account = account;
29 | }
30 |
31 | #endregion Public Constructors
32 |
33 | #region Public Methods
34 |
35 | ///
36 | /// 显示验证窗体
37 | ///
38 | /// 验证url
39 | /// 账号实例
40 | /// 运行结果
41 | public static DialogResult ShowValidateWindowDialog(string url, ref Account account)
42 | {
43 | GeetestBrowserWindow window = new GeetestBrowserWindow(ref account);
44 |
45 | window.browser.OnVaildate_Success += window.Browser_OnVaildate_Success;
46 | window.tmp_token = Device_Verify.Url2TmpToken(url);
47 | window.browser.StartVaildate(url);
48 |
49 | return window.ShowDialog();
50 | }
51 |
52 | ///
53 | /// 显示验证窗体
54 | ///
55 | /// 账号实例
56 | /// 运行结果
57 | public static DialogResult ShowValidateWindowDialog(ref Account account)
58 | {
59 | return ShowValidateWindowDialog(account.Url, ref account);
60 | }
61 |
62 | #endregion Public Methods
63 |
64 | #region Private Methods
65 |
66 | private void Browser_OnVaildate_Success(string challenge, string key, string validate)
67 | {
68 | try
69 | {
70 | Device_Verify.Send_SMS(challenge, key, tmp_token, validate);
71 | this.challenge = challenge;
72 | this.key = key;
73 | this.validate = validate;
74 |
75 | Invoke(new Action(() =>
76 | {
77 | CodeInputMask.Visible = true;
78 | browser.Visible = false;
79 | }));
80 | }
81 | catch (Exceptions.SMS_Send_Exception ex)
82 | {
83 | MessageBox.Show($"短信发送失败:{ex.Message}");
84 |
85 | Invoke(new Action(() =>
86 | {
87 | CodeInputMask.Visible = false;
88 | browser.Refresh();
89 | }));
90 |
91 | throw ex;
92 | }
93 | }
94 |
95 | private void Btn_Confirm_Click(object sender, EventArgs e)
96 | {
97 | try
98 | {
99 | Device_Verify.GetAccount(Device_Verify.Verify(TB_Code.Text, tmp_token), ref account);
100 |
101 | DialogResult = DialogResult.OK;
102 | Close();
103 | }
104 | catch (Exceptions.Verify_Exception ex)
105 | {
106 | MessageBox.Show($"验证码错误:{ex.Message}");
107 | }
108 | catch (Exceptions.GetAccount_Exception ex)
109 | {
110 | MessageBox.Show($"获取账号信息错误:{ex.Message}");
111 | }
112 | }
113 |
114 | private void Btn_Refresh_Click(object sender, EventArgs e)
115 | {
116 | browser.Refresh();
117 | }
118 |
119 | private void Btn_Resend_Click(object sender, EventArgs e)
120 | {
121 | Device_Verify.Send_SMS(challenge, key, tmp_token, validate);
122 | }
123 |
124 | #endregion Private Methods
125 | }
126 | }
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/favicon_4.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoChen98/BiliAccount/834b8eee3b2860452b9c3090dc78f1321c4fc4bf/BiliAccount.Geetest.Controls/favicon_4.ico
--------------------------------------------------------------------------------
/BiliAccount.Geetest.Controls/favicon_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoChen98/BiliAccount/834b8eee3b2860452b9c3090dc78f1321c4fc4bf/BiliAccount.Geetest.Controls/favicon_4.png
--------------------------------------------------------------------------------
/BiliAccount.Geetest/BiliAccount.Geetest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net48;net472;net471;net47;net462;net461;net46;net451;net452;net45;netstandard2.0;netstandard2.1;netcoreapp3.0;netcoreapp3.1
5 | $(LibraryFrameworks)
6 | BiliAccount.Geetest
7 | true
8 | BiliAccount.Geetest
9 | 1.0.5.5
10 | LeoChen
11 | zhangbudademao.com
12 | BiliAccount.Geetest
13 | 用于处理B站账号操作过程中的极验验证码
14 | Copyright © 2020 zhangbudademao.com, all rights reserved.
15 | MIT
16 | https://github.com/LeoChen98/BiliAccount.Geetest
17 | https://github.com/LeoChen98/BiliAccount.Geetest
18 | git
19 | bilibili bililive bililogin biliaccount
20 | favicon_4.png
21 |
22 | enhancements:
23 | 1. 更新了Titanium.Web.Proxy到3.1.1344
24 |
25 | true
26 | snupkg
27 | true
28 |
29 |
30 |
31 | BiliAccount.Geetest
32 | NETFRAMEWORK;NET45;$(AdditionalConstants)
33 |
34 |
35 | BiliAccount.Geetest .NET 4.5.1
36 | NETFRAMEWORK;NET451;$(AdditionalConstants)
37 |
38 |
39 | BiliAccount.Geetest .NET 4.5.2
40 | NETFRAMEWORK;NET452;$(AdditionalConstants)
41 |
42 |
43 | BiliAccount.Geetest .NET 4.6
44 | NETFRAMEWORK;NET46;$(AdditionalConstants)
45 |
46 |
47 | BiliAccount.Geetest .NET 4.6.1
48 | NETFRAMEWORK;NET61;$(AdditionalConstants)
49 |
50 |
51 | BiliAccount.Geetest .NET 4.6.2
52 | NETFRAMEWORK;NET462;$(AdditionalConstants)
53 |
54 |
55 | BiliAccount.Geetest .NET 4.7
56 | NETFRAMEWORK;NET47;$(AdditionalConstants)
57 |
58 |
59 | BiliAccount.Geetest .NET 4.7.1
60 | NETFRAMEWORK;NET471;$(AdditionalConstants)
61 |
62 |
63 | BiliAccount.Geetest .NET 4.7.2
64 | NETFRAMEWORK;NET472;$(AdditionalConstants)
65 |
66 |
67 | BiliAccount.Geetest .NET 4.8
68 | NETFRAMEWORK;NET48;$(AdditionalConstants)
69 |
70 |
71 | BiliAccount.Geetest .NET Standard 2.0
72 | NETSTANDARD2_0;$(AdditionalConstants)
73 |
74 |
75 | BiliAccount.Geetest .NET Standard 2.1
76 | NETSTANDARD2_0;$(AdditionalConstants)
77 |
78 |
79 | BiliAccount.Geetest .NET Core 3.0
80 | NETCORE3_0;$(AdditionalConstants)
81 |
82 |
83 | BiliAccount.Geetest .NET Core 3.1
84 | NETCORE3_0;$(AdditionalConstants)
85 |
86 |
87 |
88 | none
89 | false
90 | Auto
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | True
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/BiliAccount.Geetest/Geetest.cs:
--------------------------------------------------------------------------------
1 | namespace BiliAccount.Geetest
2 | {
3 | ///
4 | /// 极验模块入口
5 | ///
6 | public class Geetest
7 | {
8 | #region Public Delegates
9 |
10 | ///
11 | /// 验证成功委托
12 | ///
13 | /// challenge
14 | /// key
15 | /// validate值
16 | public delegate void Validate_Success_Handler(string challenge, string key, string validate);
17 |
18 | #endregion Public Delegates
19 |
20 | #region Public Events
21 |
22 | ///
23 | /// 验证成功事件
24 | ///
25 | public static event Validate_Success_Handler OnValidate_Success;
26 |
27 | #endregion Public Events
28 |
29 | #region Public Properties
30 |
31 | ///
32 | /// 代理端口
33 | ///
34 | public static int Port { get; private set; }
35 |
36 | #endregion Public Properties
37 |
38 | #region Public Methods
39 |
40 | ///
41 | /// 开始验证
42 | ///
43 | public static void StartValidate()
44 | {
45 | Proxy.Instance.Run();
46 |
47 | Port = Proxy.Instance.Port;
48 | }
49 |
50 | #endregion Public Methods
51 |
52 | #region Internal Methods
53 |
54 | ///
55 | /// 调起验证成功事件
56 | ///
57 | /// challenge
58 | /// key
59 | /// validate值
60 | internal static void Call_Validate_Success(string challenge, string key, string validate)
61 | {
62 | OnValidate_Success(challenge, key, validate);
63 | }
64 |
65 | #endregion Internal Methods
66 | }
67 | }
--------------------------------------------------------------------------------
/BiliAccount.Geetest/Proxy.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Net;
3 | using System.Net.NetworkInformation;
4 | using System.Text.RegularExpressions;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using Titanium.Web.Proxy;
8 | using Titanium.Web.Proxy.EventArguments;
9 | using Titanium.Web.Proxy.Models;
10 |
11 | namespace BiliAccount.Geetest
12 | {
13 | ///
14 | /// 用于截获数据的代理
15 | ///
16 | internal class Proxy
17 | {
18 | #region Private Fields
19 |
20 | private static Proxy _proxy;
21 | private string challenge, key;
22 | private ProxyServer proxyServer;
23 |
24 | private Regex reg_challenge = new Regex("&challenge=(.+?)&");
25 | private Regex reg_key = new Regex("\"key\":\"(.+?)\"");
26 | private Regex reg_validate = new Regex("\"validate\": \"(.+?)\"");
27 |
28 | #endregion Private Fields
29 |
30 | #region Private Constructors
31 |
32 | ///
33 | /// 初始化代理
34 | ///
35 | private Proxy()
36 | {
37 | proxyServer = new ProxyServer(false);
38 |
39 | proxyServer.BeforeRequest += OnRequest;
40 | proxyServer.BeforeResponse += OnResponse;
41 |
42 | Port = GetFirstAvailablePort();
43 | var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, Port, true);
44 |
45 | proxyServer.AddEndPoint(explicitEndPoint);
46 | }
47 |
48 | #endregion Private Constructors
49 |
50 | #region Public Properties
51 |
52 | ///
53 | /// 代理单例实例
54 | ///
55 | public static Proxy Instance
56 | {
57 | get
58 | {
59 | if (_proxy == null) _proxy = new Proxy();
60 | return _proxy;
61 | }
62 | }
63 |
64 | ///
65 | /// 指示代理是否正在运行
66 | ///
67 | public bool IsRuning { get; private set; } = false;
68 |
69 | ///
70 | /// 代理端口
71 | ///
72 | public int Port { get; private set; }
73 |
74 | #endregion Public Properties
75 |
76 | #region Public Methods
77 |
78 | ///
79 | /// 启动代理
80 | ///
81 | public void Run()
82 | {
83 | if (IsRuning)
84 | {
85 | proxyServer.Start();
86 | IsRuning = true;
87 | }
88 | }
89 |
90 | #endregion Public Methods
91 |
92 | #region Private Methods
93 |
94 | ///
95 | /// 获取第一个可用的端口号
96 | ///
97 | ///
98 | private static int GetFirstAvailablePort(int BEGIN_PORT = 8000, int MAX_PORT = 10000)
99 | {
100 | for (int i = BEGIN_PORT; i < MAX_PORT; i++)
101 | {
102 | if (PortIsAvailable(i)) return i;
103 | }
104 |
105 | return -1;
106 | }
107 |
108 | ///
109 | /// 检查指定端口是否已用
110 | ///
111 | ///
112 | ///
113 | private static bool PortIsAvailable(int port)
114 | {
115 | bool isAvailable = true;
116 |
117 | IList portUsed = PortIsUsed();
118 |
119 | foreach (int p in portUsed)
120 | {
121 | if (p == port)
122 | {
123 | isAvailable = false; break;
124 | }
125 | }
126 |
127 | return isAvailable;
128 | }
129 |
130 | ///
131 | /// 获取操作系统已用的端口号
132 | ///
133 | ///
134 | private static IList PortIsUsed()
135 | {
136 | //获取本地计算机的网络连接和通信统计数据的信息
137 | IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
138 |
139 | //返回本地计算机上的所有Tcp监听程序
140 | IPEndPoint[] ipsTCP = ipGlobalProperties.GetActiveTcpListeners();
141 |
142 | //返回本地计算机上的所有UDP监听程序
143 | IPEndPoint[] ipsUDP = ipGlobalProperties.GetActiveUdpListeners();
144 |
145 | //返回本地计算机上的Internet协议版本4(IPV4 传输控制协议(TCP)连接的信息。
146 | TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
147 |
148 | IList allPorts = new ArrayList();
149 | foreach (IPEndPoint ep in ipsTCP) allPorts.Add(ep.Port);
150 | foreach (IPEndPoint ep in ipsUDP) allPorts.Add(ep.Port);
151 | foreach (TcpConnectionInformation conn in tcpConnInfoArray) allPorts.Add(conn.LocalEndPoint.Port);
152 |
153 | return allPorts;
154 | }
155 |
156 | private Task OnRequest(object sender, SessionEventArgs e)
157 | {
158 | return Task.Run(() =>
159 | {
160 | if (e.HttpClient.Request.Url.Contains("/x/safecenter/sms/send"))
161 | {
162 | Thread.Sleep(2000);
163 | e.Ok("");
164 | }
165 |
166 | challenge = reg_challenge.IsMatch(e.HttpClient.Request.Url) ? reg_challenge.Match(e.HttpClient.Request.Url).Groups[1].Value : challenge;
167 | });
168 | }
169 |
170 | private async Task OnResponse(object sender, SessionEventArgs e)
171 | {
172 | if (e.HttpClient.Response.StatusCode == 200)
173 | {
174 | string body = await e.GetResponseBodyAsString();
175 | if (e.HttpClient.Request.Url.Contains("/web/captcha/combine"))
176 | {
177 | key = reg_key.IsMatch(body) ? reg_key.Match(body).Groups[1].Value : null;
178 | }
179 |
180 | if (e.HttpClient.Request.Url.Contains("/ajax.php"))
181 | {
182 | string validate = reg_validate.IsMatch(body) ? reg_validate.Match(body).Groups[1].Value : null;
183 |
184 | if (!string.IsNullOrEmpty(validate))
185 | {
186 | Geetest.Call_Validate_Success(challenge, key, validate);
187 | proxyServer.Stop();
188 | IsRuning = false;
189 | }
190 | }
191 | }
192 | }
193 |
194 | #endregion Private Methods
195 | }
196 | }
--------------------------------------------------------------------------------
/BiliAccount.Geetest/favicon_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoChen98/BiliAccount/834b8eee3b2860452b9c3090dc78f1321c4fc4bf/BiliAccount.Geetest/favicon_4.png
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace BiliAccount.TestProject.WPF
10 | {
11 | ///
12 | /// App.xaml 的交互逻辑
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/BiliAccount.TestProject.WPF.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {3168ACE0-0736-41E8-90CB-D368379200FF}
8 | WinExe
9 | BiliAccount.TestProject.WPF
10 | BiliAccount.TestProject.WPF
11 | v4.8
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 | true
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 4.0
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | MSBuild:Compile
57 | Designer
58 |
59 |
60 | MSBuild:Compile
61 | Designer
62 |
63 |
64 | App.xaml
65 | Code
66 |
67 |
68 | MainWindow.xaml
69 | Code
70 |
71 |
72 |
73 |
74 | Code
75 |
76 |
77 | True
78 | True
79 | Resources.resx
80 |
81 |
82 | True
83 | Settings.settings
84 | True
85 |
86 |
87 | ResXFileCodeGenerator
88 | Resources.Designer.cs
89 |
90 |
91 | SettingsSingleFileGenerator
92 | Settings.Designer.cs
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | {d54053b7-5294-4468-adc2-80e839434a3c}
101 | BiliAccount.Geetest.Controls
102 |
103 |
104 | {d50857e8-cd41-4049-b0e4-fe87cdf2cc88}
105 | BiliAccount.Geetest
106 |
107 |
108 | {051e5f22-f345-4871-9433-c586a0c6a968}
109 | BiliAccount
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using BiliAccount.Linq;
2 | using System;
3 | using System.Reflection;
4 | using System.Text;
5 | using System.Windows;
6 |
7 | namespace BiliAccount.TestProject.WPF
8 | {
9 | ///
10 | /// MainWindow.xaml 的交互逻辑
11 | ///
12 | public partial class MainWindow : Window
13 | {
14 | #region Private Fields
15 |
16 | private Account account;
17 |
18 | private string tmp_token;
19 |
20 | #endregion Private Fields
21 |
22 | #region Public Constructors
23 |
24 | public MainWindow()
25 | {
26 | InitializeComponent();
27 | }
28 |
29 | #endregion Public Constructors
30 |
31 | #region Private Methods
32 |
33 | ///
34 | /// equiv of PHP's var dump for an object’s properties because i cbf writing all the properties out.
35 | ///
36 | ///
37 | private static string var_dump(object info)
38 | {
39 | StringBuilder sb = new StringBuilder();
40 |
41 | Type t = info.GetType();
42 | FieldInfo[] props = t.GetFields();
43 | sb.AppendFormat("{0,-25} {1}", "Name", "Value");
44 | sb.AppendLine();
45 |
46 | foreach (FieldInfo prop in props)
47 | {
48 | try
49 | {
50 | if (prop.GetValue(info) != null)
51 | {
52 | sb.AppendFormat("{0,-25} {1}", prop.Name, prop.GetValue(info).ToString());
53 | sb.AppendLine();
54 | }
55 | }
56 | catch { }
57 | }
58 |
59 | return sb.ToString();
60 | }
61 |
62 | private void Browser_OnVaildate_Success(string challenge, string key, string validate)
63 | {
64 | Device_Verify.Send_SMS(challenge, key, tmp_token, validate);
65 | }
66 |
67 | private void button_Click(object sender, RoutedEventArgs e)
68 | {
69 | string code = Device_Verify.Verify(textBox.Text, tmp_token);
70 | Device_Verify.GetAccount(code, ref account);
71 | System.Windows.Forms.MessageBox.Show(var_dump(account));
72 | }
73 |
74 | private void Window_Loaded(object sender, RoutedEventArgs e)
75 | {
76 | Console.WriteLine($"测试版本:");
77 | Console.WriteLine($"BiliAccount:{AssemblyName.GetAssemblyName("BiliAccount.dll").Version.ToString()}");
78 | Console.WriteLine($"BiliAccount.Geetest:{AssemblyName.GetAssemblyName("BiliAccount.Geetest.dll").Version.ToString()}");
79 | Console.WriteLine($"BiliAccount.Geetest.Controls:{AssemblyName.GetAssemblyName("BiliAccount.Geetest.Controls.dll").Version.ToString()}");
80 | Console.WriteLine("账号");
81 | string username = "";
82 | Console.WriteLine("密码");
83 | string pwd = "";
84 | account = ByPassword.LoginByPassword(username, pwd);
85 | Console.WriteLine(var_dump(account));
86 |
87 | browser.OnVaildate_Success += Browser_OnVaildate_Success;
88 | if (account.LoginStatus == Account.LoginStatusEnum.NeedSafeVerify)
89 | {
90 | //tmp_token = Device_Verify.Url2TmpToken(account.Url);
91 | //browser.StartVaildate(account.Url);
92 | Geetest.Controls.WPF.GeetestBrowserWindow.ShowValidateWindowDialog(account.Url, ref account);
93 | Console.WriteLine(var_dump(account));
94 | }
95 | }
96 |
97 | #endregion Private Methods
98 | }
99 | }
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // 有关程序集的一般信息由以下
8 | // 控制。更改这些特性值可修改
9 | // 与程序集关联的信息。
10 | [assembly: AssemblyTitle("BiliAccount.TestProject.WPF")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("BiliAccount.TestProject.WPF")]
15 | [assembly: AssemblyCopyright("Copyright © 2020")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // 将 ComVisible 设置为 false 会使此程序集中的类型
20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
21 | //请将此类型的 ComVisible 特性设置为 true。
22 | [assembly: ComVisible(false)]
23 |
24 | //若要开始生成可本地化的应用程序,请设置
25 | //.csproj 文件中的 CultureYouAreCodingWith
26 | //例如,如果您在源文件中使用的是美国英语,
27 | //使用的是美国英语,请将 设置为 en-US。 然后取消
28 | //对以下 NeutralResourceLanguage 特性的注释。 更新
29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36 | //(未在页面中找到资源时使用,
37 | //或应用程序资源字典中找到时使用)
38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39 | //(未在页面中找到资源时使用,
40 | //、应用程序或任何主题专用资源字典中找到时使用)
41 | )]
42 |
43 |
44 | // 程序集的版本信息由下列四个值组成:
45 | //
46 | // 主版本
47 | // 次版本
48 | // 生成号
49 | // 修订号
50 | //
51 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
52 | //通过使用 "*",如下所示:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本: 4.0.30319.42000
5 | //
6 | // 对此文件的更改可能导致不正确的行为,如果
7 | // 重新生成代码,则所做更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace BiliAccount.TestProject.WPF.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 强类型资源类,用于查找本地化字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 返回此类使用的缓存 ResourceManager 实例。
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BiliAccount.TestProject.WPF.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 覆盖当前线程的 CurrentUICulture 属性
56 | /// 使用此强类型的资源类的资源查找。
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace BiliAccount.TestProject.WPF.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.WPF/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/BiliAccount.TestProject.Winforms.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {198FAA7F-444F-4511-BB37-BE2F57079B45}
8 | WinExe
9 | BiliAccount.TestProject.Winforms
10 | BiliAccount.TestProject.Winforms
11 | v4.8
12 | 512
13 | true
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 | ..\BiliAccount\bin\Debug\net48\BiliAccount.dll
38 |
39 |
40 | ..\BiliAccount.Geetest\bin\Debug\net48\BiliAccount.Geetest.dll
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | Form
61 |
62 |
63 | Form1.cs
64 |
65 |
66 |
67 |
68 | Form1.cs
69 |
70 |
71 | ResXFileCodeGenerator
72 | Resources.Designer.cs
73 | Designer
74 |
75 |
76 | True
77 | Resources.resx
78 |
79 |
80 | SettingsSingleFileGenerator
81 | Settings.Designer.cs
82 |
83 |
84 | True
85 | Settings.settings
86 | True
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | {D54053B7-5294-4468-ADC2-80E839434A3C}
95 | BiliAccount.Geetest.Controls
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace BiliAccount.TestProject.Winforms
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要修改
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.browser = new BiliAccount.Geetest.Controls.Winforms.GeetestBrowser();
32 | this.textBox = new System.Windows.Forms.TextBox();
33 | this.button = new System.Windows.Forms.Button();
34 | this.SuspendLayout();
35 | //
36 | // browser
37 | //
38 | this.browser.Location = new System.Drawing.Point(0, 1);
39 | this.browser.Name = "browser";
40 | this.browser.Size = new System.Drawing.Size(802, 415);
41 | this.browser.TabIndex = 0;
42 | this.browser.UIDelay = 3000;
43 | //
44 | // textBox
45 | //
46 | this.textBox.Location = new System.Drawing.Point(233, 422);
47 | this.textBox.Name = "textBox";
48 | this.textBox.Size = new System.Drawing.Size(100, 21);
49 | this.textBox.TabIndex = 1;
50 | //
51 | // button
52 | //
53 | this.button.Location = new System.Drawing.Point(390, 420);
54 | this.button.Name = "button";
55 | this.button.Size = new System.Drawing.Size(75, 23);
56 | this.button.TabIndex = 2;
57 | this.button.Text = "button1";
58 | this.button.UseVisualStyleBackColor = true;
59 | this.button.Click += new System.EventHandler(this.button_Click);
60 | //
61 | // Form1
62 | //
63 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
64 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
65 | this.ClientSize = new System.Drawing.Size(800, 450);
66 | this.Controls.Add(this.button);
67 | this.Controls.Add(this.textBox);
68 | this.Controls.Add(this.browser);
69 | this.Name = "Form1";
70 | this.Text = "Form1";
71 | this.Load += new System.EventHandler(this.Form1_Load);
72 | this.ResumeLayout(false);
73 | this.PerformLayout();
74 |
75 | }
76 |
77 | #endregion
78 |
79 | private Geetest.Controls.Winforms.GeetestBrowser browser;
80 | private System.Windows.Forms.TextBox textBox;
81 | private System.Windows.Forms.Button button;
82 | }
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Form1.cs:
--------------------------------------------------------------------------------
1 | using BiliAccount.Linq;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Data;
6 | using System.Drawing;
7 | using System.Linq;
8 | using System.Reflection;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 | using System.Windows.Forms;
12 |
13 | namespace BiliAccount.TestProject.Winforms
14 | {
15 | public partial class Form1 : Form
16 | {
17 | private Account account;
18 |
19 | private string tmp_token;
20 | public Form1()
21 | {
22 | InitializeComponent();
23 | }
24 |
25 | private void Browser_OnVaildate_Success(string challenge, string key, string validate)
26 | {
27 | Device_Verify.Send_SMS(challenge, key, tmp_token, validate);
28 | }
29 |
30 | private void button_Click(object sender, EventArgs e)
31 | {
32 | string code = Device_Verify.Verify(textBox.Text, tmp_token);
33 | Device_Verify.GetAccount(code, ref account);
34 | MessageBox.Show(var_dump(account));
35 | }
36 |
37 |
38 | ///
39 | /// equiv of PHP's var dump for an object’s properties because i cbf writing all the properties out.
40 | ///
41 | ///
42 | private static string var_dump(object info)
43 | {
44 | StringBuilder sb = new StringBuilder();
45 |
46 | Type t = info.GetType();
47 | FieldInfo[] props = t.GetFields();
48 | sb.AppendFormat("{0,-25} {1}", "Name", "Value");
49 | sb.AppendLine();
50 |
51 | foreach (FieldInfo prop in props)
52 | {
53 | try
54 | {
55 | if (prop.GetValue(info) != null)
56 | {
57 | sb.AppendFormat("{0,-25} {1}", prop.Name, prop.GetValue(info).ToString());
58 | sb.AppendLine();
59 | }
60 | }
61 | catch { }
62 | }
63 |
64 | return sb.ToString();
65 | }
66 |
67 | private void Form1_Load(object sender, EventArgs e)
68 | {
69 | Console.WriteLine($"测试版本:");
70 | Console.WriteLine($"BiliAccount:{AssemblyName.GetAssemblyName("BiliAccount.dll").Version.ToString()}");
71 | Console.WriteLine($"BiliAccount.Geetest:{AssemblyName.GetAssemblyName("BiliAccount.Geetest.dll").Version.ToString()}");
72 | Console.WriteLine($"BiliAccount.Geetest.Controls:{AssemblyName.GetAssemblyName("BiliAccount.Geetest.Controls.dll").Version.ToString()}");
73 | Console.WriteLine("账号");
74 | string username = "";
75 | Console.WriteLine("密码");
76 | string pwd = "";
77 | account = ByPassword.LoginByPassword(username, pwd);
78 | Console.WriteLine(var_dump(account));
79 |
80 | browser.OnVaildate_Success += Browser_OnVaildate_Success;
81 | if (account.LoginStatus == Account.LoginStatusEnum.NeedSafeVerify)
82 | {
83 | //tmp_token = Device_Verify.Url2TmpToken(account.Url);
84 | //browser.StartVaildate(account.Url);
85 | Geetest.Controls.Winforms.GeetestBrowserWindow.ShowValidateWindowDialog(account.Url, ref account);
86 | Console.WriteLine(var_dump(account));
87 | }
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace BiliAccount.TestProject.Winforms
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// 应用程序的主入口点。
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form1());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("BiliAccount.TestProject.Winforms")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("BiliAccount.TestProject.Winforms")]
13 | [assembly: AssemblyCopyright("Copyright © 2020")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("198faa7f-444f-4511-bb37-be2f57079b45")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
33 | //通过使用 "*",如下所示:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本: 4.0.30319.42000
5 | //
6 | // 对此文件的更改可能导致不正确的行为,如果
7 | // 重新生成代码,则所做更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace BiliAccount.TestProject.Winforms.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 强类型资源类,用于查找本地化字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 返回此类使用的缓存 ResourceManager 实例。
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BiliAccount.TestProject.Winforms.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 覆盖当前线程的 CurrentUICulture 属性
56 | /// 使用此强类型的资源类的资源查找。
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace BiliAccount.TestProject.Winforms.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject.Winforms/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject/BiliAccount.TestProject.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}
8 | Exe
9 | BiliAccount.TestProject
10 | BiliAccount.TestProject
11 | v4.8
12 | 512
13 | true
14 |
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | {d54053b7-5294-4468-adc2-80e839434a3c}
57 | BiliAccount.Geetest.Controls
58 |
59 |
60 | {d50857e8-cd41-4049-b0e4-fe87cdf2cc88}
61 | BiliAccount.Geetest
62 |
63 |
64 | {051e5f22-f345-4871-9433-c586a0c6a968}
65 | BiliAccount
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/BiliAccount.TestProject/Program.cs:
--------------------------------------------------------------------------------
1 | using BiliAccount.Linq;
2 | using BiliAccount.Geetest;
3 | using System;
4 | using System.Diagnostics;
5 | using System.Drawing;
6 | using System.Reflection;
7 | using System.Text;
8 | using System.Windows.Forms;
9 |
10 |
11 | #pragma warning disable CS0649
12 |
13 | namespace BiliAccount.TestProject
14 | {
15 | internal class Program
16 | {
17 | #region Private Methods
18 |
19 | private static void ByQRCode_QrCodeRefresh(Bitmap newQrCode)
20 | {
21 | newQrCode.Save("tmp.jpg");
22 | }
23 |
24 | private static void ByQRCode_QrCodeStatus_Changed(ByQRCode.QrCodeStatus status, Account account = null)
25 | {
26 | Console.WriteLine(status);
27 | if (account != null) Console.WriteLine(var_dump(account));
28 | }
29 |
30 | private static void Main(string[] args)
31 | {
32 | Console.WriteLine($"测试版本:");
33 | Console.WriteLine($"BiliAccount:{AssemblyName.GetAssemblyName("BiliAccount.dll").Version.ToString()}");
34 | Console.WriteLine($"BiliAccount.Geetest:{AssemblyName.GetAssemblyName("BiliAccount.Geetest.dll").Version.ToString()}");
35 | Console.WriteLine($"BiliAccount.Geetest.Controls:{AssemblyName.GetAssemblyName("BiliAccount.Geetest.Controls.dll").Version.ToString()}");
36 | Console.WriteLine("账号");
37 | string username = Console.ReadLine();
38 | Console.WriteLine("密码");
39 | string pwd = Console.ReadLine();
40 | Account account = ByPassword.LoginByPassword(username, pwd);
41 | Console.WriteLine(var_dump(account));
42 | if (account.LoginStatus == Account.LoginStatusEnum.NeedSafeVerify) Process.Start(account.Url);
43 |
44 | //ByQRCode.QrCodeStatus_Changed += ByQRCode_QrCodeStatus_Changed;
45 | //ByQRCode.QrCodeRefresh += ByQRCode_QrCodeRefresh;
46 | //ByQRCode.LoginByQrCode("#ff000000", "#00FFFFFF").Save("tmp.png");
47 |
48 | //string token = Console.ReadLine();
49 | //Console.WriteLine(BiliAccount.Linq.ByPassword.IsTokenAvailable(token));
50 |
51 | //Console.WriteLine("手机号");
52 | //string tel = Console.ReadLine();
53 | //BySMS.SendSMS(tel);
54 | //Console.WriteLine("验证码");
55 | //string code = Console.ReadLine();
56 | //Account account = BySMS.Login(code, tel);
57 | //Console.WriteLine(var_dump(account));
58 |
59 | //Console.WriteLine(var_dump(ByPassword.SSO(account.AccessToken)));
60 |
61 | //account.Expires_AccessToken = (DateTime)ByPassword.RefreshToken("76b3e1cb9b0d35a80f8c444dcdcb1a21", "bcb656a377362db92487929a7f258d21");
62 | //Console.WriteLine(var_dump(account));
63 |
64 | //ByPassword.Revoke(ref account);
65 |
66 | Application.Run();
67 | }
68 |
69 | ///
70 | /// equiv of PHP's var dump for an object’s properties because i cbf writing all the properties out.
71 | ///
72 | ///
73 | private static string var_dump(object info)
74 | {
75 | StringBuilder sb = new StringBuilder();
76 |
77 | Type t = info.GetType();
78 | FieldInfo[] props = t.GetFields();
79 | sb.AppendFormat("{0,-25} {1}", "Name", "Value");
80 | sb.AppendLine();
81 |
82 | foreach (FieldInfo prop in props)
83 | {
84 | try
85 | {
86 | if (prop.GetValue(info) != null)
87 | {
88 | sb.AppendFormat("{0,-25} {1}", prop.Name, prop.GetValue(info).ToString());
89 | sb.AppendLine();
90 | }
91 | }
92 | catch { }
93 | }
94 |
95 | return sb.ToString();
96 | }
97 |
98 | #endregion Private Methods
99 |
100 | #region Private Classes
101 |
102 | ///
103 | /// 初始化数据模板
104 | ///
105 | private class Init_DataTemplete
106 | {
107 | #region Public Fields
108 |
109 | public string appkey;
110 | public string appsecret;
111 | public string build;
112 | public string message;
113 | public string version;
114 |
115 | #endregion Public Fields
116 | }
117 |
118 | #endregion Private Classes
119 | }
120 | }
--------------------------------------------------------------------------------
/BiliAccount.TestProject/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("BiliAccount.TestProject")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("BiliAccount.TestProject")]
13 | [assembly: AssemblyCopyright("Copyright © 2019")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("f234c8f2-6623-4775-aaad-fae9ace77290")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
33 | //通过使用 "*",如下所示:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/BiliAccount.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29519.181
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BiliAccount", "BiliAccount\BiliAccount.csproj", "{051E5F22-F345-4871-9433-C586A0C6A968}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BiliAccount.TestProject", "BiliAccount.TestProject\BiliAccount.TestProject.csproj", "{F234C8F2-6623-4775-AAAD-FAE9ACE77290}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BiliAccount.Geetest.Controls", "BiliAccount.Geetest.Controls\BiliAccount.Geetest.Controls.csproj", "{D54053B7-5294-4468-ADC2-80E839434A3C}"
11 | ProjectSection(ProjectDependencies) = postProject
12 | {051E5F22-F345-4871-9433-C586A0C6A968} = {051E5F22-F345-4871-9433-C586A0C6A968}
13 | EndProjectSection
14 | EndProject
15 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BiliAccount.Geetest", "BiliAccount.Geetest\BiliAccount.Geetest.csproj", "{D50857E8-CD41-4049-B0E4-FE87CDF2CC88}"
16 | EndProject
17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BiliAccount.TestProject.WPF", "BiliAccount.TestProject.WPF\BiliAccount.TestProject.WPF.csproj", "{3168ACE0-0736-41E8-90CB-D368379200FF}"
18 | EndProject
19 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BiliAccount.Core31TestProject", "BiliAccount.Core31TestProject\BiliAccount.Core31TestProject.csproj", "{2B3E6CDE-29C6-4C68-A89B-AF035ED08843}"
20 | EndProject
21 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProjects", "{835C91CD-8388-45AA-B00E-03D82E72B198}"
22 | EndProject
23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BiliAccount.TestProject.Winforms", "BiliAccount.TestProject.Winforms\BiliAccount.TestProject.Winforms.csproj", "{198FAA7F-444F-4511-BB37-BE2F57079B45}"
24 | EndProject
25 | Global
26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
27 | Debug|Any CPU = Debug|Any CPU
28 | Debug|x64 = Debug|x64
29 | Debug|x86 = Debug|x86
30 | Release|Any CPU = Release|Any CPU
31 | Release|x64 = Release|x64
32 | Release|x86 = Release|x86
33 | EndGlobalSection
34 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
35 | {051E5F22-F345-4871-9433-C586A0C6A968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36 | {051E5F22-F345-4871-9433-C586A0C6A968}.Debug|Any CPU.Build.0 = Debug|Any CPU
37 | {051E5F22-F345-4871-9433-C586A0C6A968}.Debug|x64.ActiveCfg = Debug|Any CPU
38 | {051E5F22-F345-4871-9433-C586A0C6A968}.Debug|x64.Build.0 = Debug|Any CPU
39 | {051E5F22-F345-4871-9433-C586A0C6A968}.Debug|x86.ActiveCfg = Debug|Any CPU
40 | {051E5F22-F345-4871-9433-C586A0C6A968}.Debug|x86.Build.0 = Debug|Any CPU
41 | {051E5F22-F345-4871-9433-C586A0C6A968}.Release|Any CPU.ActiveCfg = Release|Any CPU
42 | {051E5F22-F345-4871-9433-C586A0C6A968}.Release|Any CPU.Build.0 = Release|Any CPU
43 | {051E5F22-F345-4871-9433-C586A0C6A968}.Release|x64.ActiveCfg = Release|Any CPU
44 | {051E5F22-F345-4871-9433-C586A0C6A968}.Release|x64.Build.0 = Release|Any CPU
45 | {051E5F22-F345-4871-9433-C586A0C6A968}.Release|x86.ActiveCfg = Release|Any CPU
46 | {051E5F22-F345-4871-9433-C586A0C6A968}.Release|x86.Build.0 = Release|Any CPU
47 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Debug|Any CPU.Build.0 = Debug|Any CPU
49 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Debug|x64.ActiveCfg = Debug|Any CPU
50 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Debug|x64.Build.0 = Debug|Any CPU
51 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Debug|x86.ActiveCfg = Debug|Any CPU
52 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Debug|x86.Build.0 = Debug|Any CPU
53 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Release|Any CPU.ActiveCfg = Release|Any CPU
54 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Release|Any CPU.Build.0 = Release|Any CPU
55 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Release|x64.ActiveCfg = Release|Any CPU
56 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Release|x64.Build.0 = Release|Any CPU
57 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Release|x86.ActiveCfg = Release|Any CPU
58 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290}.Release|x86.Build.0 = Release|Any CPU
59 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Debug|Any CPU.ActiveCfg = Debug|x86
60 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Debug|Any CPU.Build.0 = Debug|x86
61 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Debug|x64.ActiveCfg = Debug|x64
62 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Debug|x64.Build.0 = Debug|x64
63 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Debug|x86.ActiveCfg = Debug|x86
64 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Debug|x86.Build.0 = Debug|x86
65 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Release|Any CPU.ActiveCfg = Release|x86
66 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Release|x64.ActiveCfg = Release|x64
67 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Release|x64.Build.0 = Release|x64
68 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Release|x86.ActiveCfg = Release|x86
69 | {D54053B7-5294-4468-ADC2-80E839434A3C}.Release|x86.Build.0 = Release|x86
70 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
71 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Debug|Any CPU.Build.0 = Debug|Any CPU
72 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Debug|x64.ActiveCfg = Debug|Any CPU
73 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Debug|x64.Build.0 = Debug|Any CPU
74 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Debug|x86.ActiveCfg = Debug|Any CPU
75 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Debug|x86.Build.0 = Debug|Any CPU
76 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Release|Any CPU.ActiveCfg = Release|Any CPU
77 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Release|Any CPU.Build.0 = Release|Any CPU
78 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Release|x64.ActiveCfg = Release|Any CPU
79 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Release|x64.Build.0 = Release|Any CPU
80 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Release|x86.ActiveCfg = Release|Any CPU
81 | {D50857E8-CD41-4049-B0E4-FE87CDF2CC88}.Release|x86.Build.0 = Release|Any CPU
82 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
83 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
84 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Debug|x64.ActiveCfg = Debug|Any CPU
85 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Debug|x64.Build.0 = Debug|Any CPU
86 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Debug|x86.ActiveCfg = Debug|Any CPU
87 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Debug|x86.Build.0 = Debug|Any CPU
88 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
89 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Release|Any CPU.Build.0 = Release|Any CPU
90 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Release|x64.ActiveCfg = Release|Any CPU
91 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Release|x64.Build.0 = Release|Any CPU
92 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Release|x86.ActiveCfg = Release|Any CPU
93 | {3168ACE0-0736-41E8-90CB-D368379200FF}.Release|x86.Build.0 = Release|Any CPU
94 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
95 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Debug|Any CPU.Build.0 = Debug|Any CPU
96 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Debug|x64.ActiveCfg = Debug|Any CPU
97 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Debug|x64.Build.0 = Debug|Any CPU
98 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Debug|x86.ActiveCfg = Debug|Any CPU
99 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Debug|x86.Build.0 = Debug|Any CPU
100 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Release|Any CPU.ActiveCfg = Release|Any CPU
101 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Release|Any CPU.Build.0 = Release|Any CPU
102 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Release|x64.ActiveCfg = Release|Any CPU
103 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Release|x64.Build.0 = Release|Any CPU
104 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Release|x86.ActiveCfg = Release|Any CPU
105 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843}.Release|x86.Build.0 = Release|Any CPU
106 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
107 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Debug|Any CPU.Build.0 = Debug|Any CPU
108 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Debug|x64.ActiveCfg = Debug|Any CPU
109 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Debug|x64.Build.0 = Debug|Any CPU
110 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Debug|x86.ActiveCfg = Debug|Any CPU
111 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Debug|x86.Build.0 = Debug|Any CPU
112 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Release|Any CPU.ActiveCfg = Release|Any CPU
113 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Release|Any CPU.Build.0 = Release|Any CPU
114 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Release|x64.ActiveCfg = Release|Any CPU
115 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Release|x64.Build.0 = Release|Any CPU
116 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Release|x86.ActiveCfg = Release|Any CPU
117 | {198FAA7F-444F-4511-BB37-BE2F57079B45}.Release|x86.Build.0 = Release|Any CPU
118 | EndGlobalSection
119 | GlobalSection(SolutionProperties) = preSolution
120 | HideSolutionNode = FALSE
121 | EndGlobalSection
122 | GlobalSection(NestedProjects) = preSolution
123 | {F234C8F2-6623-4775-AAAD-FAE9ACE77290} = {835C91CD-8388-45AA-B00E-03D82E72B198}
124 | {3168ACE0-0736-41E8-90CB-D368379200FF} = {835C91CD-8388-45AA-B00E-03D82E72B198}
125 | {2B3E6CDE-29C6-4C68-A89B-AF035ED08843} = {835C91CD-8388-45AA-B00E-03D82E72B198}
126 | {198FAA7F-444F-4511-BB37-BE2F57079B45} = {835C91CD-8388-45AA-B00E-03D82E72B198}
127 | EndGlobalSection
128 | GlobalSection(ExtensibilityGlobals) = postSolution
129 | SolutionGuid = {7AC806D8-62E7-4DD4-A718-B51C638256FD}
130 | EndGlobalSection
131 | EndGlobal
132 |
--------------------------------------------------------------------------------
/BiliAccount/Account.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Net;
4 |
5 | namespace BiliAccount
6 | {
7 | ///
8 | /// 账号信息模板
9 | ///
10 | public class Account
11 | {
12 | #region Public Fields
13 |
14 | ///
15 | /// Access_Token(使用二维码登录时此项为空)
16 | ///
17 | public string AccessToken;
18 |
19 | ///
20 | /// Buvid/local_id
21 | ///
22 | public string Buvid;
23 |
24 | ///
25 | /// 验证码图片(仅当需要验证码验证时有值)
26 | ///
27 | public Bitmap CaptchaPic = null;
28 |
29 | ///
30 | /// Cookies集合实例
31 | ///
32 | public CookieCollection Cookies;
33 |
34 | ///
35 | /// csrf_token
36 | ///
37 | public string CsrfToken;
38 |
39 | ///
40 | /// 设备标识
41 | ///
42 | public string DeviceGuid;
43 |
44 | ///
45 | /// device_id/bili_local_id
46 | ///
47 | public string DeviceId;
48 |
49 | ///
50 | /// 加密过的密码(使用二维码登录时此项为空)
51 | ///
52 | public string EncryptedPassword;
53 |
54 | ///
55 | /// Access_Token有效期(使用二维码登录时此项为空)
56 | ///
57 | public DateTime Expires_AccessToken;
58 |
59 | ///
60 | /// Cookies有效期
61 | ///
62 | public DateTime Expires_Cookies;
63 |
64 | ///
65 | /// 指示是否登录成功
66 | ///
67 | public LoginStatusEnum LoginStatus = LoginStatusEnum.None;
68 |
69 | ///
70 | /// 密码(使用二维码登录时此项为空)
71 | ///
72 | public string Password;
73 |
74 | ///
75 | /// Refresh_Token(使用二维码登录时此项为空)
76 | ///
77 | public string RefreshToken;
78 |
79 | ///
80 | /// Cookies字符串
81 | ///
82 | public string strCookies;
83 |
84 | ///
85 | /// 手机号(仅当需要手机验证的时候有值)
86 | ///
87 | public string Tel;
88 |
89 | ///
90 | /// 用户数字id
91 | ///
92 | public string Uid;
93 |
94 | ///
95 | /// 手机验证链接(仅当需要手机验证的时候有值)
96 | ///
97 | public string Url;
98 |
99 | ///
100 | /// 用户名(使用二维码登录时此项为空)
101 | ///
102 | public string UserName;
103 |
104 | #endregion Public Fields
105 |
106 | #region Public Constructors
107 |
108 | ///
109 | /// 构造函数
110 | ///
111 | public Account()
112 | {
113 | Buvid = $"XZ{Guid.NewGuid().ToString("N")}{Guid.NewGuid().ToString("N").Substring(0, 4)}";
114 | DeviceId = $"{Guid.NewGuid().ToString("N")}{DateTime.Now.ToString("yyyyMMddHHmmssffff")}{Guid.NewGuid().ToString("N").Substring(0, 16)}";
115 | DeviceGuid = Guid.NewGuid().ToString("D");
116 | }
117 |
118 | #endregion Public Constructors
119 |
120 | #region Public Enums
121 |
122 | ///
123 | /// 登录状态枚举
124 | ///
125 | public enum LoginStatusEnum
126 | {
127 | ///
128 | /// 设备安全验证
129 | ///
130 | NeedSafeVerify = -4,
131 |
132 | ///
133 | /// 手机验证
134 | ///
135 | NeedTelVerify = -3,
136 |
137 | ///
138 | /// 图片验证码
139 | ///
140 | NeedCaptcha = -2,
141 |
142 | ///
143 | /// 密码错误
144 | ///
145 | WrongPassword = -1,
146 |
147 | ///
148 | /// 未登录
149 | ///
150 | None,
151 |
152 | ///
153 | /// 二维码登录
154 | ///
155 | ByQrCode,
156 |
157 | ///
158 | /// 密码登录
159 | ///
160 | ByPassword,
161 |
162 | ///
163 | /// 短信登录
164 | ///
165 | BySMS
166 | }
167 |
168 | #endregion Public Enums
169 | }
170 | }
--------------------------------------------------------------------------------
/BiliAccount/BiliAccount.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net48;net472;net471;net47;net462;net461;net46;net451;net452;net45;net40;net35;netstandard2.0;netstandard2.1;netcoreapp3.0;netcoreapp3.1
5 | $(LibraryFrameworks)
6 | BiliAccount
7 | true
8 | BiliAccount
9 | 2.5.5.27
10 | LeoChen
11 | zhangbudademao.com
12 | BiliAccount
13 | 用于处理B站账号类的操作
14 | Copyright © 2022 zhangbudademao.com, all rights reserved.
15 | MIT
16 | https://github.com/LeoChen98/BiliAccount
17 | https://github.com/LeoChen98/BiliAccount
18 | git
19 | bilibili bililive bililogin biliaccount
20 | favicon_4.png
21 |
22 | adds:
23 | 1. 新增 `Linq.ByQRCode.LoginByQrCodeUrl`。
24 | enhancements:
25 | 1. 更新引用库版本。
26 |
27 | true
28 | snupkg
29 | true
30 |
31 |
32 |
33 | BiliAccount
34 | NETFRAMEWORK;NET45;$(AdditionalConstants)
35 |
36 |
37 | BiliAccount .NET 4.5.1
38 | NETFRAMEWORK;NET451;$(AdditionalConstants)
39 |
40 |
41 | BiliAccount .NET 4.5.2
42 | NETFRAMEWORK;NET452;$(AdditionalConstants)
43 |
44 |
45 | BiliAccount .NET 4.6
46 | NETFRAMEWORK;NET46;$(AdditionalConstants)
47 |
48 |
49 | BiliAccount .NET 4.6.1
50 | NETFRAMEWORK;NET61;$(AdditionalConstants)
51 |
52 |
53 | BiliAccount .NET 4.6.2
54 | NETFRAMEWORK;NET462;$(AdditionalConstants)
55 |
56 |
57 | BiliAccount .NET 4.7
58 | NETFRAMEWORK;NET47;$(AdditionalConstants)
59 |
60 |
61 | BiliAccount .NET 4.7.1
62 | NETFRAMEWORK;NET471;$(AdditionalConstants)
63 |
64 |
65 | BiliAccount .NET 4.7.2
66 | NETFRAMEWORK;NET472;$(AdditionalConstants)
67 |
68 |
69 | BiliAccount .NET 4.8
70 | NETFRAMEWORK;NET48;$(AdditionalConstants)
71 |
72 |
73 | BiliAccount .NET 4.0
74 | NETFRAMEWORK;NET40;$(AdditionalConstants)
75 |
76 |
77 | BiliAccount .NET 3.5
78 | NETFRAMEWORK;NET35;$(AdditionalConstants)
79 |
80 |
81 | BiliAccount .NET Standard 2.0
82 | NETSTANDARD2_0;$(AdditionalConstants)
83 |
84 |
85 | BiliAccount .NET Standard 2.1
86 | NETSTANDARD2_0;$(AdditionalConstants)
87 |
88 |
89 | BiliAccount .NET Core 3.0
90 | NETCORE3_0;$(AdditionalConstants)
91 |
92 |
93 | BiliAccount .NET Core 3.1
94 | NETCORE3_0;$(AdditionalConstants)
95 |
96 |
97 |
98 | none
99 | false
100 | Auto
101 |
102 |
103 |
104 | 1701;1702;NETSDK1138
105 |
106 |
107 |
108 | 1701;1702;NETSDK1138
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 | True
132 |
133 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/BiliAccount/Core/BySMS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 | using System.Reflection;
4 | using System.Security.Cryptography;
5 | using System.Text;
6 |
7 | #if NETSTANDARD2_0 || NETCORE3_0
8 | using Newtonsoft.Json;
9 | #else
10 |
11 | using System.Web.Script.Serialization;
12 |
13 | #endif
14 |
15 | #pragma warning disable CS0649
16 |
17 | namespace BiliAccount.Core
18 | {
19 | ///
20 | /// 通过手机验证码登录
21 | ///
22 | internal class BySMS
23 | {
24 | #region Private Properties
25 |
26 | ///
27 | /// Unix时间戳
28 | ///
29 | private static long TimeStamp
30 | {
31 | get
32 | {
33 | return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
34 | }
35 | }
36 |
37 | #endregion Private Properties
38 |
39 | #region Public Methods
40 |
41 | ///
42 | /// 登录
43 | ///
44 | /// captcha_key
45 | /// 验证码
46 | /// 手机号
47 | /// 账号实例
48 | public static Account Login(string captcha_key, string code, string tel)
49 | {
50 | Account account = new Account();
51 | string param = $"appkey={Config.Instance.Appkey}&bili_local_id={account.DeviceId}&build={Config.Instance.Build}&buvid={account.Buvid}&captcha_key={captcha_key}&channel=bili&cid=86&code={code}&device=phone&device_id={account.DeviceId}&device_name=BiliAccount{account.DeviceGuid}&device_platform=BiliAccount{Config.Dll_Version}&local_id={account.Buvid}&mobi_app=android&platform=android&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%22{Config.Instance.Version}%22%2C%22abtest%22%3A%22%22%7D&tel={tel}&ts={TimeStamp}";
52 | param += $"&sign={GetSign(param)}";
53 |
54 | string str = Http.PostBody("https://passport.bilibili.com/x/passport-login/login/sms", param,null, $"BiliAccount/{Config.Dll_Version}");
55 | #if NETSTANDARD2_0 || NETCORE3_0
56 | Login_DataTemplete obj = JsonConvert.DeserializeObject(str);
57 | #else
58 | Login_DataTemplete obj = (new JavaScriptSerializer()).Deserialize(str);
59 | #endif
60 | if (obj.code == 0)
61 | {
62 | account.Uid = obj.data.token_info.mid;
63 | account.AccessToken = obj.data.token_info.access_token;
64 | account.RefreshToken = obj.data.token_info.refresh_token;
65 | account.Expires_AccessToken = DateTime.Now.AddSeconds(obj.data.token_info.expires_in);
66 |
67 | account.Cookies = new CookieCollection();
68 | foreach (Login_DataTemplete.Data_Templete.Cookie_Info_Templete.Cookie_Templete i in obj.data.cookie_info.cookies)
69 | {
70 | account.strCookies += i.name + "=" + i.value + "; ";
71 | account.Cookies.Add(new Cookie(i.name, i.value) { Domain = ".bilibili.com" });
72 | account.Expires_Cookies = DateTime.Parse("1970-01-01 08:00:00").AddSeconds(i.expires);
73 |
74 | if (i.name == "bili_jct")
75 | account.CsrfToken = i.value;
76 | }
77 | account.strCookies = account.strCookies.Substring(0, account.strCookies.Length - 2);
78 | account.LoginStatus = Account.LoginStatusEnum.BySMS;
79 | return account;
80 | }
81 | else
82 | throw new SMS_Login_Exception(obj.code, obj.message);
83 | }
84 |
85 | ///
86 | /// 发送验证码
87 | ///
88 | /// captcha_key
89 | ///
90 | ///
91 | public static string SMS_Send(string tel)
92 | {
93 | string param = $"appkey={Config.Instance.Appkey}&build={Config.Instance.Build}&channel=bili&cid=86&mobi_app=android&platform=android&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%22{Config.Instance.Version}%22%2C%22abtest%22%3A%22%22%7D&tel={tel}&ts={TimeStamp}";
94 | param += $"&sign={GetSign(param)}";
95 | string str = Http.PostBody("https://passport.bilibili.com/x/passport-login/sms/send", param,null, $"BiliAccount/{Config.Dll_Version}");
96 | #if NETSTANDARD2_0 || NETCORE3_0
97 | SMS_Send_DataTemplete obj = JsonConvert.DeserializeObject(str);
98 | #else
99 | SMS_Send_DataTemplete obj = (new JavaScriptSerializer()).Deserialize(str);
100 | #endif
101 | if (obj.code == 0)
102 | {
103 | if (string.IsNullOrEmpty(obj.data.recaptcha_url))
104 | return obj.data.captcha_key;
105 | else
106 | throw new Exceptions.SMS_NeedGeetest_Exception(obj.data.recaptcha_url);
107 | }
108 | else
109 | throw new Exceptions.SMS_Send_Exception(obj.code, obj.message);
110 | }
111 |
112 | #endregion Public Methods
113 |
114 | #region Private Methods
115 |
116 | ///
117 | /// 获取字符串md5
118 | ///
119 | /// 文本
120 | /// md5
121 | private static string GetMD5(string str)
122 | {
123 | try
124 | {
125 | MD5 md5 = new MD5CryptoServiceProvider();
126 | byte[] retVal = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
127 |
128 | StringBuilder sb = new StringBuilder();
129 | for (int i = 0; i < retVal.Length; i++)
130 | {
131 | sb.Append(retVal[i].ToString("x2"));
132 | }
133 | return sb.ToString();
134 | }
135 | catch
136 | {
137 | return "";
138 | }
139 | }
140 |
141 | ///
142 | /// 获取参数签名
143 | ///
144 | /// 请求参数
145 | /// 签名
146 | private static string GetSign(string strReq)
147 | {
148 | return GetMD5(strReq + Config.Instance.Appsecret);
149 | }
150 |
151 | #endregion Private Methods
152 |
153 | #region Public Classes
154 |
155 | ///
156 | /// 登录错误
157 | ///
158 | public class SMS_Login_Exception : Exception
159 | {
160 | #region Public Fields
161 |
162 | public int code;
163 |
164 | #endregion Public Fields
165 |
166 | #region Public Constructors
167 |
168 | public SMS_Login_Exception(int code, string message) : base(message)
169 | {
170 | this.code = code;
171 | }
172 |
173 | #endregion Public Constructors
174 | }
175 |
176 | #endregion Public Classes
177 |
178 | #region Private Classes
179 |
180 | ///
181 | /// 登录数据模板
182 | ///
183 | private class Login_DataTemplete
184 | {
185 | #region Public Fields
186 |
187 | public int code;
188 | public Data_Templete data;
189 | public string message;
190 | public long ts;
191 |
192 | #endregion Public Fields
193 |
194 | #region Public Classes
195 |
196 | public class Data_Templete
197 | {
198 | #region Public Fields
199 |
200 | public Cookie_Info_Templete cookie_info;
201 | public Token_Info_Templete token_info;
202 |
203 | #endregion Public Fields
204 |
205 | #region Public Classes
206 |
207 | public class Cookie_Info_Templete
208 | {
209 | #region Public Fields
210 |
211 | public Cookie_Templete[] cookies;
212 |
213 | #endregion Public Fields
214 |
215 | #region Public Classes
216 |
217 | public class Cookie_Templete
218 | {
219 | #region Public Fields
220 |
221 | public long expires;
222 | public string name;
223 | public string value;
224 |
225 | #endregion Public Fields
226 | }
227 |
228 | #endregion Public Classes
229 | }
230 |
231 | public class Token_Info_Templete
232 | {
233 | #region Public Fields
234 |
235 | public string access_token;
236 | public long expires_in;
237 | public string mid;
238 | public string refresh_token;
239 |
240 | #endregion Public Fields
241 | }
242 |
243 | #endregion Public Classes
244 | }
245 |
246 | #endregion Public Classes
247 | }
248 |
249 | ///
250 | /// 发送短信返回数据模板
251 | ///
252 | private class SMS_Send_DataTemplete
253 | {
254 | #region Public Fields
255 |
256 | public int code;
257 | public Data data;
258 | public string message;
259 |
260 | #endregion Public Fields
261 |
262 | #region Public Classes
263 |
264 | public class Data
265 | {
266 | #region Public Fields
267 |
268 | public string captcha_key;
269 | public string recaptcha_url;
270 |
271 | #endregion Public Fields
272 | }
273 |
274 | #endregion Public Classes
275 | }
276 |
277 | #endregion Private Classes
278 | }
279 | }
--------------------------------------------------------------------------------
/BiliAccount/Core/Config.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | #if NETSTANDARD2_0 || NETCORE3_0
5 | using Newtonsoft.Json;
6 | #else
7 | using System.Web.Script.Serialization;
8 | #endif
9 |
10 | #pragma warning disable CS0649
11 |
12 | namespace BiliAccount.Core
13 | {
14 | internal class Config
15 | {
16 | #region Private Fields
17 |
18 | private static Config instance;
19 |
20 | ///
21 | /// 后端配置文件地址(如非必要请勿修改)
22 | ///
23 | private const string init_url = "http://ctrl.zhangbudademao.com/118/Init.json";
24 |
25 | #endregion Private Fields
26 |
27 | ///
28 | /// 当前程序集版本号
29 | ///
30 | public static string Dll_Version
31 | {
32 | get
33 | {
34 | return Assembly.GetExecutingAssembly().GetName().Version.ToString();
35 | }
36 | }
37 |
38 | #region Private Constructors
39 |
40 | ///
41 | /// 初始化登录模块
42 | ///
43 | private Config()
44 | {
45 | string str = Http.GetBody($"{init_url}");
46 |
47 | if (!string.IsNullOrEmpty(str))
48 | {
49 | #if NETSTANDARD2_0 || NETCORE3_0
50 | Init_DataTemplete obj = JsonConvert.DeserializeObject(str);
51 | #else
52 | Init_DataTemplete obj = (new JavaScriptSerializer()).Deserialize(str);
53 | #endif
54 | Appkey = obj.appkey;
55 | Appsecret = obj.appsecret;
56 | Build = obj.build;
57 | Version = obj.version;
58 | IsInited = true;
59 | }
60 | }
61 |
62 | ///
63 | /// 初始化登录模块(DEBUG Mode)
64 | ///
65 | private Config(string str)
66 | {
67 | if (!string.IsNullOrEmpty(str))
68 | {
69 | #if NETSTANDARD2_0 || NETCORE3_0
70 | Init_DataTemplete obj = JsonConvert.DeserializeObject(str);
71 | #else
72 | Init_DataTemplete obj = (new JavaScriptSerializer()).Deserialize(str);
73 | #endif
74 | Appkey = obj.appkey;
75 | Appsecret = obj.appsecret;
76 | Build = obj.build;
77 | Version = obj.version;
78 | IsInited = true;
79 | }
80 | }
81 |
82 | #endregion Private Constructors
83 |
84 | #region Public Properties
85 |
86 | ///
87 | /// 单例接口
88 | ///
89 | public static Config Instance
90 | {
91 | get
92 | {
93 | if (instance == null) instance = new Config();
94 | return instance;
95 | }
96 | }
97 |
98 | ///
99 | /// Appkey
100 | ///
101 | public string Appkey { get; private set; } = "bca7e84c2d947ac6";
102 |
103 | ///
104 | /// AppSecret
105 | ///
106 | public string Appsecret { get; private set; } = "60698ba2f68e01ce44738920a0ffe768";
107 |
108 | ///
109 | /// Build
110 | ///
111 | public string Build { get; private set; } = "5572000";
112 |
113 | ///
114 | /// 指示是否已经初始化
115 | ///
116 | public bool IsInited { get; private set; } = false;
117 |
118 | ///
119 | /// UA
120 | ///
121 | public string User_Agent
122 | {
123 | get
124 | {
125 | return $"Mozilla/5.0 BiliDroid/{Version} (bbcallen@gmail.com) os/android model/MI 9 mobi_app/android build/{Build} channel/master innerVer/{Build} osVer/10 network/2";
126 | }
127 | }
128 |
129 | ///
130 | /// 版本号
131 | ///
132 | public string Version { get; private set; } = "5.57.2";
133 |
134 | #endregion Public Properties
135 |
136 | #region Private Classes
137 |
138 | ///
139 | /// 初始化数据模板
140 | ///
141 | private class Init_DataTemplete
142 | {
143 | #region Public Fields
144 |
145 | public string appkey;
146 | public string appsecret;
147 | public string build;
148 | public string version;
149 |
150 | #endregion Public Fields
151 | }
152 |
153 | #endregion Private Classes
154 | }
155 | }
--------------------------------------------------------------------------------
/BiliAccount/Exceptions/GetAccount_Exception.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BiliAccount.Exceptions
4 | {
5 | ///
6 | /// 获取登录账号信息错误
7 | ///
8 | public class GetAccount_Exception : Exception
9 | {
10 | #region Public Fields
11 |
12 | public int code;
13 |
14 | #endregion Public Fields
15 |
16 | #region Public Constructors
17 |
18 | public GetAccount_Exception(int code, string message) : base(message)
19 | {
20 | this.code = code;
21 | }
22 |
23 | #endregion Public Constructors
24 | }
25 | }
--------------------------------------------------------------------------------
/BiliAccount/Exceptions/InvalidColorValue.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BiliAccount.Exceptions
4 | {
5 | ///
6 | /// 传入了错误的颜色值
7 | ///
8 | public class InvalidColorValue : Exception
9 | {
10 | #region Public Constructors
11 |
12 | ///
13 | /// 以指定的属性名初始化
14 | ///
15 | /// 属性名
16 | public InvalidColorValue(string name) : base($"传入了错误的颜色值!{name}")
17 | {
18 | PropertyName = name;
19 | }
20 |
21 | #endregion Public Constructors
22 |
23 | #region Public Properties
24 |
25 | ///
26 | /// 错误的属性名
27 | ///
28 | public string PropertyName { get; private set; }
29 |
30 | #endregion Public Properties
31 | }
32 | }
--------------------------------------------------------------------------------
/BiliAccount/Exceptions/Revoke_Exception.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | #pragma warning disable CS1591
4 |
5 | namespace BiliAccount.Exceptions
6 | {
7 | ///
8 | /// 注销错误
9 | ///
10 | public class Revoke_Exception : Exception
11 | {
12 | #region Public Constructors
13 |
14 | public Revoke_Exception(int code, string message) : base(message)
15 | {
16 | this.code = code;
17 | }
18 |
19 | #endregion Public Constructors
20 |
21 | #region Public Properties
22 |
23 | public int code { get; private set; }
24 |
25 | #endregion Public Properties
26 | }
27 | }
--------------------------------------------------------------------------------
/BiliAccount/Exceptions/SMS_NeedGeetest_Exception.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BiliAccount.Exceptions
4 | {
5 | ///
6 | /// 发送短信需要极验验证时引发的错误
7 | ///
8 | public class SMS_NeedGeetest_Exception : Exception
9 | {
10 | #region Public Constructors
11 |
12 | ///
13 | /// 构造函数
14 | ///
15 | /// 校验弹窗地址
16 | public SMS_NeedGeetest_Exception(string recaptcha_url) : base("需要极验校验!")
17 | {
18 | url = recaptcha_url;
19 | }
20 |
21 | #endregion Public Constructors
22 |
23 | #region Public Properties
24 |
25 | ///
26 | /// 校验弹窗地址
27 | ///
28 | public string url { get; private set; }
29 |
30 | #endregion Public Properties
31 | }
32 | }
--------------------------------------------------------------------------------
/BiliAccount/Exceptions/SMS_Send_Exception.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BiliAccount.Exceptions
4 | {
5 | #pragma warning disable CS1591
6 |
7 | ///
8 | /// 发送验证码信息错误
9 | ///
10 | public class SMS_Send_Exception : Exception
11 | {
12 | #region Public Constructors
13 |
14 | public SMS_Send_Exception(int code, string message) : base(message)
15 | {
16 | this.code = code;
17 | }
18 |
19 | #endregion Public Constructors
20 |
21 | #region Public Properties
22 |
23 | public int code { get; private set; }
24 |
25 | #endregion Public Properties
26 | }
27 | }
--------------------------------------------------------------------------------
/BiliAccount/Exceptions/Verify_Exception.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BiliAccount.Exceptions
4 | {
5 | ///
6 | /// 设备验证错误
7 | ///
8 | public class Verify_Exception : Exception
9 | {
10 | #region Public Fields
11 |
12 | public int code;
13 |
14 | #endregion Public Fields
15 |
16 | #region Public Constructors
17 |
18 | public Verify_Exception(int code, string message) : base(message)
19 | {
20 | this.code = code;
21 | }
22 |
23 | #endregion Public Constructors
24 | }
25 | }
--------------------------------------------------------------------------------
/BiliAccount/Framework4.0Methods/Stream4Methods.cs:
--------------------------------------------------------------------------------
1 | namespace BiliAccount
2 | {
3 | internal class Stream4Methods
4 | {
5 | #region Public Methods
6 |
7 | public static void CopyTo(System.IO.Stream input, System.IO.Stream output)
8 | {
9 | byte[] buffer = new byte[16 * 1024];
10 | int bytesRead;
11 | while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
12 | {
13 | output.Write(buffer, 0, bytesRead);
14 | }
15 | }
16 |
17 | #endregion Public Methods
18 | }
19 | }
--------------------------------------------------------------------------------
/BiliAccount/Framework4.0Methods/String4Methods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BiliAccount
4 | {
5 | internal static class String40Methods
6 | {
7 | #region Public Methods
8 |
9 | public static bool IsAllDigit(string str)
10 | {
11 | foreach (var c in str)
12 | {
13 | if (!char.IsDigit(c))
14 | {
15 | return false;
16 | }
17 | }
18 | return true;
19 | }
20 |
21 | ///
22 | /// The IsNullOrWhiteSpace method from Framework4.0
23 | ///
24 | ///
25 | /// true if the is null or white space; otherwise, false.
26 | ///
27 | public static bool IsNullOrWhiteSpace(String value)
28 | {
29 | if (value == null) return true;
30 |
31 | for (int i = 0; i < value.Length; i++)
32 | {
33 | if (!Char.IsWhiteSpace(value[i])) return false;
34 | }
35 |
36 | return true;
37 | }
38 |
39 | public static string ReverseString(string str)
40 | {
41 | char[] chars = str.ToCharArray();
42 | char[] result = new char[chars.Length];
43 | for (int i = 0, j = str.Length - 1; i < str.Length; i++, j--)
44 | {
45 | result[i] = chars[j];
46 | }
47 | return new string(result);
48 | }
49 |
50 | #endregion Public Methods
51 | }
52 | }
--------------------------------------------------------------------------------
/BiliAccount/Init.json:
--------------------------------------------------------------------------------
1 | {
2 | "appkey": "bca7e84c2d947ac6",
3 | "appsecret": "60698ba2f68e01ce44738920a0ffe768",
4 | "build": "6200400",
5 | "version": "6.20.0",
6 | "user_agent": "Mozilla/5.0 BiliDroid/6.20.0(bbcallen@gmail.com) os/android model/MI 9 mobi_app/android build/6200400 channel/master innerVer/6200400 osVer/10 network/2"
7 | }
--------------------------------------------------------------------------------
/BiliAccount/Linq/ByPassword.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | #pragma warning disable CS0618
4 |
5 | namespace BiliAccount.Linq
6 | {
7 | ///
8 | /// 账号密码登录模式
9 | ///
10 | public partial class ByPassword
11 | {
12 | #region Public Methods
13 |
14 | ///
15 | /// 检查token可用性
16 | ///
17 | /// token
18 | /// 是否可用
19 | public static bool IsTokenAvailable(string access_token)
20 | {
21 | return Core.ByPassword.IsTokenAvailable(access_token);
22 | }
23 |
24 | ///
25 | /// 用账号密码登录
26 | ///
27 | /// 用户名(邮箱/手机)
28 | /// 密码(明文)
29 | /// 账号信息实例
30 | public static Account LoginByPassword(string username, string password)
31 | {
32 | Account account = new Account()
33 | {
34 | UserName = username,
35 | Password = password
36 | };
37 | Core.ByPassword.GetKey(out string hash, out string key, out account.Cookies);
38 | account.EncryptedPassword = Core.ByPassword.EncryptPwd(password, key, hash);
39 | Core.ByPassword.DoLogin(ref account);
40 | return account;
41 | }
42 |
43 | ///
44 | /// 登录(带验证码。在当前版本api中已鲜见图片验证码,该方法已弃用。)
45 | ///
46 | /// 验证码字符
47 | /// 账号实例
48 | [Obsolete("在当前版本api中已鲜见图片验证码,该方法已弃用。")]
49 | public static void LoginByPasswordWithCaptcha(string Captcha, ref Account account)
50 | {
51 | Core.ByPassword.DoLoginWithCatpcha(Captcha, ref account);
52 | }
53 |
54 | ///
55 | /// token续期
56 | ///
57 | ///
58 | ///
59 | /// 到期时间
60 | public static DateTime? RefreshToken(string access_token, string refresh_token)
61 | {
62 | return Core.ByPassword.RefreshToken(access_token, refresh_token);
63 | }
64 |
65 | ///
66 | /// 注销登录
67 | ///
68 | /// 账号实例
69 | ///
70 | public static void Revoke(ref Account account)
71 | {
72 | Core.ByPassword.Revoke(ref account);
73 | }
74 |
75 | ///
76 | /// SSO
77 | ///
78 | ///
79 | /// [0]=>(string)strCookies,[1]=>(string)csrf_token,[2]=>(DateTime)Expiress,[3]=>(CookieCollection)Cookies
80 | public static object[] SSO(string access_token)
81 | {
82 | return Core.ByPassword.SSO(access_token);
83 | }
84 |
85 | #endregion Public Methods
86 | }
87 | }
--------------------------------------------------------------------------------
/BiliAccount/Linq/ByQRCode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Text.RegularExpressions;
4 |
5 | #if NETFRAMEWORK
6 |
7 | using System.Windows;
8 |
9 | #endif
10 |
11 | #if !NETSTANDARD2_0 && !NETCORE3_0
12 |
13 | using System.Windows.Media;
14 | using System.Windows.Media.Imaging;
15 |
16 | #endif
17 |
18 | namespace BiliAccount.Linq
19 | {
20 | ///
21 | /// 二维码登录
22 | ///
23 | public class ByQRCode
24 | {
25 | #region Public Delegates
26 |
27 | ///
28 | /// 二维码刷新处理程序
29 | ///
30 | /// 新二维码
31 | public delegate void QrCodeRefresh_Handle(Bitmap newQrCode);
32 |
33 | ///
34 | /// 二维码刷新处理程序(仅登录url)
35 | ///
36 | /// 新二维码
37 | public delegate void QrCodeUrlRefresh_Handle(string newQrCodeUrl);
38 |
39 | ///
40 | /// 二维码登录状态变更处理程序
41 | ///
42 | /// 二维码状态
43 | /// 登录成功时有值,账号信息实例
44 | public delegate void QrCodeStatus_Changed_Handle(QrCodeStatus status, Account account = null);
45 |
46 | #endregion Public Delegates
47 |
48 | #region Public Events
49 |
50 | ///
51 | /// 二维码刷新事件
52 | ///
53 | public static event QrCodeRefresh_Handle QrCodeRefresh;
54 |
55 | ///
56 | /// 登录Url刷新事件
57 | ///
58 | public static event QrCodeUrlRefresh_Handle QrCodeUrlRefresh;
59 |
60 | ///
61 | /// 二维码登录状态变更事件
62 | ///
63 | public static event QrCodeStatus_Changed_Handle QrCodeStatus_Changed;
64 |
65 | #endregion Public Events
66 |
67 | #region Public Enums
68 |
69 | ///
70 | /// 二维码登录状态枚举
71 | ///
72 | public enum QrCodeStatus
73 | {
74 | #region Public Fields
75 |
76 | ///
77 | /// 等待扫描
78 | ///
79 | Wating,
80 |
81 | ///
82 | /// 等待确认
83 | ///
84 | Scaned,
85 |
86 | ///
87 | /// 登录成功
88 | ///
89 | Success
90 |
91 | #endregion Public Fields
92 | }
93 |
94 | #endregion Public Enums
95 |
96 | #region Public Methods
97 |
98 | ///
99 | /// 取消登录
100 | ///
101 | public static void CancelLogin()
102 | {
103 | Core.ByQRCode.CancelLogin();
104 | }
105 |
106 | #if !NETSTANDARD2_0 && !NETCORE3_0
107 |
108 | ///
109 | /// 删除对象
110 | ///
111 | /// 对象指针
112 | ///
113 | [System.Runtime.InteropServices.DllImport("gdi32.dll")]
114 | public static extern bool DeleteObject(IntPtr hObject);
115 |
116 | ///
117 | /// 获取WPF显示用的ImageSource
118 | ///
119 | /// 二维码图片Bitmap
120 | /// ImageSource
121 | public static ImageSource GetQrCodeImageSource(Bitmap qrCodeImage)
122 | {
123 | IntPtr myImagePtr = qrCodeImage.GetHbitmap(); //创建GDI对象,返回指针
124 |
125 | BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); //创建imgSource
126 |
127 | DeleteObject(myImagePtr);
128 |
129 | return imgsource;
130 | }
131 |
132 | #endif
133 |
134 | ///
135 | /// 获取登录Url
136 | ///
137 | /// 登录Url
138 | /// 传入了错误的颜色值
139 | public static string LoginByQrCodeUrl()
140 | {
141 | return Core.ByQRCode.GetQrcode();
142 | }
143 |
144 | ///
145 | /// 获取二维码
146 | ///
147 | /// 前景颜色
148 | /// 背景颜色
149 | /// 是否使用边框
150 | /// 二维码位图
151 | /// 传入了错误的颜色值
152 | public static Bitmap LoginByQrCode(string strForeground = "#FF000000", string strBackground = "#FFFFFFFF", bool IsBorderVisable = false)
153 | {
154 | Regex reg = new Regex("#[0-9A-Fa-f]{6,8}");
155 | if (reg.IsMatch(strForeground) && reg.IsMatch(strBackground))
156 | return LoginByQrCode(ColorTranslator.FromHtml(strForeground), ColorTranslator.FromHtml(strBackground), IsBorderVisable);
157 | else if (!reg.IsMatch(strForeground))
158 | throw new Exceptions.InvalidColorValue("strForeground");
159 | else
160 | throw new Exceptions.InvalidColorValue("strBackground");
161 | }
162 |
163 | ///
164 | /// 获取二维码
165 | ///
166 | /// 前景颜色
167 | /// 背景颜色
168 | /// 是否使用边框
169 | /// 二维码位图
170 | /// 传入了错误的颜色值
171 | public static Bitmap LoginByQrCode(System.Drawing.Color Foreground, System.Drawing.Color Background, bool IsBorderVisable = false)
172 | {
173 | if (Foreground != Background)
174 | return Core.ByQRCode.GetQrcode(Foreground, Background, IsBorderVisable);
175 | else
176 | throw new Exceptions.InvalidColorValue("strForeground and strBackground can not be same!");
177 | }
178 |
179 | #endregion Public Methods
180 |
181 | #region Internal Methods
182 |
183 | ///
184 | /// 调起二维码刷新
185 | ///
186 | /// 新二维码
187 | internal static void RaiseQrCodeRefresh(Bitmap newQrCode)
188 | {
189 | QrCodeRefresh?.Invoke(newQrCode);
190 | }
191 |
192 | ///
193 | /// 调起二维码刷新
194 | ///
195 | /// 新二维码
196 | internal static void RaiseQrCodeRefresh(string newQrCodeUrl)
197 | {
198 | QrCodeUrlRefresh?.Invoke(newQrCodeUrl);
199 | }
200 |
201 | ///
202 | /// 调起二维码登录状态变更
203 | ///
204 | /// 二维码状态
205 | /// 登录成功时有值,账号信息实例
206 | internal static void RaiseQrCodeStatus_Changed(QrCodeStatus status, Account account = null)
207 | {
208 | QrCodeStatus_Changed?.Invoke(status, account);
209 | }
210 |
211 | #endregion Internal Methods
212 | }
213 | }
--------------------------------------------------------------------------------
/BiliAccount/Linq/BySMS.cs:
--------------------------------------------------------------------------------
1 | namespace BiliAccount.Linq
2 | {
3 | ///
4 | /// 短信登录
5 | ///
6 | public partial class BySMS
7 | {
8 | #region Private Fields
9 |
10 | private static string captcha_key;
11 |
12 | #endregion Private Fields
13 |
14 | #region Public Methods
15 |
16 | ///
17 | /// 登录
18 | ///
19 | /// 短信验证码
20 | /// 电话号码
21 | /// 账号实例
22 | ///
23 | public static Account Login(string code, string tel)
24 | {
25 | return Core.BySMS.Login(captcha_key, code, tel);
26 | }
27 |
28 | ///
29 | /// 发送验证短信
30 | ///
31 | /// 电话号码
32 | ///
33 | public static void SendSMS(string tel)
34 | {
35 | captcha_key = Core.BySMS.SMS_Send(tel);
36 | }
37 |
38 | #endregion Public Methods
39 | }
40 | }
--------------------------------------------------------------------------------
/BiliAccount/Linq/Device_Verify.cs:
--------------------------------------------------------------------------------
1 | using System.Text.RegularExpressions;
2 |
3 | namespace BiliAccount.Linq
4 | {
5 | ///
6 | /// 设备验证类
7 | ///
8 | public class Device_Verify
9 | {
10 | #region Public Methods
11 |
12 | ///
13 | /// 获取账号信息
14 | ///
15 | /// 验证后返回的code
16 | /// 账号实例
17 | ///
18 | public static void GetAccount(string code, ref Account account)
19 | {
20 | Core.Device_Verify.GetAccount(code, ref account);
21 | }
22 |
23 | ///
24 | /// 发送短信
25 | ///
26 | /// challenge
27 | /// key
28 | /// tmp_token
29 | /// validate
30 | ///
31 | public static void Send_SMS(string challenge, string key, string tmp_token, string validate)
32 | {
33 | Core.Device_Verify.SMS_Send(challenge, key, tmp_token, validate);
34 | }
35 |
36 | ///
37 | /// 从验证url获取tmp_token
38 | ///
39 | /// 验证url
40 | /// tmp_token
41 | public static string Url2TmpToken(string url)
42 | {
43 | Regex reg = new Regex("tmp_token=(.+?)(&|$)");
44 | return reg.Match(url).Groups[1].Value;
45 | }
46 |
47 | ///
48 | /// 单纯的设备验证
49 | ///
50 | /// 手机验证码
51 | /// tmp_token
52 | /// 验证后返回的code
53 | ///
54 | public static string Verify(string code, string tmp_token)
55 | {
56 | return Core.Device_Verify.Verify(code, tmp_token);
57 | }
58 |
59 | ///
60 | /// 返回账号信息的设备验证
61 | ///
62 | /// 手机验证码
63 | /// tmp_token
64 | /// 账号实例
65 | ///
66 | public static void Verify(string code, string tmp_token, ref Account account)
67 | {
68 | Core.Device_Verify.GetAccount(Core.Device_Verify.Verify(code, tmp_token), ref account);
69 | }
70 |
71 | #endregion Public Methods
72 | }
73 | }
--------------------------------------------------------------------------------
/BiliAccount/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "TestProject": {
4 | "commandName": "Executable"
5 | }
6 | }
7 | }
--------------------------------------------------------------------------------
/BiliAccount/QRCode/AbstractQRCode.cs:
--------------------------------------------------------------------------------
1 | #if !NETSTANDARD2_0 && !NETCORE3_0
2 |
3 | namespace BiliAccount
4 | {
5 | #pragma warning disable CS1591
6 |
7 | internal abstract class AbstractQRCode
8 | {
9 | #region Protected Constructors
10 |
11 | protected AbstractQRCode()
12 | {
13 | }
14 |
15 | protected AbstractQRCode(QRCodeData data)
16 | {
17 | this.QrCodeData = data;
18 | }
19 |
20 | #endregion Protected Constructors
21 |
22 | #region Protected Properties
23 |
24 | protected QRCodeData QrCodeData { get; set; }
25 |
26 | #endregion Protected Properties
27 |
28 | #region Public Methods
29 |
30 | public void Dispose()
31 | {
32 | this.QrCodeData = null;
33 | }
34 |
35 | ///
36 | /// Set a QRCodeData object that will be used to generate QR code. Used in COM Objects connections
37 | ///
38 | /// Need a QRCodeData object generated by QRCodeGenerator.CreateQrCode()
39 | virtual public void SetQRCodeData(QRCodeData data)
40 | {
41 | this.QrCodeData = data;
42 | }
43 |
44 | #endregion Public Methods
45 | }
46 | }
47 |
48 | #endif
--------------------------------------------------------------------------------
/BiliAccount/QRCode/QRCode.cs:
--------------------------------------------------------------------------------
1 | #if !NETSTANDARD2_0 && !NETCORE3_0
2 | using System.Drawing;
3 | using System.Drawing.Drawing2D;
4 |
5 |
6 | namespace BiliAccount
7 | {
8 | #pragma warning disable CS1591
9 | using System;
10 |
11 | internal class QRCode : AbstractQRCode, IDisposable
12 | {
13 | #region Public Constructors
14 |
15 | ///
16 | /// Constructor without params to be used in COM Objects connections
17 | ///
18 | public QRCode() { }
19 |
20 | public QRCode(QRCodeData data) : base(data)
21 | {
22 | }
23 |
24 | #endregion Public Constructors
25 |
26 | #region Public Methods
27 |
28 | public Bitmap GetGraphic(int pixelsPerModule)
29 | {
30 | return this.GetGraphic(pixelsPerModule, Color.Black, Color.White, true);
31 | }
32 |
33 | public Bitmap GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true)
34 | {
35 | return this.GetGraphic(pixelsPerModule, ColorTranslator.FromHtml(darkColorHtmlHex), ColorTranslator.FromHtml(lightColorHtmlHex), drawQuietZones);
36 | }
37 |
38 | public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true)
39 | {
40 | var size = (this.QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8)) * pixelsPerModule;
41 | var offset = drawQuietZones ? 0 : 4 * pixelsPerModule;
42 |
43 | var bmp = new Bitmap(size, size);
44 | var gfx = Graphics.FromImage(bmp);
45 | for (var x = 0; x < size + offset; x = x + pixelsPerModule)
46 | {
47 | for (var y = 0; y < size + offset; y = y + pixelsPerModule)
48 | {
49 | var module = this.QrCodeData.ModuleMatrix[(y + pixelsPerModule) / pixelsPerModule - 1][(x + pixelsPerModule) / pixelsPerModule - 1];
50 | if (module)
51 | {
52 | gfx.FillRectangle(new SolidBrush(darkColor), new Rectangle(x - offset, y - offset, pixelsPerModule, pixelsPerModule));
53 | }
54 | else
55 | {
56 | gfx.FillRectangle(new SolidBrush(lightColor), new Rectangle(x - offset, y - offset, pixelsPerModule, pixelsPerModule));
57 | }
58 | }
59 | }
60 |
61 | gfx.Save();
62 | return bmp;
63 | }
64 |
65 | public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Bitmap icon = null, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true)
66 | {
67 | var size = (this.QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8)) * pixelsPerModule;
68 | var offset = drawQuietZones ? 0 : 4 * pixelsPerModule;
69 |
70 | var bmp = new Bitmap(size, size, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
71 |
72 | var gfx = Graphics.FromImage(bmp);
73 | gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
74 | gfx.CompositingQuality = CompositingQuality.HighQuality;
75 | gfx.Clear(lightColor);
76 |
77 | var drawIconFlag = icon != null && iconSizePercent > 0 && iconSizePercent <= 100;
78 |
79 | GraphicsPath iconPath = null;
80 | float iconDestWidth = 0, iconDestHeight = 0, iconX = 0, iconY = 0;
81 |
82 | if (drawIconFlag)
83 | {
84 | iconDestWidth = iconSizePercent * bmp.Width / 100f;
85 | iconDestHeight = drawIconFlag ? iconDestWidth * icon.Height / icon.Width : 0;
86 | iconX = (bmp.Width - iconDestWidth) / 2;
87 | iconY = (bmp.Height - iconDestHeight) / 2;
88 |
89 | var centerDest = new RectangleF(iconX - iconBorderWidth, iconY - iconBorderWidth, iconDestWidth + iconBorderWidth * 2, iconDestHeight + iconBorderWidth * 2);
90 | iconPath = this.CreateRoundedRectanglePath(centerDest, iconBorderWidth * 2);
91 | }
92 |
93 | var lightBrush = new SolidBrush(lightColor);
94 | var darkBrush = new SolidBrush(darkColor);
95 |
96 | for (var x = 0; x < size + offset; x = x + pixelsPerModule)
97 | {
98 | for (var y = 0; y < size + offset; y = y + pixelsPerModule)
99 | {
100 | var module = this.QrCodeData.ModuleMatrix[(y + pixelsPerModule) / pixelsPerModule - 1][(x + pixelsPerModule) / pixelsPerModule - 1];
101 | if (module)
102 | {
103 | var r = new Rectangle(x - offset, y - offset, pixelsPerModule, pixelsPerModule);
104 |
105 | if (drawIconFlag)
106 | {
107 | var region = new Region(r);
108 | region.Exclude(iconPath);
109 | gfx.FillRegion(darkBrush, region);
110 | }
111 | else
112 | {
113 | gfx.FillRectangle(darkBrush, r);
114 | }
115 | }
116 | else
117 | gfx.FillRectangle(lightBrush, new Rectangle(x - offset, y - offset, pixelsPerModule, pixelsPerModule));
118 | }
119 | }
120 |
121 | if (drawIconFlag)
122 | {
123 | var iconDestRect = new RectangleF(iconX, iconY, iconDestWidth, iconDestHeight);
124 | gfx.DrawImage(icon, iconDestRect, new RectangleF(0, 0, icon.Width, icon.Height), GraphicsUnit.Pixel);
125 | }
126 |
127 | gfx.Save();
128 | return bmp;
129 | }
130 |
131 | #endregion Public Methods
132 |
133 | #region Internal Methods
134 |
135 | internal GraphicsPath CreateRoundedRectanglePath(RectangleF rect, int cornerRadius)
136 | {
137 | var roundedRect = new GraphicsPath();
138 | roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
139 | roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
140 | roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
141 | roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
142 | roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
143 | roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
144 | roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
145 | roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
146 | roundedRect.CloseFigure();
147 | return roundedRect;
148 | }
149 |
150 | #endregion Internal Methods
151 | }
152 | }
153 | #endif
--------------------------------------------------------------------------------
/BiliAccount/QRCode/QRCodeData.cs:
--------------------------------------------------------------------------------
1 | #if !NETSTANDARD2_0 && !NETCORE3_0
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | namespace BiliAccount
6 | {
7 | #pragma warning disable CS1591
8 | using System;
9 | using System.IO;
10 | using System.IO.Compression;
11 |
12 | internal class QRCodeData : IDisposable
13 | {
14 | #region Public Constructors
15 |
16 | public QRCodeData(int version)
17 | {
18 | this.Version = version;
19 | var size = ModulesPerSideFromVersion(version);
20 | this.ModuleMatrix = new List();
21 | for (var i = 0; i < size; i++)
22 | this.ModuleMatrix.Add(new BitArray(size));
23 | }
24 |
25 | public QRCodeData(string pathToRawData, Compression compressMode) : this(File.ReadAllBytes(pathToRawData), compressMode)
26 | {
27 | }
28 |
29 | public QRCodeData(byte[] rawData, Compression compressMode)
30 | {
31 | var bytes = new List(rawData);
32 |
33 | //Decompress
34 | if (compressMode.Equals(Compression.Deflate))
35 | {
36 | using (var input = new MemoryStream(bytes.ToArray()))
37 | {
38 | using (var output = new MemoryStream())
39 | {
40 | using (var dstream = new DeflateStream(input, CompressionMode.Decompress))
41 | {
42 | Stream4Methods.CopyTo(dstream, output);
43 | }
44 | bytes = new List(output.ToArray());
45 | }
46 | }
47 | }
48 | else if (compressMode.Equals(Compression.GZip))
49 | {
50 | using (var input = new MemoryStream(bytes.ToArray()))
51 | {
52 | using (var output = new MemoryStream())
53 | {
54 | using (var dstream = new GZipStream(input, CompressionMode.Decompress))
55 | {
56 | Stream4Methods.CopyTo(dstream, output);
57 | }
58 | bytes = new List(output.ToArray());
59 | }
60 | }
61 | }
62 |
63 | if (bytes[0] != 0x51 || bytes[1] != 0x52 || bytes[2] != 0x52)
64 | throw new Exception("Invalid raw data file. Filetype doesn't match \"QRR\".");
65 |
66 | //Set QR code version
67 | var sideLen = (int)bytes[4];
68 | bytes.RemoveRange(0, 5);
69 | this.Version = (sideLen - 21 - 8) / 4 + 1;
70 |
71 | //Unpack
72 | var modules = new Queue();
73 | foreach (var b in bytes)
74 | {
75 | var bArr = new BitArray(new byte[] { b });
76 | for (int i = 7; i >= 0; i--)
77 | {
78 | modules.Enqueue((b & (1 << i)) != 0);
79 | }
80 | }
81 |
82 | //Build module matrix
83 | this.ModuleMatrix = new List();
84 | for (int y = 0; y < sideLen; y++)
85 | {
86 | this.ModuleMatrix.Add(new BitArray(sideLen));
87 | for (int x = 0; x < sideLen; x++)
88 | {
89 | this.ModuleMatrix[y][x] = modules.Dequeue();
90 | }
91 | }
92 | }
93 |
94 | #endregion Public Constructors
95 |
96 | #region Public Enums
97 |
98 | public enum Compression
99 | {
100 | Uncompressed,
101 | Deflate,
102 | GZip
103 | }
104 |
105 | #endregion Public Enums
106 |
107 | #region Public Properties
108 |
109 | public List ModuleMatrix { get; set; }
110 | public int Version { get; private set; }
111 |
112 | #endregion Public Properties
113 |
114 | #region Public Methods
115 |
116 | public void Dispose()
117 | {
118 | this.ModuleMatrix = null;
119 | this.Version = 0;
120 | }
121 |
122 | public byte[] GetRawData(Compression compressMode)
123 | {
124 | var bytes = new List();
125 |
126 | //Add header - signature ("QRR")
127 | bytes.AddRange(new byte[] { 0x51, 0x52, 0x52, 0x00 });
128 |
129 | //Add header - rowsize
130 | bytes.Add((byte)ModuleMatrix.Count);
131 |
132 | //Build data queue
133 | var dataQueue = new Queue();
134 | foreach (var row in ModuleMatrix)
135 | {
136 | foreach (var module in row)
137 | {
138 | dataQueue.Enqueue((bool)module ? 1 : 0);
139 | }
140 | }
141 | for (int i = 0; i < 8 - (ModuleMatrix.Count * ModuleMatrix.Count) % 8; i++)
142 | {
143 | dataQueue.Enqueue(0);
144 | }
145 |
146 | //Process queue
147 | while (dataQueue.Count > 0)
148 | {
149 | byte b = 0;
150 | for (int i = 7; i >= 0; i--)
151 | {
152 | b += (byte)(dataQueue.Dequeue() << i);
153 | }
154 | bytes.Add(b);
155 | }
156 | var rawData = bytes.ToArray();
157 |
158 | //Compress stream (optional)
159 | if (compressMode.Equals(Compression.Deflate))
160 | {
161 | using (var output = new MemoryStream())
162 | {
163 | using (var dstream = new DeflateStream(output, CompressionMode.Compress))
164 | {
165 | dstream.Write(rawData, 0, rawData.Length);
166 | }
167 | rawData = output.ToArray();
168 | }
169 | }
170 | else if (compressMode.Equals(Compression.GZip))
171 | {
172 | using (var output = new MemoryStream())
173 | {
174 | using (GZipStream gzipStream = new GZipStream(output, CompressionMode.Compress, true))
175 | {
176 | gzipStream.Write(rawData, 0, rawData.Length);
177 | }
178 | rawData = output.ToArray();
179 | }
180 | }
181 | return rawData;
182 | }
183 |
184 | public void SaveRawData(string filePath, Compression compressMode)
185 | {
186 | File.WriteAllBytes(filePath, GetRawData(compressMode));
187 | }
188 |
189 | #endregion Public Methods
190 |
191 | #region Private Methods
192 |
193 | private static int ModulesPerSideFromVersion(int version)
194 | {
195 | return 21 + (version - 1) * 4;
196 | }
197 |
198 | #endregion Private Methods
199 | }
200 | }
201 | #endif
--------------------------------------------------------------------------------
/BiliAccount/favicon_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoChen98/BiliAccount/834b8eee3b2860452b9c3090dc78f1321c4fc4bf/BiliAccount/favicon_4.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Leo Chen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BiliAccount
2 | B站账号操作封装
3 |
4 | [](https://github.com/LeoChen98/BiliAccount/releases)
5 | [](https://github.com/LeoChen98/BiliAccount/issues)
6 | [](https://github.com/LeoChen98/BiliAccount/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
7 | [](#)
8 | [](#)
9 | [](#)
10 | [](https://github.com/LeoChen98/BiliAccount/blob/master/LICENSE)
11 |
12 | ## 项目已经停止维护,虽然部分功能仍可使用,但可能由于B站的后续更新不再可用。
13 |
14 | ## 支持与依赖
15 | 框架|版本|依赖|备注
16 | ---|---|---|---
17 | .net framework|≥3.5|(无)|`2.0.0.7`前只支持`.net framework 4.5`
18 | .net standard|≥2.0|[Newtonsoft.Json](//github.com/JamesNK/Newtonsoft.Json) (≥ 12.0.3)
[QRCoder](//github.com/codebude/QRCoder/) (≥ 1.3.6)
[System.Drawing.Common](//github.com/dotnet/corefx) (≥ 4.7.0)|`2.0.0.7`起支持
19 | .net core|≥3.0|[Newtonsoft.Json](//github.com/JamesNK/Newtonsoft.Json) (≥ 12.0.3)
[QRCoder](//github.com/codebude/QRCoder/) (≥ 1.3.6)
[System.Drawing.Common](//github.com/dotnet/corefx) (≥ 4.7.0)|`2.0.2.9`起支持
20 |
21 | ## 项目结构
22 | 项目名|备注
23 | --|--
24 | [BiliAccount](//github.com/LeoChen98/BiliAccount/wiki/BiliAccount)|BiliAccount类库
25 | [BiliAccount.Geetest](//github.com/LeoChen98/BiliAccount.Geetest)|用于处理B站账号操作过程中的极验验证码的类库
26 | [BiliAccount.Geetest.Controls](//github.com/LeoChen98/BiliAccount.Geetest.Controls)|用于处理B站账号操作过程中的极验验证码的控件和窗体类库
27 | [BiliAccount.TestProject](//github.com/LeoChen98/BiliAccount/wiki/BiliAccount.TestProject)|测试工程
28 | [BiliAccount.TestProject.Winforms](//github.com/LeoChen98/BiliAccount/wiki/BiliAccount.TestProject.Winforms)|Winform测试工程
29 | [BiliAccount.TestProject.WPF](//github.com/LeoChen98/BiliAccount/wiki/BiliAccount.TestProject.WPF)|WPF测试工程
30 | [BiliAccount.Core31TestProject](//github.com/LeoChen98/BiliAccount/wiki/BiliAccount.Core31TestProject)|Core3.1命令行测试工程
31 |
32 | ## 获取与使用
33 |
34 | [](https://www.nuget.org/packages/BiliAccount/)
35 | [](https://github.com/LeoChen98/BiliAccount/releases/latest)
36 |
37 | **在使用以下命令时请将`Version`节点改为上述最新版本,否则可能会有错误。**
38 |
39 | 工具|命令/代码
40 | --|--
41 | Package Manager|`Install-Package BiliAccount -Version 2.2.0.12`
42 | .NET CLI|`dotnet add package BiliAccount --version 2.2.0.12`
43 | PackageReference|``
44 | Packet CLI|`paket add BiliAccount --version 2.2.0.12`
45 |
46 | **当前已知`CentOS`环境下需要手动安装gdi+组件**
47 | 具体使用方法请见[Wiki](https://github.com/LeoChen98/BiliAccount/wiki)
48 |
49 | ## 开放源代码许可
50 | [](https://app.fossa.io/projects/git%2Bgithub.com%2FLeoChen98%2FBiliAccount?ref=badge_large)
51 |
--------------------------------------------------------------------------------