浏览代码

解决参数中文乱码的问题

master
张剑 1年前
父节点
当前提交
5ed04dfc8b
共有 3 个文件被更改,包括 13 次插入49 次删除
  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 查看文件

@@ -21,19 +21,11 @@ namespace Common
21 21
                 key = QrcodeLoginKey.PadRight(16, '0');
22 22
             }
23 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 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 29
             return BytesToHexString(resultArray);
38 30
         }
39 31
 
@@ -50,20 +42,12 @@ namespace Common
50 42
                 key = QrcodeLoginKey.PadRight(16, '0');
51 43
             }
52 44
             // 256-AES key      
53
-            byte[] keyArray = Encoding.ASCII.GetBytes(key);
45
+            byte[] keyArray = Encoding.UTF8.GetBytes(key);
54 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 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 53
         /// <summary>
@@ -108,4 +92,4 @@ namespace Common
108 92
             return d;
109 93
         }
110 94
     }
111
-}
95
+}

+ 1
- 22
XHWK.WKTool/DAL/XHApi.cs 查看文件

@@ -226,28 +226,7 @@ namespace XHWK.WKTool.DAL
226 226
             try
227 227
             {
228 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 230
                 if (model.directorid != "999999") //章节上传可以不选
252 231
                 {
253 232
                     dic.Add("directorid", model.directorid);

+ 3
- 2
XHWK.WKTool/Utils/ZHttpUtil.cs 查看文件

@@ -113,11 +113,11 @@
113 113
             Stream responseStream = null;
114 114
             try
115 115
             {
116
-                Encoding encoding = Encoding.UTF8;
117 116
                 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
118 117
                 webRequest.Method = "POST";
119 118
                 webRequest.Accept = "text/html,application/xhtml+xml,*/*";
120 119
                 webRequest.ContentType = contentType + ";" + "UTF-8";
120
+                Console.WriteLine(@"postData:" + postData);
121 121
                 string aesPostData = postData;
122 122
                 if (jm)
123 123
                 {
@@ -126,8 +126,9 @@
126 126
                         aesPostData = AesHelper.AesEncrypt(postData, "XINGHUOLIAOYUAN7");
127 127
                     }
128 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 132
                 webRequest.ContentLength = buffer.Length;
132 133
                 webRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
133 134
                 HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

正在加载...
取消
保存