Browse Source

请求添加认证参数和用户ID

master
张剑 1 year ago
parent
commit
effb979b4d

XHWK.Model/Model_UserInfo.cs → XHWK.Model/ModelUserInfo.cs View File

2
 
2
 
3
 namespace XHWK.Model
3
 namespace XHWK.Model
4
 {
4
 {
5
-    public class Model_UserInfo
5
+    public class ModelUserInfo
6
     {
6
     {
7
+        public string token_key { get; set; }
8
+        public string token_value { get; set; }
9
+
7
         /// <summary>
10
         /// <summary>
8
         /// 用户id
11
         /// 用户id
9
         /// </summary>
12
         /// </summary>

+ 1
- 1
XHWK.Model/XHWK.Model.csproj View File

81
     <Compile Include="Model_Signatures.cs" />
81
     <Compile Include="Model_Signatures.cs" />
82
     <Compile Include="Model_TmatrixCode.cs" />
82
     <Compile Include="Model_TmatrixCode.cs" />
83
     <Compile Include="Model_TsubjectbookList.cs" />
83
     <Compile Include="Model_TsubjectbookList.cs" />
84
-    <Compile Include="Model_UserInfo.cs" />
84
+    <Compile Include="ModelUserInfo.cs" />
85
     <Compile Include="Model_Video.cs" />
85
     <Compile Include="Model_Video.cs" />
86
     <Compile Include="Model_WKData.cs" />
86
     <Compile Include="Model_WKData.cs" />
87
     <Compile Include="NotifyModel.cs" />
87
     <Compile Include="NotifyModel.cs" />

+ 3
- 3
XHWK.WKTool/App.config View File

5
   </startup>
5
   </startup>
6
   <appSettings>
6
   <appSettings>
7
     <!--0正式 1测试-->
7
     <!--0正式 1测试-->
8
-    <add key="IsDebug" value="0" />
8
+    <add key="IsDebug" value="1" />
9
     <!--参数是否加密 0不加密 1加密-->
9
     <!--参数是否加密 0不加密 1加密-->
10
     <add key="IsParameterEncryption" value="0" />
10
     <add key="IsParameterEncryption" value="0" />
11
     <!--版本号-->
11
     <!--版本号-->
12
-    <add key="VersionCode" value="125" />
13
-    <add key="VersionName" value="3.9.8" />
12
+    <add key="VersionCode" value="126" />
13
+    <add key="VersionName" value="3.12.0" />
14
     <!--皮肤样式 0白 1蓝 2黑色 -->
14
     <!--皮肤样式 0白 1蓝 2黑色 -->
15
     <add key="SkinStyle" value="0" />
15
     <add key="SkinStyle" value="0" />
16
     <!--是否输出视频记录日志:0否-->
16
     <!--是否输出视频记录日志:0否-->

+ 4
- 2
XHWK.WKTool/App.xaml.cs View File

136
         /// <summary>
136
         /// <summary>
137
         /// 用户信息
137
         /// 用户信息
138
         /// </summary>
138
         /// </summary>
139
-        public static Model_UserInfo UserInfo;
139
+        public static ModelUserInfo UserInfo;
140
 
140
 
141
         /// <summary>
141
         /// <summary>
142
         /// 接口返回消息
142
         /// 接口返回消息
316
         {
316
         {
317
             Console.WriteLine(@"初始化APP");
317
             Console.WriteLine(@"初始化APP");
318
             LogHelper.InitLog4Net();
318
             LogHelper.InitLog4Net();
319
+            bool isParameterEncryption = FileToolsCommon.GetConfigValue("IsParameterEncryption") != "0";
320
+            HttpHelper.isParameterEncryption = isParameterEncryption;
319
             myloading = new LoadDialog();
321
             myloading = new LoadDialog();
320
             Killffmpeg();
322
             Killffmpeg();
321
             try
323
             try
322
             {
324
             {
323
-                UserInfo = new Model_UserInfo();
325
+                UserInfo = new ModelUserInfo();
324
                 WKDataList = new List<Model_WKData>();
326
                 WKDataList = new List<Model_WKData>();
325
                 VideoList = new List<Model_Video>();
327
                 VideoList = new List<Model_Video>();
326
 
328
 

+ 67
- 91
XHWK.WKTool/DAL/XHApi.cs View File

13
 {
13
 {
14
     using system;
14
     using system;
15
 
15
 
16
-    public class XHApi
16
+    public class XhApi
17
     {
17
     {
18
         /// <summary>
18
         /// <summary>
19
         /// 激活信息--添加
19
         /// 激活信息--添加
20
         /// </summary>
20
         /// </summary>
21
-        /// <param name="request">
22
-        /// </param>
23
         /// <returns>
21
         /// <returns>
24
         /// </returns>
22
         /// </returns>
25
-        public int ActivationAdd(string mac, string device, string projectcode)
23
+        public int ActivationAdd
24
+        (
25
+            string mac,
26
+            string device,
27
+            string projectcode
28
+        )
26
         {
29
         {
27
             try
30
             try
28
             {
31
             {
42
                     App.ServerMsg = "网络异常!";
45
                     App.ServerMsg = "网络异常!";
43
                     return 1;
46
                     return 1;
44
                 }
47
                 }
45
-                else
48
+                JObject obj = JObject.Parse(xmlDoc);
49
+                if (obj["code"].ToString().Equals("0"))
46
                 {
50
                 {
47
-                    JObject obj = JObject.Parse(xmlDoc);
48
-                    if (obj != null)
49
-                    {
50
-                        if (obj["code"].ToString().Equals("0"))
51
-                        {
52
-                            App.Signature = obj["obj"].ToString();
53
-                            if (!Directory.Exists(App.DataPath))
54
-                            {
55
-                                Directory.CreateDirectory(App.DataPath);
56
-                            }
57
-                            string ApplicationData = App.DataPath + "signature.txt";
58
-                            System.IO.File.WriteAllText
59
-                            (
60
-                                ApplicationData,
61
-                                App.Signature,
62
-                                Encoding.Default
63
-                            ); //存放签名
64
-                            return 0;
65
-                        }
66
-                        else
67
-                        {
68
-                            App.ServerMsg = obj["msg"].ToString();
69
-                            return Convert.ToInt32(obj["code"].ToString());
70
-                        }
71
-                    }
72
-                    else
51
+                    App.Signature = obj["obj"]?.ToString();
52
+                    if (!Directory.Exists(App.DataPath))
73
                     {
53
                     {
74
-                        return 1;
54
+                        Directory.CreateDirectory(App.DataPath);
75
                     }
55
                     }
56
+                    string applicationData = App.DataPath + "signature.txt";
57
+                    System.IO.File.WriteAllText
58
+                    (
59
+                        applicationData,
60
+                        App.Signature,
61
+                        Encoding.Default
62
+                    ); //存放签名
63
+                    return 0;
64
+                }
65
+                else
66
+                {
67
+                    App.ServerMsg = obj["msg"]?.ToString();
68
+                    return Convert.ToInt32(obj["code"].ToString());
76
                 }
69
                 }
77
             }
70
             }
78
             catch (Exception ex)
71
             catch (Exception ex)
86
         /// <summary>
79
         /// <summary>
87
         /// 激活信息--添加激活历史
80
         /// 激活信息--添加激活历史
88
         /// </summary>
81
         /// </summary>
89
-        /// <param name="request">
90
-        /// </param>
91
         /// <returns>
82
         /// <returns>
92
         /// </returns>
83
         /// </returns>
93
         public int ActivationAddHistory()
84
         public int ActivationAddHistory()
107
                 else
98
                 else
108
                 {
99
                 {
109
                     JObject obj = JObject.Parse(xmlDoc);
100
                     JObject obj = JObject.Parse(xmlDoc);
110
-                    if (obj != null)
111
-                    {
112
-                        App.ServerMsg = obj["msg"].ToString();
113
-                        return Convert.ToInt32(obj["code"].ToString());
114
-                    }
115
-                    else
116
-                    {
117
-                        return 1;
118
-                    }
101
+                    App.ServerMsg = obj["msg"]?.ToString();
102
+                    return Convert.ToInt32(obj["code"]?.ToString());
119
                 }
103
                 }
120
             }
104
             }
121
             catch (Exception ex)
105
             catch (Exception ex)
128
         /// <summary>
112
         /// <summary>
129
         /// 登录
113
         /// 登录
130
         /// </summary>
114
         /// </summary>
131
-        /// <param name="request">
132
-        /// </param>
133
         /// <returns>
115
         /// <returns>
134
         /// </returns>
116
         /// </returns>
135
         public int Login(string loginname, string loginpwd)
117
         public int Login(string loginname, string loginpwd)
138
             string url = App.apiUrl + "/suser/user/login"; //地址
120
             string url = App.apiUrl + "/suser/user/login"; //地址
139
 
121
 
140
             //1.193.37.200
122
             //1.193.37.200
141
-            string Address = "";//河南 郑州
142
-            HttpHelper.GetAddressIP(out string AddressIP, out AddressIP);
123
+            const string address = ""; //河南 郑州
124
+            HttpHelper.GetAddressIp(out string addressIp, out addressIp);
143
             Dictionary<string, object> dic = new Dictionary<string, object>
125
             Dictionary<string, object> dic = new Dictionary<string, object>
144
             {
126
             {
145
-                { "loginname", loginname},
146
-                { "loginpwd", loginpwd},
147
-                {"logip", AddressIP},
148
-                {"logaddress", Address},
149
-                {"ultype", "microlecture_pc_t"},
150
-                {"versionnum", FileToolsCommon.GetConfigValue("VersionName")}
127
+                { "loginname", loginname },
128
+                { "loginpwd", loginpwd },
129
+                { "logip", addressIp },
130
+                { "logaddress", address },
131
+                { "ultype", "microlecture_pc_t" },
132
+                { "versionnum", FileToolsCommon.GetConfigValue("VersionName") }
151
             };
133
             };
152
             string body = JsonHelper.ToJson(dic);
134
             string body = JsonHelper.ToJson(dic);
153
-            ResultVo<Model_UserInfo> result = HttpHelper.PostAndRespSignle<ResultVo<Model_UserInfo>>(url, postData: body);
135
+            ResultVo<ModelUserInfo> result = HttpHelper.PostAndRespSignle<ResultVo<ModelUserInfo>>(url, postData: body);
154
             if (result != null)
136
             if (result != null)
155
             {
137
             {
156
-                App.UserInfo = new Model_UserInfo();
138
+                App.UserInfo = new ModelUserInfo();
157
                 App.ServerMsg = result.msg;
139
                 App.ServerMsg = result.msg;
158
                 if (result.obj != null)
140
                 if (result.obj != null)
159
                 {
141
                 {
160
                     App.UserInfo = result.obj;
142
                     App.UserInfo = result.obj;
143
+                    HttpHelper.tokenKey = result.obj.token_key;
144
+                    HttpHelper.tokenValue = result.obj.token_value;
145
+                    HttpHelper.userId = result.obj.Userid + "";
161
                 }
146
                 }
162
                 return result.code;
147
                 return result.code;
163
             }
148
             }
164
-            else
165
-            {
166
-                App.ServerMsg = "网络异常!";
167
-                App.UserInfo = new Model_UserInfo();
168
-                return 1;
169
-            }
149
+            App.ServerMsg = "网络异常!";
150
+            App.UserInfo = new ModelUserInfo();
151
+            return 1;
170
         }
152
         }
171
 
153
 
172
         /// <summary>
154
         /// <summary>
174
         /// </summary>
156
         /// </summary>
175
         /// <param name="headPortrait">
157
         /// <param name="headPortrait">
176
         /// </param>
158
         /// </param>
177
-        /// <param name="SavePath">
159
+        /// <param name="savePath">
178
         /// </param>
160
         /// </param>
179
         /// <returns>
161
         /// <returns>
180
         /// </returns>
162
         /// </returns>
181
-        public bool DownloadAvatar(string headPortrait, string SavePath)
163
+        public bool DownloadAvatar(string headPortrait, string savePath)
182
         {
164
         {
183
             string url = App.showImageUrl + headPortrait;
165
             string url = App.showImageUrl + headPortrait;
184
-            bool result = HttpHelper.GetDataGetHtml(url, SavePath, "");
166
+            bool result = HttpHelper.GetDataGetHtml
167
+            (
168
+                url,
169
+                savePath,
170
+                ""
171
+            );
185
             return result;
172
             return result;
186
         }
173
         }
187
 
174
 
188
         /// <summary>
175
         /// <summary>
189
         /// 教师教材列表
176
         /// 教师教材列表
190
         /// </summary>
177
         /// </summary>
191
-        /// <param name="request">
192
-        /// </param>
193
         /// <returns>
178
         /// <returns>
194
         /// </returns>
179
         /// </returns>
195
         public int TsubjectbookList()
180
         public int TsubjectbookList()
223
         /// <summary>
208
         /// <summary>
224
         /// 章节--列表
209
         /// 章节--列表
225
         /// </summary>
210
         /// </summary>
226
-        /// <param name="request">
227
-        /// </param>
228
         /// <returns>
211
         /// <returns>
229
         /// </returns>
212
         /// </returns>
230
-        public int DirectorList(string lsbid, int belong, int createid)
213
+        public int DirectorList
214
+        (
215
+            string lsbid,
216
+            int belong,
217
+            int createid
218
+        )
231
         {
219
         {
232
             App.DirectorList = new List<Model_DirectorList>();
220
             App.DirectorList = new List<Model_DirectorList>();
233
             try
221
             try
263
         /// <summary>
251
         /// <summary>
264
         /// 资源--添加
252
         /// 资源--添加
265
         /// </summary>
253
         /// </summary>
266
-        /// <param name="request">
267
-        /// </param>
268
         /// <returns>
254
         /// <returns>
269
         /// </returns>
255
         /// </returns>
270
         public int ResourceAdd(Model_ResourceAdd model)
256
         public int ResourceAdd(Model_ResourceAdd model)
320
                 string body = JsonHelper.ToJson(dic);
306
                 string body = JsonHelper.ToJson(dic);
321
                 string xmlDoc = HttpHelper.HttpPost(body, url);
307
                 string xmlDoc = HttpHelper.HttpPost(body, url);
322
                 JObject obj = JObject.Parse(xmlDoc);
308
                 JObject obj = JObject.Parse(xmlDoc);
323
-                if (obj != null)
324
-                {
325
-                    App.ServerMsg = obj["msg"].ToString();
326
-                    return Convert.ToInt32(obj["code"].ToString());
327
-                }
328
-                else
329
-                {
330
-                    App.ServerMsg = "网络异常!";
331
-                    return 1;
332
-                }
309
+                App.ServerMsg = obj["msg"]?.ToString();
310
+                return Convert.ToInt32(obj["code"]?.ToString());
333
             }
311
             }
334
             catch (Exception ex)
312
             catch (Exception ex)
335
             {
313
             {
342
         /// <summary>
320
         /// <summary>
343
         /// 请求服务地址
321
         /// 请求服务地址
344
         /// </summary>
322
         /// </summary>
345
-        /// <param name="Schoolcode">
323
+        /// <param name="schoolcode">
346
         /// </param>
324
         /// </param>
325
+        /// <param name="message"></param>
347
         /// <returns>
326
         /// <returns>
348
         /// </returns>
327
         /// </returns>
349
-        public bool GetServiceAddress(string Schoolcode, out string Message)
328
+        public bool GetServiceAddress(string schoolcode, out string message)
350
         {
329
         {
351
             string url = App.certapiUrl + "/school/find_code"; //地址
330
             string url = App.certapiUrl + "/school/find_code"; //地址
352
-            Dictionary<string, object> dic = new Dictionary<string, object>
353
-            {
354
-                { "schoolcode", Schoolcode}
355
-            };
331
+            Dictionary<string, object> dic = new Dictionary<string, object> { { "schoolcode", schoolcode } };
356
             string body = JsonHelper.ToJson(dic);
332
             string body = JsonHelper.ToJson(dic);
357
             ResultVo<Model_ServiceAddress> result = HttpHelper.PostAndRespSignle<ResultVo<Model_ServiceAddress>>(url, postData: body);
333
             ResultVo<Model_ServiceAddress> result = HttpHelper.PostAndRespSignle<ResultVo<Model_ServiceAddress>>(url, postData: body);
358
             if (result != null)
334
             if (result != null)
361
                 {
337
                 {
362
                     if (result.obj != null)
338
                     if (result.obj != null)
363
                     {
339
                     {
364
-                        Message = result.msg;
340
+                        message = result.msg;
365
                         App.ServiceAddress = result.obj;
341
                         App.ServiceAddress = result.obj;
366
                         App.SaveServiceAddressData();
342
                         App.SaveServiceAddressData();
367
                         return true;
343
                         return true;
368
                     }
344
                     }
369
                     else
345
                     else
370
                     {
346
                     {
371
-                        Message = "服务地址错误,请输入正确的地址!";
347
+                        message = "服务地址错误,请输入正确的地址!";
372
                         return false;
348
                         return false;
373
                     }
349
                     }
374
                 }
350
                 }
375
                 else
351
                 else
376
                 {
352
                 {
377
-                    Message = result.msg;
353
+                    message = result.msg;
378
                     return false;
354
                     return false;
379
                 }
355
                 }
380
             }
356
             }
381
             else
357
             else
382
             {
358
             {
383
-                Message = "无法与服务器建立连接,请检查网络状态。";
359
+                message = "无法与服务器建立连接,请检查网络状态。";
384
                 return false;
360
                 return false;
385
             }
361
             }
386
         }
362
         }

+ 2
- 2
XHWK.WKTool/KeyVerification.xaml View File

44
                 Grid.Row="0"
44
                 Grid.Row="0"
45
                 Padding="10,0,10,0"
45
                 Padding="10,0,10,0"
46
                 HorizontalAlignment="Right"
46
                 HorizontalAlignment="Right"
47
-                Click="close_click"
47
+                Click="CloseClick"
48
                 Content="×"
48
                 Content="×"
49
                 Cursor="Hand"
49
                 Cursor="Hand"
50
                 FontSize="30"
50
                 FontSize="30"
77
             Width="138"
77
             Width="138"
78
             Height="36"
78
             Height="36"
79
             Margin="30,0,30,0"
79
             Margin="30,0,30,0"
80
-            Click="btnEnd_Click"
80
+            Click="BtnEndClick"
81
             Content="验证"
81
             Content="验证"
82
             Cursor="Hand"
82
             Cursor="Hand"
83
             FontSize="16"
83
             FontSize="16"

+ 3
- 3
XHWK.WKTool/KeyVerification.xaml.cs View File

17
          */
17
          */
18
     public partial class KeyVerification
18
     public partial class KeyVerification
19
     {
19
     {
20
-        private readonly XHApi _registerController = new XHApi();
20
+        private readonly XhApi _registerController = new XhApi();
21
         private int _serverReturnCode;
21
         private int _serverReturnCode;
22
 
22
 
23
         public KeyVerification()
23
         public KeyVerification()
34
             DragMove();
34
             DragMove();
35
         }
35
         }
36
 
36
 
37
-        private void btnEnd_Click(object sender, RoutedEventArgs e)
37
+        private void BtnEndClick(object sender, RoutedEventArgs e)
38
         {
38
         {
39
             if (string.IsNullOrWhiteSpace(TxbKey.Text))
39
             if (string.IsNullOrWhiteSpace(TxbKey.Text))
40
             {
40
             {
154
             }
154
             }
155
         }
155
         }
156
 
156
 
157
-        private void close_click(object sender, RoutedEventArgs e)
157
+        private void CloseClick(object sender, RoutedEventArgs e)
158
         {
158
         {
159
             CloseAction();
159
             CloseAction();
160
         }
160
         }

+ 1
- 1
XHWK.WKTool/LoginWindow.xaml View File

122
                                 FontSize="14"
122
                                 FontSize="14"
123
                                 Foreground="#FF999999"
123
                                 Foreground="#FF999999"
124
                                 InputMethod.IsInputMethodEnabled="False"
124
                                 InputMethod.IsInputMethodEnabled="False"
125
-                                PreviewTextInput="txbAccountNumber_PreviewTextInput"
125
+                                PreviewTextInput="TxbAccountNumberPreviewTextInput"
126
                                 Text="" />
126
                                 Text="" />
127
                             <Label Height="1.5" Background="#3F6FFF" />
127
                             <Label Height="1.5" Background="#3F6FFF" />
128
                         </StackPanel>
128
                         </StackPanel>

+ 2
- 2
XHWK.WKTool/LoginWindow.xaml.cs View File

23
         /// <summary>
23
         /// <summary>
24
         /// 调用接口
24
         /// 调用接口
25
         /// </summary>
25
         /// </summary>
26
-        private readonly XHApi xhapi = new XHApi();
26
+        private readonly XhApi xhapi = new XhApi();
27
 
27
 
28
         public LoginWindow()
28
         public LoginWindow()
29
         {
29
         {
224
         /// </param>
224
         /// </param>
225
         /// <param name="e">
225
         /// <param name="e">
226
         /// </param>
226
         /// </param>
227
-        private void txbAccountNumber_PreviewTextInput(object sender, TextCompositionEventArgs e)
227
+        private void TxbAccountNumberPreviewTextInput(object sender, TextCompositionEventArgs e)
228
         {
228
         {
229
             try
229
             try
230
             {
230
             {

+ 1
- 1
XHWK.WKTool/MainWindow.xaml.cs View File

376
             TxbLoginType.Text = "未登录";
376
             TxbLoginType.Text = "未登录";
377
             ImgHeadImgN.Visibility = Visibility.Visible;
377
             ImgHeadImgN.Visibility = Visibility.Visible;
378
             ImgHeadImg.Visibility = Visibility.Collapsed;
378
             ImgHeadImg.Visibility = Visibility.Collapsed;
379
-            App.UserInfo = new Model_UserInfo();
379
+            App.UserInfo = new ModelUserInfo();
380
         }
380
         }
381
 
381
 
382
         #endregion 登录
382
         #endregion 登录

+ 1
- 1
XHWK.WKTool/ProductVerification.xaml View File

85
                     HorizontalAlignment="Right"
85
                     HorizontalAlignment="Right"
86
                     VerticalAlignment="Center"
86
                     VerticalAlignment="Center"
87
                     Background="White"
87
                     Background="White"
88
-                    Click="close_click"
88
+                    Click="CloseClick"
89
                     Cursor="Hand"
89
                     Cursor="Hand"
90
                     >
90
                     >
91
                     <Button.Template>
91
                     <Button.Template>

+ 5
- 4
XHWK.WKTool/ProductVerification.xaml.cs View File

20
          */
20
          */
21
     public partial class ProductVerification : Window
21
     public partial class ProductVerification : Window
22
     {
22
     {
23
-        private readonly XHApi registerController = new XHApi();
23
+        private readonly XhApi registerController = new XhApi();
24
         private int serverReturnCode = 0;
24
         private int serverReturnCode = 0;
25
 
25
 
26
         public ProductVerification()
26
         public ProductVerification()
132
         /// </summary>
132
         /// </summary>
133
         /// <param name="sender"></param>
133
         /// <param name="sender"></param>
134
         /// <param name="e"></param>
134
         /// <param name="e"></param>
135
-        private void close_click(object sender, RoutedEventArgs e)
135
+        private void CloseClick(object sender, RoutedEventArgs e)
136
         {
136
         {
137
-            closeAction();
137
+            CloseAction();
138
         }
138
         }
139
+
139
         /// <summary>
140
         /// <summary>
140
         /// 退出程序
141
         /// 退出程序
141
         /// </summary>
142
         /// </summary>
142
-        private void closeAction()
143
+        private void CloseAction()
143
         {
144
         {
144
             Dispatcher.Invoke(new Action(() =>
145
             Dispatcher.Invoke(new Action(() =>
145
             {
146
             {

+ 1
- 1
XHWK.WKTool/UploadWindow.xaml View File

93
             Foreground="Black"
93
             Foreground="Black"
94
             ItemsSource="{Binding bookList}"
94
             ItemsSource="{Binding bookList}"
95
             SelectedValuePath="Key"
95
             SelectedValuePath="Key"
96
-            SelectionChanged="toolbar_list_SelectionChanged">
96
+            SelectionChanged="ToolbarListSelectionChanged">
97
             <ComboBox.Resources>
97
             <ComboBox.Resources>
98
                 <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="White" />
98
                 <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="White" />
99
                 <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Gray" />
99
                 <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Gray" />

+ 136
- 115
XHWK.WKTool/UploadWindow.xaml.cs View File

17
     /// <summary>
17
     /// <summary>
18
     /// UploadWindow.xaml 的交互逻辑
18
     /// UploadWindow.xaml 的交互逻辑
19
     /// </summary>
19
     /// </summary>
20
-    public partial class UploadWindow : Window
20
+    public partial class UploadWindow
21
     {
21
     {
22
         /// <summary>
22
         /// <summary>
23
         /// 调用接口
23
         /// 调用接口
24
         /// </summary>
24
         /// </summary>
25
-        private readonly XHApi xhapi = new XHApi();
25
+        private readonly XhApi _xhapi = new XhApi();
26
 
26
 
27
         /// <summary>
27
         /// <summary>
28
         /// 前台数据
28
         /// 前台数据
32
         /// <summary>
32
         /// <summary>
33
         /// 文件名
33
         /// 文件名
34
         /// </summary>
34
         /// </summary>
35
-        private string Resourcename = string.Empty;
35
+        private string _resourcename = string.Empty;
36
 
36
 
37
         /// <summary>
37
         /// <summary>
38
         /// 文件大小
38
         /// 文件大小
39
         /// </summary>
39
         /// </summary>
40
-        private long Resourcesize = 0;
40
+        private long _resourcesize;
41
 
41
 
42
         /// <summary>
42
         /// <summary>
43
         /// 文件类型
43
         /// 文件类型
44
         /// </summary>
44
         /// </summary>
45
-        private string Suffix = string.Empty;
45
+        private string _suffix = string.Empty;
46
 
46
 
47
         /// <summary>
47
         /// <summary>
48
         /// 唯一编号
48
         /// 唯一编号
49
         /// </summary>
49
         /// </summary>
50
-        private string Guid = string.Empty;
50
+        private string _guid = string.Empty;
51
 
51
 
52
         //定义事件
52
         //定义事件
53
         public event ChangeTextHandlers ChangeTextEvents;
53
         public event ChangeTextHandlers ChangeTextEvents;
55
         /// <summary>
55
         /// <summary>
56
         /// 当前视频的下标
56
         /// 当前视频的下标
57
         /// </summary>
57
         /// </summary>
58
-        private int i = 0;
58
+        private int _i;
59
 
59
 
60
-        private System.Timers.Timer times;
60
+        private System.Timers.Timer _times;
61
 
61
 
62
         public UploadWindow()
62
         public UploadWindow()
63
         {
63
         {
67
         /// <summary>
67
         /// <summary>
68
         /// 初始化
68
         /// 初始化
69
         /// </summary>
69
         /// </summary>
70
-        public void Initialize(string _resourcename, long _resourcesize, string _suffix, string _guid, int _i)
70
+        public void Initialize
71
+        (
72
+            string mResourcename,
73
+            long mResourcesize,
74
+            string mSuffix,
75
+            string mGuid,
76
+            int m
77
+        )
71
         {
78
         {
72
-            i = _i;
73
-            Resourcename = _resourcename;
74
-            Resourcesize = _resourcesize;
75
-            Suffix = _suffix;
76
-            Guid = _guid;
79
+            this._i = m;
80
+            this._resourcename = mResourcename;
81
+            this._resourcesize = mResourcesize;
82
+            this._suffix = mSuffix;
83
+            this._guid = mGuid;
77
             tip_outer.Visibility = Visibility.Collapsed;
84
             tip_outer.Visibility = Visibility.Collapsed;
78
             Tsubjectbook();
85
             Tsubjectbook();
79
         }
86
         }
85
         /// </returns>
92
         /// </returns>
86
         private void Tsubjectbook()
93
         private void Tsubjectbook()
87
         {
94
         {
88
-            int code = xhapi.TsubjectbookList();
95
+            int code = _xhapi.TsubjectbookList();
89
             if (code == 0)
96
             if (code == 0)
90
             {
97
             {
91
                 for (int i = 0; i < App.TsubjectbookList.Count; i++)
98
                 for (int i = 0; i < App.TsubjectbookList.Count; i++)
132
             }
139
             }
133
             if (App.TsubjectbookList.Count > selectIndex)
140
             if (App.TsubjectbookList.Count > selectIndex)
134
             {
141
             {
135
-                int code = xhapi.DirectorList
142
+                int code = _xhapi.DirectorList
136
                 (
143
                 (
137
                     App.TsubjectbookList[selectIndex].Lsbid,
144
                     App.TsubjectbookList[selectIndex].Lsbid,
138
                     4,
145
                     4,
162
                                 leaf = item.leaf
169
                                 leaf = item.leaf
163
                             }
170
                             }
164
                         );
171
                         );
165
-                        addChild(item);
172
+                        AddChild(item);
166
                     }
173
                     }
167
                     cmbTeachingMaterial.SelectedIndex = 0;
174
                     cmbTeachingMaterial.SelectedIndex = 0;
168
                 }
175
                 }
178
         /// </summary>
185
         /// </summary>
179
         /// <param name="directorList">
186
         /// <param name="directorList">
180
         /// </param>
187
         /// </param>
181
-        private void addChild(Model_DirectorList directorList)
188
+        private void AddChild(Model_DirectorList directorList)
182
         {
189
         {
183
             if (directorList.children != null && directorList.children.Count > 0)
190
             if (directorList.children != null && directorList.children.Count > 0)
184
             {
191
             {
185
                 foreach (Model_DirectorList child in directorList.children)
192
                 foreach (Model_DirectorList child in directorList.children)
186
                 {
193
                 {
187
-                    pageData.zhangjieList.Add(new ComboBoxBean()
188
-                    {
189
-                        Key = child.directorid,
190
-                        Value = getSpace(child.directorlevel) + child.directorname,
191
-                        leaf = child.leaf
192
-                    });
194
+                    pageData.zhangjieList.Add
195
+                    (
196
+                        new ComboBoxBean()
197
+                        {
198
+                            Key = child.directorid,
199
+                            Value = GetSpace(child.directorlevel) + child.directorname,
200
+                            leaf = child.leaf
201
+                        }
202
+                    );
193
                     if (child.children != null && child.children.Count > 0)
203
                     if (child.children != null && child.children.Count > 0)
194
                     {
204
                     {
195
-                        addChild(child);
205
+                        AddChild(child);
196
                     }
206
                     }
197
                 }
207
                 }
198
             }
208
             }
205
         /// </param>
215
         /// </param>
206
         /// <returns>
216
         /// <returns>
207
         /// </returns>
217
         /// </returns>
208
-        private string getSpace(int num)
218
+        private string GetSpace(int num)
209
         {
219
         {
210
             string str = "";
220
             string str = "";
211
             for (int i = 0; i < num; i++)
221
             for (int i = 0; i < num; i++)
231
         /// </param>
241
         /// </param>
232
         /// <param name="e">
242
         /// <param name="e">
233
         /// </param>
243
         /// </param>
234
-        private void toolbar_list_SelectionChanged(object sender, SelectionChangedEventArgs e)
244
+        private void ToolbarListSelectionChanged(object sender, SelectionChangedEventArgs e)
235
         {
245
         {
236
             if (App.TsubjectbookList.Count > 0)
246
             if (App.TsubjectbookList.Count > 0)
237
             {
247
             {
280
             book_list.IsEnabled = false;
290
             book_list.IsEnabled = false;
281
             cmbTeachingMaterial.IsEnabled = false;
291
             cmbTeachingMaterial.IsEnabled = false;
282
             Thread myThread = new Thread(StartUpload);
292
             Thread myThread = new Thread(StartUpload);
283
-
284
-            num = 0;
293
+            _num = 0;
285
             tip_outer.Visibility = Visibility.Visible;
294
             tip_outer.Visibility = Visibility.Visible;
286
             myThread.Start();
295
             myThread.Start();
287
-            times = new System.Timers.Timer(100);
288
-            times.Elapsed += Times_ElapsedClick;
289
-            times.Start();
296
+            _times = new System.Timers.Timer(100);
297
+            _times.Elapsed += Times_ElapsedClick;
298
+            _times.Start();
290
         }
299
         }
291
 
300
 
292
         private void StartUpload()
301
         private void StartUpload()
293
         {
302
         {
294
             try
303
             try
295
             {
304
             {
296
-                DalUpload dAL_Upload = new DalUpload();
297
-                if (dAL_Upload.UploadVideoTwo(Guid, out string ErrMessage))
305
+                DalUpload dAlUpload = new DalUpload();
306
+                if (dAlUpload.UploadVideoTwo(_guid, out string errMessage))
298
                 {
307
                 {
299
                     //        converted: 0
308
                     //        converted: 0
300
                     //createid: 80
309
                     //createid: 80
314
                     //schoolid: 12
323
                     //schoolid: 12
315
                     //suffix: "mp4"
324
                     //suffix: "mp4"
316
                     //uid: 80
325
                     //uid: 80
317
-                    Model_ResourceAdd model_ResourceAdd = new Model_ResourceAdd();
318
-                    Dispatcher.Invoke(() =>
319
-                    {
320
-                        model_ResourceAdd = new Model_ResourceAdd
326
+                    Model_ResourceAdd modelResourceAdd = new Model_ResourceAdd();
327
+                    Dispatcher.Invoke
328
+                    (
329
+                        () =>
321
                         {
330
                         {
322
-                            converted = 0,
323
-                            createid = App.UserInfo.Userid,
324
-                            directorid = cmbTeachingMaterial.SelectedValue.ToString(),
325
-                            duration = App.ResourceAddTwo.duration,
326
-                            subjectid = App.TsubjectbookList[book_list.SelectedIndex].Subjectid,
327
-                            imgUrl = "",
328
-                            level = 2,
329
-                            lsbid = book_list.SelectedValue.ToString(),
330
-                            mp4code = App.ResourceAddTwo.mp4code,
331
-                            resourcebelong = 3,
332
-                            resourceclass = 5,
333
-                            resourcecover = App.ResourceAddTwo.coverpath,
334
-                            resourcename = Resourcename,
335
-                            resourcesize = Resourcesize,
336
-                            resourcetype = 10,
337
-                            resourceurl = App.ResourceAddTwo.videopath,
338
-                            schoolid = App.UserInfo.Schoolid
339
-                        };
340
-                    });
341
-
342
-                    if (Suffix.Equals("FLV"))
331
+                            modelResourceAdd = new Model_ResourceAdd
332
+                            {
333
+                                converted = 0,
334
+                                createid = App.UserInfo.Userid,
335
+                                directorid = cmbTeachingMaterial.SelectedValue.ToString(),
336
+                                duration = App.ResourceAddTwo.duration,
337
+                                subjectid = App.TsubjectbookList[book_list.SelectedIndex].Subjectid,
338
+                                imgUrl = "",
339
+                                level = 2,
340
+                                lsbid = book_list.SelectedValue.ToString(),
341
+                                mp4code = App.ResourceAddTwo.mp4code,
342
+                                resourcebelong = 3,
343
+                                resourceclass = 5,
344
+                                resourcecover = App.ResourceAddTwo.coverpath,
345
+                                resourcename = _resourcename,
346
+                                resourcesize = _resourcesize,
347
+                                resourcetype = 10,
348
+                                resourceurl = App.ResourceAddTwo.videopath,
349
+                                schoolid = App.UserInfo.Schoolid
350
+                            };
351
+                        }
352
+                    );
353
+                    if (_suffix.Equals("FLV"))
343
                     {
354
                     {
344
-                        Suffix = "flv";
355
+                        _suffix = "flv";
345
                     }
356
                     }
346
-                    else if (Suffix.Equals("AVI"))
357
+                    else if (_suffix.Equals("AVI"))
347
                     {
358
                     {
348
-                        Suffix = "avi";
359
+                        _suffix = "avi";
349
                     }
360
                     }
350
                     else
361
                     else
351
                     {
362
                     {
352
-                        Suffix = "mp4";
363
+                        _suffix = "mp4";
353
                     }
364
                     }
354
-
355
-                    model_ResourceAdd.suffix = Suffix;
365
+                    modelResourceAdd.suffix = _suffix;
356
                     //model_ResourceAdd.uid = 0;//zxy
366
                     //model_ResourceAdd.uid = 0;//zxy
357
-                    int code = xhapi.ResourceAdd(model_ResourceAdd);
367
+                    int code = _xhapi.ResourceAdd(modelResourceAdd);
358
                     if (code == 0)
368
                     if (code == 0)
359
                     {
369
                     {
360
-                        Dispatcher.Invoke(() =>
361
-                        {
362
-                            foreach (Model_WKData Vdata in App.WKDataList)
370
+                        Dispatcher.Invoke
371
+                        (
372
+                            () =>
363
                             {
373
                             {
364
-                                if (Vdata.VideoList == null)
374
+                                foreach (Model_WKData vdata in App.WKDataList)
365
                                 {
375
                                 {
366
-                                    continue;
367
-                                }
368
-                                foreach (Model_Video videoinfo in Vdata.VideoList)
369
-                                {
370
-                                    if (videoinfo.FileGuid == Guid)
376
+                                    if (vdata.VideoList == null)
377
+                                    {
378
+                                        continue;
379
+                                    }
380
+                                    foreach (Model_Video videoinfo in vdata.VideoList)
371
                                     {
381
                                     {
372
-                                        videoinfo.IsUpload = true;
373
-                                        break;
382
+                                        if (videoinfo.FileGuid == _guid)
383
+                                        {
384
+                                            videoinfo.IsUpload = true;
385
+                                            break;
386
+                                        }
374
                                     }
387
                                     }
375
                                 }
388
                                 }
389
+                                btnStart.IsEnabled = true;
390
+                                book_list.IsEnabled = true;
391
+                                cmbTeachingMaterial.IsEnabled = true;
392
+                                _num = 99;
393
+                                _times.Stop();
394
+                                pgbProcess.Value = 100;
395
+                                lbProcess.Content = "100%";
396
+                                MessageWindow.Show("视频上传成功!");
397
+                                tip_outer.Visibility = Visibility.Collapsed;
398
+                                if (ChangeTextEvents != null)
399
+                                {
400
+                                    ChangeTextEvents("上传成功", _i);
401
+                                }
402
+                                Hide();
376
                             }
403
                             }
377
-
378
-                            btnStart.IsEnabled = true;
379
-                            book_list.IsEnabled = true;
380
-                            cmbTeachingMaterial.IsEnabled = true;
381
-                            num = 99;
382
-                            times.Stop();
383
-                            pgbProcess.Value = 100;
384
-                            lbProcess.Content = "100%";
385
-                            MessageWindow.Show("视频上传成功!");
386
-                            tip_outer.Visibility = Visibility.Collapsed;
387
-                            ChangeTextEvents("上传成功", i);
388
-                            Hide();
389
-                        });
404
+                        );
390
                     }
405
                     }
391
                     else
406
                     else
392
                     {
407
                     {
393
-                        Dispatcher.Invoke(() =>
408
+                        Dispatcher.Invoke
409
+                        (
410
+                            () =>
411
+                            {
412
+                                btnStart.IsEnabled = true;
413
+                                book_list.IsEnabled = true;
414
+                                cmbTeachingMaterial.IsEnabled = true;
415
+                                _times.Stop();
416
+                                tip_outer.Visibility = Visibility.Collapsed;
417
+                                MessageWindow.Show(App.ServerMsg);
418
+                            }
419
+                        );
420
+                    }
421
+                }
422
+                else
423
+                {
424
+                    Dispatcher.Invoke
425
+                    (
426
+                        () =>
394
                         {
427
                         {
395
                             btnStart.IsEnabled = true;
428
                             btnStart.IsEnabled = true;
396
                             book_list.IsEnabled = true;
429
                             book_list.IsEnabled = true;
397
                             cmbTeachingMaterial.IsEnabled = true;
430
                             cmbTeachingMaterial.IsEnabled = true;
398
-                            times.Stop();
431
+                            _times.Stop();
399
                             tip_outer.Visibility = Visibility.Collapsed;
432
                             tip_outer.Visibility = Visibility.Collapsed;
400
-                            MessageWindow.Show(App.ServerMsg);
401
-                        });
402
-                    }
403
-                }
404
-                else
405
-                {
406
-                    Dispatcher.Invoke(() =>
407
-                    {
408
-                        btnStart.IsEnabled = true;
409
-                        book_list.IsEnabled = true;
410
-                        cmbTeachingMaterial.IsEnabled = true;
411
-                        times.Stop();
412
-                        tip_outer.Visibility = Visibility.Collapsed;
413
-                        MessageWindow.Show(ErrMessage);
414
-                    });
433
+                            MessageWindow.Show(errMessage);
434
+                        }
435
+                    );
415
                 }
436
                 }
416
             }
437
             }
417
             catch (Exception ex)
438
             catch (Exception ex)
421
                     btnStart.IsEnabled = true;
442
                     btnStart.IsEnabled = true;
422
                     book_list.IsEnabled = true;
443
                     book_list.IsEnabled = true;
423
                     cmbTeachingMaterial.IsEnabled = true;
444
                     cmbTeachingMaterial.IsEnabled = true;
424
-                    times.Stop();
445
+                    _times.Stop();
425
                     tip_outer.Visibility = Visibility.Collapsed;
446
                     tip_outer.Visibility = Visibility.Collapsed;
426
                     MessageWindow.Show("无法上传视频,请检查与服务器链接状态!");
447
                     MessageWindow.Show("无法上传视频,请检查与服务器链接状态!");
427
                     App.IsUpLoad = false;
448
                     App.IsUpLoad = false;
431
             }
452
             }
432
         }
453
         }
433
 
454
 
434
-        private int num = 0;
455
+        private int _num;
435
 
456
 
436
         /// <summary>
457
         /// <summary>
437
         /// 计时器
458
         /// 计时器
444
         {
465
         {
445
             Dispatcher.Invoke(() =>
466
             Dispatcher.Invoke(() =>
446
             {
467
             {
447
-                pgbProcess.Value = num;
448
-                lbProcess.Content = num.ToString() + "%";
449
-                if (num < 99)
468
+                pgbProcess.Value = _num;
469
+                lbProcess.Content = _num.ToString() + "%";
470
+                if (_num < 99)
450
                 {
471
                 {
451
-                    num++;
452
-                    times.Interval += (num / 2);
472
+                    _num++;
473
+                    _times.Interval += _num / 2;
453
                 }
474
                 }
454
                 else
475
                 else
455
                 {
476
                 {
456
-                    times.Stop();
477
+                    _times.Stop();
457
                 }
478
                 }
458
             });
479
             });
459
         }
480
         }

+ 107
- 101
XHWK.WKTool/system/HttpHelper.cs View File

12
 
12
 
13
 namespace Common.system
13
 namespace Common.system
14
 {
14
 {
15
-    using XHWK.WKTool.system;
16
-
17
     /// <summary>
15
     /// <summary>
18
     /// HttpHelper
16
     /// HttpHelper
19
     /// 创建人:赵耀
17
     /// 创建人:赵耀
20
     /// </summary>
18
     /// </summary>
21
     public class HttpHelper
19
     public class HttpHelper
22
     {
20
     {
23
-        public static void init_Request(ref System.Net.HttpWebRequest request)
21
+        public static string tokenKey = "";
22
+        public static string tokenValue = "";
23
+        public static string userId = "";
24
+        public static bool isParameterEncryption = false;
25
+
26
+        public static void InitRequest(ref System.Net.HttpWebRequest request)
24
         {
27
         {
25
             request.Accept = "text/json,*/*;q=0.5";
28
             request.Accept = "text/json,*/*;q=0.5";
26
             request.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7");
29
             request.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7");
36
 
39
 
37
         public static System.Net.HttpWebRequest GetHttpWebRequest(string url)
40
         public static System.Net.HttpWebRequest GetHttpWebRequest(string url)
38
         {
41
         {
39
-            HttpWebRequest request = null;
42
+            HttpWebRequest request;
40
             if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
43
             if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
41
             {
44
             {
42
                 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
45
                 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
57
                 try
60
                 try
58
                 {
61
                 {
59
                     HttpWebRequest request = HttpHelper.GetHttpWebRequest(downloadUrl);
62
                     HttpWebRequest request = HttpHelper.GetHttpWebRequest(downloadUrl);
60
-                    HttpHelper.init_Request(ref request);
63
+                    HttpHelper.InitRequest(ref request);
61
                     request.Accept = "text/json,*/*;q=0.5";
64
                     request.Accept = "text/json,*/*;q=0.5";
62
                     request.AddRange(from, to);
65
                     request.AddRange(from, to);
63
                     request.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7");
66
                     request.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7");
95
                 HttpWebRequest request = GetHttpWebRequest(url);
98
                 HttpWebRequest request = GetHttpWebRequest(url);
96
                 if (request != null)
99
                 if (request != null)
97
                 {
100
                 {
98
-                    string retval = null;
99
-                    init_Request(ref request);
100
-                    using (WebResponse Response = request.GetResponse())
101
+                    string retval;
102
+                    InitRequest(ref request);
103
+                    using (WebResponse response = request.GetResponse())
101
                     {
104
                     {
102
-                        using (StreamReader reader = new System.IO.StreamReader(Response.GetResponseStream(), System.Text.Encoding.UTF8))
105
+                        using (StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
103
                         {
106
                         {
104
                             retval = reader.ReadToEnd();
107
                             retval = reader.ReadToEnd();
105
                         }
108
                         }
121
                 if (request != null)
124
                 if (request != null)
122
                 {
125
                 {
123
                     string retval = null;
126
                     string retval = null;
124
-                    init_Request(ref request);
127
+                    InitRequest(ref request);
125
                     request.Method = "POST";
128
                     request.Method = "POST";
126
                     request.ServicePoint.Expect100Continue = false;
129
                     request.ServicePoint.Expect100Continue = false;
127
                     request.ContentType = "application/json; charset=utf-8";
130
                     request.ContentType = "application/json; charset=utf-8";
128
                     request.Timeout = 5000;
131
                     request.Timeout = 5000;
129
-                    byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(data);
132
+                    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
130
                     request.ContentLength = bytes.Length;
133
                     request.ContentLength = bytes.Length;
131
                     using (Stream stream = request.GetRequestStream())
134
                     using (Stream stream = request.GetRequestStream())
132
                     {
135
                     {
148
             return null;
151
             return null;
149
         }
152
         }
150
 
153
 
151
-        /// <summary>
152
-        ///调用Post接口
153
-        /// </summary>
154
-        /// <param name="request"></param>
155
-        /// <returns></returns>
156
-        public static string HttpPost(string body, string Url)
154
+        ///  <summary>
155
+        /// 调用Post接口
156
+        ///  </summary>
157
+        ///  <returns></returns>
158
+        public static string HttpPost(string body, string url)
157
         {
159
         {
158
             try
160
             try
159
             {
161
             {
160
                 Encoding encoding = Encoding.UTF8;
162
                 Encoding encoding = Encoding.UTF8;
161
-
162
-                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
163
+                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
163
                 request.Method = "POST";
164
                 request.Method = "POST";
164
                 request.Accept = "text/html,application/xhtml+xml,*/*";
165
                 request.Accept = "text/html,application/xhtml+xml,*/*";
165
                 request.ContentType = "application/json";
166
                 request.ContentType = "application/json";
166
-
167
-                string postDataAES = body;
168
-                bool IsParameterEncryption = FileToolsCommon.GetConfigValue("IsParameterEncryption") != "0";
169
-                if (IsParameterEncryption)
167
+                string postDataAes = body;
168
+                if (isParameterEncryption)
170
                 {
169
                 {
171
-                    postDataAES = AESHelper.AESEncrypt(body, "XINGHUOLIAOYUAN7");
170
+                    postDataAes = AESHelper.AESEncrypt(body, "XINGHUOLIAOYUAN7");
171
+                    request.Headers.Add("st", "true");
172
                 }
172
                 }
173
-
174
-                byte[] buffer = encoding.GetBytes(postDataAES);
173
+                else
174
+                {
175
+                    request.Headers.Add("st", "false");
176
+                }
177
+                if (!string.IsNullOrEmpty(tokenKey) && !string.IsNullOrEmpty(tokenValue))
178
+                {
179
+                    request.Headers.Add("Token-Key", tokenKey);
180
+                    request.Headers.Add("Token-Value", tokenValue);
181
+                }
182
+                if (!string.IsNullOrEmpty(userId))
183
+                {
184
+                    request.Headers.Add("User-Id", userId);
185
+                }
186
+                byte[] buffer = encoding.GetBytes(postDataAes);
175
                 request.ContentLength = buffer.Length;
187
                 request.ContentLength = buffer.Length;
176
                 request.GetRequestStream().Write(buffer, 0, buffer.Length);
188
                 request.GetRequestStream().Write(buffer, 0, buffer.Length);
177
 
189
 
201
         {
213
         {
202
             if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(encode) && !string.IsNullOrEmpty(contentType) && postData != null)
214
             if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(encode) && !string.IsNullOrEmpty(contentType) && postData != null)
203
             {
215
             {
204
-                // webRequest.Headers.Add("Authorization", "Bearer " + "SportApiAuthData");
205
-                HttpWebResponse webResponse = null;
206
-                Stream responseStream = null;
207
-                Stream requestStream = null;
208
-                StreamReader streamReader = null;
209
                 try
216
                 try
210
                 {
217
                 {
211
-                    string postDataAES = postData;
212
-                    bool IsParameterEncryption = FileToolsCommon.GetConfigValue("IsParameterEncryption") != "0";
213
-                    if (IsParameterEncryption)
218
+                    string postDataAes = postData;
219
+                    if (isParameterEncryption)
214
                     {
220
                     {
215
-                        postDataAES = AESHelper.AESEncrypt(postData, "XINGHUOLIAOYUAN7");
221
+                        postDataAes = AESHelper.AESEncrypt(postDataAes, "XINGHUOLIAOYUAN7");
216
                     }
222
                     }
217
-                    string respstr = GetStreamReader(url, responseStream, requestStream, streamReader, webResponse, timeout, encode, postDataAES, contentType);
223
+                    string respstr = GetStreamReader
224
+                    (
225
+                        url,
226
+                        null,
227
+                        null,
228
+                        null,
229
+                        null,
230
+                        timeout,
231
+                        encode,
232
+                        postDataAes,
233
+                        contentType
234
+                    );
218
                     return JsonHelper.JsonToObj<T>(respstr);
235
                     return JsonHelper.JsonToObj<T>(respstr);
219
                 }
236
                 }
220
                 catch (Exception)
237
                 catch (Exception)
221
                 {
238
                 {
222
-                }
223
-                finally
224
-                {
225
-                    if (responseStream != null)
226
-                    {
227
-                        responseStream.Dispose();
228
-                    }
229
-
230
-                    if (webResponse != null)
231
-                    {
232
-                        webResponse.Close();
233
-                    }
234
-
235
-                    if (requestStream != null)
236
-                    {
237
-                        requestStream.Dispose();
238
-                    }
239
-
240
-                    if (streamReader != null)
241
-                    {
242
-                        streamReader.Dispose();
243
-                    }
239
+                    // ignored
244
                 }
240
                 }
245
             }
241
             }
246
             return default(T);
242
             return default(T);
256
                 webRequest.ContentType = contentType + ";" + encode;
252
                 webRequest.ContentType = contentType + ";" + encode;
257
                 webRequest.ContentLength = data.Length;
253
                 webRequest.ContentLength = data.Length;
258
                 webRequest.Timeout = timeout;
254
                 webRequest.Timeout = timeout;
255
+                if (isParameterEncryption)
256
+                {
257
+                    webRequest.Headers.Add("st", "true");
258
+                }
259
+                else
260
+                {
261
+                    webRequest.Headers.Add("st", "false");
262
+                }
263
+                if (!string.IsNullOrEmpty(tokenKey) && !string.IsNullOrEmpty(tokenValue))
264
+                {
265
+                    webRequest.Headers.Add("Token-Key", tokenKey);
266
+                    webRequest.Headers.Add("Token-Value", tokenValue);
267
+                }
268
+                if (!string.IsNullOrEmpty(userId))
269
+                {
270
+                    webRequest.Headers.Add("User-Id", userId);
271
+                }
259
                 requestStream = webRequest.GetRequestStream();
272
                 requestStream = webRequest.GetRequestStream();
260
                 requestStream.Write(data, 0, data.Length);
273
                 requestStream.Write(data, 0, data.Length);
261
                 webResponse = (HttpWebResponse)webRequest.GetResponse();
274
                 webResponse = (HttpWebResponse)webRequest.GetResponse();
282
         /// <param name="strcontent">头</param>
295
         /// <param name="strcontent">头</param>
283
         /// <param name="contenttype">参数</param>
296
         /// <param name="contenttype">参数</param>
284
         /// <param name="header">token</param>
297
         /// <param name="header">token</param>
298
+        /// <param name="timeout"></param>
285
         /// <returns></returns>
299
         /// <returns></returns>
286
-        public static JObject GetFunction(string serviceaddress, string strcontent, string contenttype, string header, int Timeout = 5000)
300
+        public static JObject GetFunction
301
+        (
302
+            string serviceaddress,
303
+            string strcontent,
304
+            string contenttype,
305
+            string header,
306
+            int timeout = 5000
307
+        )
287
         {
308
         {
288
             try
309
             try
289
             {
310
             {
301
                 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
322
                 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
302
 
323
 
303
                 string encoding = response.ContentEncoding;
324
                 string encoding = response.ContentEncoding;
304
-                if (encoding == null || encoding.Length < 1)
325
+                if (encoding.Length < 1)
305
                 {
326
                 {
306
                     encoding = "UTF-8"; //默认编码
327
                     encoding = "UTF-8"; //默认编码
307
                 }
328
                 }
609
         {
630
         {
610
             if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(encode) && !string.IsNullOrEmpty(contentType) && postData != null)
631
             if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(encode) && !string.IsNullOrEmpty(contentType) && postData != null)
611
             {
632
             {
612
-                HttpWebResponse webResponse = null;
613
-                Stream responseStream = null;
614
-                Stream requestStream = null;
615
-                StreamReader streamReader = null;
616
                 try
633
                 try
617
                 {
634
                 {
618
-                    string postDataAES = postData;
619
-                    bool IsParameterEncryption = FileToolsCommon.GetConfigValue("IsParameterEncryption") != "0";
620
-                    if (IsParameterEncryption)
635
+                    string postDataAes = postData;
636
+                    if (isParameterEncryption)
621
                     {
637
                     {
622
-                        postDataAES = AESHelper.AESEncrypt(postData, "XINGHUOLIAOYUAN7");
638
+                        postDataAes = AESHelper.AESEncrypt(postData, "XINGHUOLIAOYUAN7");
623
                     }
639
                     }
624
-                    return GetStreamReader(url, responseStream, requestStream, streamReader, webResponse, timeout, encode, postDataAES, contentType);
640
+                    return GetStreamReader
641
+                    (
642
+                        url,
643
+                        null,
644
+                        null,
645
+                        null,
646
+                        null,
647
+                        timeout,
648
+                        encode,
649
+                        postDataAes,
650
+                        contentType
651
+                    );
625
                 }
652
                 }
626
                 catch (Exception)
653
                 catch (Exception)
627
                 {
654
                 {
628
-                }
629
-                finally
630
-                {
631
-                    if (responseStream != null)
632
-                    {
633
-                        responseStream.Dispose();
634
-                    }
635
-
636
-                    if (webResponse != null)
637
-                    {
638
-                        webResponse.Close();
639
-                    }
640
-
641
-                    if (requestStream != null)
642
-                    {
643
-                        requestStream.Dispose();
644
-                    }
645
-
646
-                    if (streamReader != null)
647
-                    {
648
-                        streamReader.Dispose();
649
-                    }
655
+                    // ignored
650
                 }
656
                 }
651
             }
657
             }
652
             return null;
658
             return null;
655
         /// <summary>
661
         /// <summary>
656
         /// 获取公网IP和地址,失败则获取局域网IP
662
         /// 获取公网IP和地址,失败则获取局域网IP
657
         /// </summary>
663
         /// </summary>
658
-        /// <param name="AddressIP">IP地址</param>
659
-        /// <param name="Address">地址</param>
664
+        /// <param name="addressIp">IP地址</param>
665
+        /// <param name="address">地址</param>
660
         /// <returns></returns>
666
         /// <returns></returns>
661
-        public static bool GetAddressIP(out string AddressIP, out string Address)
667
+        public static bool GetAddressIp(out string addressIp, out string address)
662
         {
668
         {
663
-            AddressIP = "";
664
-            Address = "";
669
+            addressIp = "";
670
+            address = "";
665
             try
671
             try
666
             {
672
             {
667
                 //请求搜狐获取公网IP,获取失败后获取局域网IP
673
                 //请求搜狐获取公网IP,获取失败后获取局域网IP
673
                 string htmlinfo = sr.ReadToEnd();
679
                 string htmlinfo = sr.ReadToEnd();
674
                 string jsonStr = htmlinfo.Substring(htmlinfo.IndexOf("{"), htmlinfo.LastIndexOf("}") - htmlinfo.IndexOf("{") + 1);
680
                 string jsonStr = htmlinfo.Substring(htmlinfo.IndexOf("{"), htmlinfo.LastIndexOf("}") - htmlinfo.IndexOf("{") + 1);
675
                 JObject obj = JObject.Parse(jsonStr);
681
                 JObject obj = JObject.Parse(jsonStr);
676
-                AddressIP = obj["cip"].ToString();
677
-                Address = obj["cname"].ToString();
682
+                addressIp = obj["cip"].ToString();
683
+                address = obj["cname"].ToString();
678
                 resStream.Close();
684
                 resStream.Close();
679
                 sr.Close();
685
                 sr.Close();
680
                 return true;
686
                 return true;
685
             catch (Exception)
691
             catch (Exception)
686
             {
692
             {
687
                 //获取本地局域网IP
693
                 //获取本地局域网IP
688
-                foreach (System.Net.IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
694
+                foreach (System.Net.IPAddress ipAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
689
                 {
695
                 {
690
-                    if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
696
+                    if (ipAddress.AddressFamily.ToString() == "InterNetwork")
691
                     {
697
                     {
692
-                        AddressIP = _IPAddress.ToString();
698
+                        addressIp = ipAddress.ToString();
693
                     }
699
                     }
694
                 }
700
                 }
695
                 return false;
701
                 return false;

+ 1
- 1
星火微课/星火微课-测试.iss View File

3
 
3
 
4
 #define MyAppName "星火微课测试版"  
4
 #define MyAppName "星火微课测试版"  
5
 #define MyAppDir "xhwk_test"
5
 #define MyAppDir "xhwk_test"
6
-#define MyAppVersion "3.9.8"
6
+#define MyAppVersion "3.12.0"
7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
8
 #define MyAppURL "http://www.xhkjedu.com/"
8
 #define MyAppURL "http://www.xhkjedu.com/"
9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"
9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"

Loading…
Cancel
Save