Skip to content

Commit 904f588

Browse files
ztizti
zti
authored and
zti
committed
增加了登录功能
1 parent d396b99 commit 904f588

File tree

7 files changed

+164
-3
lines changed

7 files changed

+164
-3
lines changed

Qzone/Qzone.sln

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30320.27
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Qzone", "Qzone\Qzone.csproj", "{E408026B-7EC0-488A-B8ED-F7DB814E6186}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qzone", "Qzone\Qzone.csproj", "{E408026B-7EC0-488A-B8ED-F7DB814E6186}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
1112
Release|Any CPU = Release|Any CPU
13+
Release|x64 = Release|x64
1214
EndGlobalSection
1315
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1416
{E408026B-7EC0-488A-B8ED-F7DB814E6186}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1517
{E408026B-7EC0-488A-B8ED-F7DB814E6186}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{E408026B-7EC0-488A-B8ED-F7DB814E6186}.Debug|x64.ActiveCfg = Debug|x64
19+
{E408026B-7EC0-488A-B8ED-F7DB814E6186}.Debug|x64.Build.0 = Debug|x64
1620
{E408026B-7EC0-488A-B8ED-F7DB814E6186}.Release|Any CPU.ActiveCfg = Release|Any CPU
1721
{E408026B-7EC0-488A-B8ED-F7DB814E6186}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{E408026B-7EC0-488A-B8ED-F7DB814E6186}.Release|x64.ActiveCfg = Release|x64
23+
{E408026B-7EC0-488A-B8ED-F7DB814E6186}.Release|x64.Build.0 = Release|x64
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

Qzone/Qzone/MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:tianxia="clr-namespace:TianXiaTech;assembly=BlurWindow"
77
xmlns:local="clr-namespace:Qzone"
88
mc:Ignorable="d"
9-
Title="MainWindow" Height="450" Width="800" Background="White">
9+
Title="MainWindow" Height="600" Width="800" Background="White">
1010
<Grid>
1111

1212
</Grid>

Qzone/Qzone/Qzone.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<OutputType>WinExe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<UseWPF>true</UseWPF>
7+
<UseWindowsForms>true</UseWindowsForms>
8+
<Platforms>AnyCPU;x64</Platforms>
79
</PropertyGroup>
810

911
<ItemGroup>
@@ -12,6 +14,7 @@
1214

1315
<ItemGroup>
1416
<PackageReference Include="BlurWindow" Version="2.0.0" />
17+
<PackageReference Include="PuppeteerSharp" Version="2.0.4" />
1518
</ItemGroup>
1619

1720
<ItemGroup>

Qzone/Qzone/Util/ChromiumHelper.cs

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using PuppeteerSharp;
7+
8+
namespace Qzone.Util
9+
{
10+
public class ChromiumHelper
11+
{
12+
private Browser browser;
13+
private Page page;
14+
15+
private static object obj = new object();
16+
private static ChromiumHelper helper;
17+
18+
public Browser ChromiumBrowser
19+
{
20+
get
21+
{
22+
return browser;
23+
}
24+
}
25+
26+
public Page CurrentBrowserTab
27+
{
28+
get
29+
{
30+
return page;
31+
}
32+
}
33+
34+
public ChromiumHelper()
35+
{
36+
37+
}
38+
39+
public static ChromiumHelper GetChromium()
40+
{
41+
if(helper == null)
42+
{
43+
lock(obj)
44+
{
45+
if (helper == null)
46+
helper = new ChromiumHelper();
47+
}
48+
}
49+
50+
return helper;
51+
}
52+
53+
public async Task InitBrowser()
54+
{
55+
if (browser == null)
56+
{
57+
await new PuppeteerSharp.BrowserFetcher().DownloadAsync(PuppeteerSharp.BrowserFetcher.DefaultRevision);
58+
59+
browser = await PuppeteerSharp.Puppeteer.LaunchAsync(new PuppeteerSharp.LaunchOptions
60+
{
61+
Headless = false
62+
});
63+
64+
page = await browser.NewPageAsync();
65+
}
66+
}
67+
68+
public async Task LaunchUrl(string url)
69+
{
70+
if(page != null)
71+
{
72+
await page.GoToAsync(url);
73+
}
74+
}
75+
76+
public async Task<Stream> Screenshot()
77+
{
78+
if(page != null)
79+
{
80+
return await page.ScreenshotStreamAsync();
81+
}
82+
83+
return null;
84+
}
85+
86+
public void SetTargetChangedHandler(EventHandler<TargetChangedArgs> eventHandler)
87+
{
88+
if(browser != null)
89+
{
90+
browser.TargetChanged += eventHandler;
91+
}
92+
}
93+
94+
~ChromiumHelper()
95+
{
96+
if (browser != null)
97+
{
98+
browser.Disconnect();
99+
browser.Dispose();
100+
}
101+
}
102+
}
103+
}

Qzone/Qzone/Util/QzoneUrl.cs

+5
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ namespace Qzone.Util
77
public class QzoneUrl
88
{
99
public const string DefaultBackgroundUrl = "http://qzonestyle.gtimg.cn/qzone/qzactStatics/imgs/20171122191532_f2975b.jpg";
10+
11+
/// <summary>
12+
/// 访问该链接会弹出快捷登录
13+
/// </summary>
14+
public const string LoginUrl = "https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https%3A%2F%2Fqzs.qzone.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&pt_qr_app=手机QQ空间&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=https%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html&pt_no_auth=1";
1015
}
1116
}

Qzone/Qzone/Util/WinAPI.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Qzone.Util
6+
{
7+
public class WinAPI
8+
{
9+
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
10+
public static extern bool DeleteObject(IntPtr hObject);
11+
}
12+
}

Qzone/Qzone/View/Login.xaml.cs

+33-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public Login()
2323
{
2424
InitializeComponent();
2525

26-
LoadBackgroundImageAsync();
26+
LoadLoginPage();
2727
}
2828

2929
private async void LoadBackgroundImageAsync()
@@ -44,5 +44,37 @@ private async void LoadBackgroundImageAsync()
4444
ib.ImageSource = bi;
4545
this.Background = ib;
4646
}
47+
48+
private async void LoadLoginPage()
49+
{
50+
var chromium = ChromiumHelper.GetChromium();
51+
await chromium.InitBrowser();
52+
chromium.SetTargetChangedHandler(NavigateToQzone);
53+
await chromium.LaunchUrl(QzoneUrl.LoginUrl);
54+
using(System.IO.Stream stream = await chromium.Screenshot())
55+
{
56+
System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(stream);
57+
var hBitmap = bitmap.GetHbitmap();
58+
59+
try
60+
{
61+
var source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
62+
ImageBrush ib = new ImageBrush();
63+
ib.ImageSource = source;
64+
ib.Stretch = Stretch.UniformToFill;
65+
this.Background = ib;
66+
}
67+
finally
68+
{
69+
WinAPI.DeleteObject(hBitmap);
70+
}
71+
72+
}
73+
}
74+
75+
private void NavigateToQzone(object sender, PuppeteerSharp.TargetChangedArgs args)
76+
{
77+
78+
}
4779
}
4880
}

0 commit comments

Comments
 (0)