Browse Source

解决参数中文乱码的问题

master
张剑 1 year ago
parent
commit
5ed04dfc8b
3 changed files with 13 additions and 49 deletions
  1. 9
    25
      XHWK.WKTool/AESHelper.cs
  2. 1
    22
      XHWK.WKTool/DAL/XHApi.cs
  3. 3
    2
      XHWK.WKTool/Utils/ZHttpUtil.cs

+ 9
- 25
XHWK.WKTool/AESHelper.cs View File

21
                 key = QrcodeLoginKey.PadRight(16, '0');
21
                 key = QrcodeLoginKey.PadRight(16, '0');
22
             }
22
             }
23
             // 256-AES key      
23
             // 256-AES key      
24
-            byte[] keyArray = Encoding.ASCII.GetBytes(key);
25
-            byte[] toEncryptArray = Encoding.ASCII.GetBytes(data);
26
-            RijndaelManaged rDel = new RijndaelManaged
27
-            {
28
-                Key = keyArray,
29
-                Mode = CipherMode.ECB,
30
-                Padding = PaddingMode.PKCS7
31
-            };
32
-
24
+            byte[] keyArray = Encoding.UTF8.GetBytes(key);
25
+            byte[] toEncryptArray = Encoding.UTF8.GetBytes(data);
26
+            RijndaelManaged rDel = new RijndaelManaged { Key = keyArray, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 };
33
             ICryptoTransform cTransform = rDel.CreateEncryptor();
27
             ICryptoTransform cTransform = rDel.CreateEncryptor();
34
-            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0,
35
-                    toEncryptArray.Length);
36
-
28
+            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
37
             return BytesToHexString(resultArray);
29
             return BytesToHexString(resultArray);
38
         }
30
         }
39
 
31
 
50
                 key = QrcodeLoginKey.PadRight(16, '0');
42
                 key = QrcodeLoginKey.PadRight(16, '0');
51
             }
43
             }
52
             // 256-AES key      
44
             // 256-AES key      
53
-            byte[] keyArray = Encoding.ASCII.GetBytes(key);
45
+            byte[] keyArray = Encoding.UTF8.GetBytes(key);
54
             byte[] toEncryptArray = HexStringToBytes(hexString);
46
             byte[] toEncryptArray = HexStringToBytes(hexString);
55
-
56
-            RijndaelManaged rDel = new RijndaelManaged
57
-            {
58
-                Key = keyArray,
59
-                Mode = CipherMode.ECB,
60
-                Padding = PaddingMode.PKCS7
61
-            };
62
-
47
+            RijndaelManaged rDel = new RijndaelManaged { Key = keyArray, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 };
63
             ICryptoTransform cTransform = rDel.CreateDecryptor();
48
             ICryptoTransform cTransform = rDel.CreateDecryptor();
64
-            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0,
65
-                    toEncryptArray.Length);
66
-            return Encoding.ASCII.GetString(resultArray);
49
+            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
50
+            return Encoding.UTF8.GetString(resultArray);
67
         }
51
         }
68
 
52
 
69
         /// <summary>
53
         /// <summary>
108
             return d;
92
             return d;
109
         }
93
         }
110
     }
94
     }
111
-}
95
+}

+ 1
- 22
XHWK.WKTool/DAL/XHApi.cs View File

226
             try
226
             try
227
             {
227
             {
228
                 string url = App.apiUrl + "/sstudy/resource/add"; //地址
228
                 string url = App.apiUrl + "/sstudy/resource/add"; //地址
229
-                Dictionary<string, object> dic = new Dictionary<string, object>
230
-                {
231
-                    //            converted: 0
232
-                    //createid: 80
233
-                    //directorid: 1009
234
-                    //duration: 39
235
-                    //imgUrl: ""
236
-                    //level: 2
237
-                    //lsbid: 40
238
-                    //mp4code: "h264"
239
-                    //resourcebelong: 3
240
-                    //resourceclass: 2
241
-                    //resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg"
242
-                    //resourcename: "weather_pic"
243
-                    //resourcesize: 6105268
244
-                    //resourcetype: 0
245
-                    //resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4"
246
-                    //schoolid: 12
247
-                    //suffix: "mp4"
248
-                    //uid: 80
249
-                    { "converted", model.converted }, { "createid", model.createid }
250
-                };
229
+                Dictionary<string, object> dic = new Dictionary<string, object> { { "converted", model.converted }, { "createid", model.createid } };
251
                 if (model.directorid != "999999") //章节上传可以不选
230
                 if (model.directorid != "999999") //章节上传可以不选
252
                 {
231
                 {
253
                     dic.Add("directorid", model.directorid);
232
                     dic.Add("directorid", model.directorid);

+ 3
- 2
XHWK.WKTool/Utils/ZHttpUtil.cs View File

113
             Stream responseStream = null;
113
             Stream responseStream = null;
114
             try
114
             try
115
             {
115
             {
116
-                Encoding encoding = Encoding.UTF8;
117
                 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
116
                 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
118
                 webRequest.Method = "POST";
117
                 webRequest.Method = "POST";
119
                 webRequest.Accept = "text/html,application/xhtml+xml,*/*";
118
                 webRequest.Accept = "text/html,application/xhtml+xml,*/*";
120
                 webRequest.ContentType = contentType + ";" + "UTF-8";
119
                 webRequest.ContentType = contentType + ";" + "UTF-8";
120
+                Console.WriteLine(@"postData:" + postData);
121
                 string aesPostData = postData;
121
                 string aesPostData = postData;
122
                 if (jm)
122
                 if (jm)
123
                 {
123
                 {
126
                         aesPostData = AesHelper.AesEncrypt(postData, "XINGHUOLIAOYUAN7");
126
                         aesPostData = AesHelper.AesEncrypt(postData, "XINGHUOLIAOYUAN7");
127
                     }
127
                     }
128
                     AddHeader(webRequest);
128
                     AddHeader(webRequest);
129
+                    Console.WriteLine(@"加密再解密后:" + AesHelper.AesDecrypt(aesPostData, "XINGHUOLIAOYUAN7"));
129
                 }
130
                 }
130
-                byte[] buffer = encoding.GetBytes(aesPostData);
131
+                byte[] buffer = Encoding.UTF8.GetBytes(aesPostData);
131
                 webRequest.ContentLength = buffer.Length;
132
                 webRequest.ContentLength = buffer.Length;
132
                 webRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
133
                 webRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
133
                 HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
134
                 HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

Loading…
Cancel
Save