1
- using System ;
1
+ using Qzone . Model ;
2
+ using Qzone . Util ;
3
+ using System ;
2
4
using System . Collections . Generic ;
3
5
using System . Linq ;
6
+ using System . Runtime . CompilerServices ;
4
7
using System . Text ;
5
8
using System . Threading . Tasks ;
6
9
using System . Windows ;
@@ -20,9 +23,112 @@ namespace Qzone
20
23
/// </summary>
21
24
public partial class MainWindow : TianXiaTech . BlurWindow
22
25
{
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 )
24
33
{
25
34
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
+ }
26
132
}
27
133
}
28
134
}
0 commit comments