Skip to content

Commit e68ec97

Browse files
committed
可以获取说说基本信息
1 parent 904f588 commit e68ec97

20 files changed

+1004
-19
lines changed

Qzone/Qzone/App.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="clr-namespace:Qzone"
5-
StartupUri="View/Login.xaml">
5+
StartupUri="View\Login.xaml" DispatcherUnhandledException="Application_DispatcherUnhandledException">
66
<Application.Resources>
77

88
</Application.Resources>

Qzone/Qzone/App.xaml.cs

+5
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ namespace Qzone
1313
/// </summary>
1414
public partial class App : Application
1515
{
16+
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
17+
{
18+
MessageBox.Show(e.Exception.ToString());
19+
e.Handled = true;
20+
}
1621
}
1722
}

Qzone/Qzone/Icon/avatar.jpg

36.8 KB
Loading

Qzone/Qzone/MainWindow.xaml

+62-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,69 @@
66
xmlns:tianxia="clr-namespace:TianXiaTech;assembly=BlurWindow"
77
xmlns:local="clr-namespace:Qzone"
88
mc:Ignorable="d"
9-
Title="MainWindow" Height="600" Width="800" Background="White">
9+
Height="750" Width="400" Background="White" Closing="BlurWindow_Closing" Loaded="BlurWindow_Loaded" KeyDown="BlurWindow_KeyDown">
1010
<Grid>
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="auto"/>
13+
<RowDefinition Height="auto"/>
14+
<RowDefinition/>
15+
</Grid.RowDefinitions>
1116

17+
<WrapPanel VerticalAlignment="Center" Visibility="Collapsed">
18+
<Image Width="80" Height="80">
19+
<Image.Clip>
20+
<EllipseGeometry RadiusX="40" RadiusY="40" Center="40,40">
21+
22+
</EllipseGeometry>
23+
</Image.Clip>
24+
</Image>
25+
<StackPanel>
26+
<Label Content="Test" FontSize="25" FontWeight="Bold" Margin="5"/>
27+
<Label Content="Today is a good day" VerticalAlignment="Bottom" Margin="5,0,0,5"/>
28+
</StackPanel>
29+
</WrapPanel>
30+
31+
<StackPanel Grid.Row="1" Background="#8d93ab" Margin="1">
32+
<Label Content="2020年09月02日" FontSize="20" Foreground="White" Name="lbl_Date"/>
33+
<Label Content="星期五 22:00:30 " FontSize="10" Foreground="White" Name="lbl_Time"/>
34+
</StackPanel>
35+
36+
<Grid Grid.Row="2">
37+
<Border Margin="0,0,0,30" Background="Transparent" >
38+
39+
<Grid Visibility="Visible">
40+
<Grid.RowDefinitions>
41+
<RowDefinition Height="auto"/>
42+
<RowDefinition Height="auto"/>
43+
<RowDefinition Height="auto"/>
44+
<RowDefinition Height="auto"/>
45+
<RowDefinition Height="auto"/>
46+
</Grid.RowDefinitions>
47+
48+
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="0" Margin="10,10">
49+
<TextBlock TextWrapping="WrapWithOverflow" Grid.Row="0" FontSize="12" Name="tbox_Content" />
50+
51+
</ScrollViewer>
52+
53+
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="1">
54+
<WrapPanel Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Auto" Name="area_SuoSuoImage">
55+
56+
</WrapPanel>
57+
</ScrollViewer>
58+
59+
<WrapPanel Grid.Row="2" HorizontalAlignment="Left" Margin="10,0,10,0" Name="area_Like">
60+
61+
</WrapPanel>
62+
63+
<Grid Grid.Row="3" Margin="10,0,10,0">
64+
<Label Content="阅读:30 点赞:30" Foreground="#FF958F8F" Name="lbl_Statistics"/>
65+
</Grid>
66+
67+
<StackPanel Grid.Row="4" Margin="10,0,0,10" Name="area_Comment">
68+
69+
</StackPanel>
70+
</Grid>
71+
</Border>
72+
</Grid>
1273
</Grid>
1374
</tianxia:BlurWindow>

Qzone/Qzone/MainWindow.xaml.cs

+108-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using System;
1+
using Qzone.Model;
2+
using Qzone.Util;
3+
using System;
24
using System.Collections.Generic;
35
using System.Linq;
6+
using System.Runtime.CompilerServices;
47
using System.Text;
58
using System.Threading.Tasks;
69
using System.Windows;
@@ -20,9 +23,112 @@ namespace Qzone
2023
/// </summary>
2124
public partial class MainWindow : TianXiaTech.BlurWindow
2225
{
23-
public MainWindow()
26+
private const int WindowWidth = 400;
27+
28+
private string currentQQNum;
29+
private string g_tk;
30+
private int count;
31+
32+
public MainWindow(string qqNum)
2433
{
2534
InitializeComponent();
35+
currentQQNum = qqNum;
36+
}
37+
38+
private void BlurWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
39+
{
40+
ChromiumHelper.GetChromium().FreeChromiumHelper();
41+
}
42+
43+
private async void BlurWindow_Loaded(object sender, RoutedEventArgs e)
44+
{
45+
await Task.Delay(500);
46+
count = await GetSSCount();
47+
RandomFetchSuoSuo();
48+
}
49+
50+
private async void RandomFetchSuoSuo()
51+
{
52+
var pos = new Random().Next(0, count).ToString();
53+
var getSSUrl = QzoneUrl.GetQzoneSuoSuoUrl.Replace("@qq", currentQQNum).Replace("@pos", pos).Replace("@num", "1").Replace("@g_tk", g_tk);
54+
var ssStr = await ChromiumHelper.GetChromium().GetHtmlSource(getSSUrl);
55+
ssStr = RegexUtil.ExtractJson(ssStr);
56+
var ss = JsonUtil.Parse<SuoSuo>(ssStr);
57+
DisplaySuoSuo(ss);
58+
}
59+
60+
private void DisplaySuoSuo(SuoSuo ss)
61+
{
62+
if (ss == null || ss.msglist.Count == 0)
63+
return;
64+
65+
var msg = ss.msglist.First();
66+
67+
this.lbl_Date.Content = msg.createTime.ToString("yyyy年MM月dd日");
68+
this.lbl_Time.Content = ConvertUtil.ConvertFromJsTick(ConvertUtil.SafeConvertToLong(msg.created_time)).ToString("HH:mm:ss");
69+
this.tbox_Content.Text = msg.content;
70+
71+
area_SuoSuoImage.Children.Clear();
72+
area_Comment.Children.Clear();
73+
area_Like.Children.Clear();
74+
75+
if (msg.pic != null && msg.pic.Count > 0)
76+
{
77+
var columns = msg.pic.Count % 3;
78+
79+
foreach (var item in msg.pic)
80+
{
81+
Image image = new Image() { Width = (WindowWidth - 20) /columns, Height = Width, Margin = new Thickness(5), Stretch = Stretch.UniformToFill };
82+
BitmapImage bi = new BitmapImage();
83+
bi.BeginInit();
84+
bi.UriSource = new Uri(item.url3);
85+
bi.EndInit();
86+
image.Source = bi;
87+
88+
//设置缩略图Tooltip
89+
System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
90+
//binding.ElementName = "image";
91+
binding.Source = image;
92+
binding.Path = new PropertyPath("Source");
93+
Image toolTipImage = new Image();
94+
System.Windows.Controls.ToolTip toolTip = new System.Windows.Controls.ToolTip();
95+
toolTipImage.SetBinding(Image.SourceProperty, binding);
96+
toolTip.Content = toolTipImage;
97+
98+
image.ToolTip = toolTip;
99+
100+
area_SuoSuoImage.Children.Add(image);
101+
}
102+
}
103+
}
104+
105+
/// <summary>
106+
/// 获取说说总条数
107+
/// </summary>
108+
/// <returns></returns>
109+
private async Task<int> GetSSCount()
110+
{
111+
var chromium = ChromiumHelper.GetChromium();
112+
var skey = await chromium.GetS_Key();
113+
g_tk = WebUtil.CalcG_tk(skey);
114+
var url = QzoneUrl.GetPersonalMain.Replace("@qq", currentQQNum).Replace("@g_tk",g_tk);
115+
await chromium.LaunchUrl(url);
116+
var source = await chromium.GetHtmlSource();
117+
118+
if (string.IsNullOrEmpty(source))
119+
return 0;
120+
121+
var ssCount = RegexUtil.Extract(source, RegexUtil.ExtractSSPattern, "ss");
122+
123+
return ConvertUtil.SafeConvertToInt(ssCount);
124+
}
125+
126+
private void BlurWindow_KeyDown(object sender, KeyEventArgs e)
127+
{
128+
if(e.Key == Key.F5)
129+
{
130+
RandomFetchSuoSuo();
131+
}
26132
}
27133
}
28134
}

0 commit comments

Comments
 (0)