Function.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. using System;
  2. using System.Data;
  3. using System.Web;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.Security.Cryptography;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Net.Mail;
  10. using System.Net;
  11. using LitJson;
  12. using Microsoft.AspNetCore.Http;
  13. using ThoughtWorks.QRCode.Codec;
  14. using System.Linq;
  15. using System.IO;
  16. namespace Common
  17. {
  18. public class Function
  19. {
  20. /// <summary>
  21. /// hmacSha1算法加密(生成长度40)
  22. /// </summary>
  23. /// <param name="encryptText">加密明文</param>
  24. /// <param name="encryptKey">加密密钥</param>
  25. /// <returns></returns>
  26. public static string hmacSha1(string encryptText, string encryptKey)
  27. {
  28. HMACSHA1 myHMACSHA1 = new HMACSHA1(Encoding.UTF8.GetBytes(encryptKey));
  29. byte[] RstRes = myHMACSHA1.ComputeHash(Encoding.UTF8.GetBytes(encryptText));
  30. StringBuilder EnText = new StringBuilder();
  31. foreach (byte Byte in RstRes)
  32. {
  33. EnText.AppendFormat("{0:x2}", Byte);
  34. }
  35. return EnText.ToString();
  36. }
  37. public static string hmacmd5(string encryptText, string encryptKey)
  38. {
  39. HMACMD5 myHMACSHA1 = new HMACMD5(Encoding.UTF8.GetBytes(encryptKey));
  40. byte[] RstRes = myHMACSHA1.ComputeHash(Encoding.UTF8.GetBytes(encryptText));
  41. StringBuilder EnText = new StringBuilder();
  42. foreach (byte Byte in RstRes)
  43. {
  44. EnText.AppendFormat("{0:x2}", Byte);
  45. }
  46. return EnText.ToString();
  47. }
  48. /// <summary>
  49. /// MD5 32位加密字符串
  50. /// </summary>
  51. /// <param name="str"></param>
  52. /// <returns></returns>
  53. public static string MD5_32(string str)
  54. {
  55. string cl = str + "@$1212#";
  56. string pwd = "";
  57. MD5 md5 = MD5.Create();//实例化一个md5对像
  58. // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 
  59. byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
  60. // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
  61. for (int i = 0; i < s.Length; i++)
  62. {
  63. // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
  64. pwd = pwd + s[i].ToString("X").ToLower().PadLeft(2, '0');
  65. }
  66. return pwd;
  67. }
  68. public static string MD532(string str)
  69. {
  70. string cl = str;
  71. string pwd = "";
  72. MD5 md5 = MD5.Create();//实例化一个md5对像
  73. // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 
  74. byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
  75. // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
  76. for (int i = 0; i < s.Length; i++)
  77. {
  78. // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
  79. pwd = pwd + s[i].ToString("X").ToLower().PadLeft(2, '0');
  80. }
  81. return pwd;
  82. }
  83. /// <summary>
  84. /// 获取MD5值
  85. /// </summary>
  86. /// <param name="str">加密的字符串</param>
  87. /// <returns>返回MD5值</returns>
  88. public static string MD5_16(string str)
  89. {
  90. return MD5_32(str).Substring(8, 16);
  91. }
  92. /// <summary>
  93. /// 写日志(错误报告)
  94. /// </summary>
  95. /// <param name="str"></param>
  96. public static void WriteLog(string str)
  97. {
  98. try
  99. {
  100. string path = getPath("/log/message/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/");
  101. if (!Directory.Exists(path))
  102. {
  103. Directory.CreateDirectory(path);
  104. }
  105. StreamWriter sw = File.AppendText(path + "content.log");
  106. sw.WriteLine(str);
  107. sw.Flush();
  108. sw.Dispose();
  109. }
  110. catch
  111. { }
  112. }
  113. /// <summary>
  114. /// 写日志(错误报告)
  115. /// </summary>
  116. /// <param name="str"></param>
  117. public static void WriteLog(string str, string filename)
  118. {
  119. try
  120. {
  121. string path = getPath("/log/" + filename + "/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/");
  122. if (!Directory.Exists(path))
  123. {
  124. Directory.CreateDirectory(path);
  125. }
  126. StreamWriter sw = File.AppendText(path + "content.log");
  127. sw.WriteLine(str);
  128. sw.Flush();
  129. sw.Dispose();
  130. }
  131. catch
  132. { }
  133. }
  134. public static void WriteLog(string path_str, string file_name, string page_content)
  135. {
  136. try
  137. {
  138. string path = getPath(path_str);
  139. if (!Directory.Exists(path))
  140. {
  141. Directory.CreateDirectory(path);
  142. }
  143. StreamWriter sw = File.AppendText(path + "/" + file_name);
  144. sw.WriteLine(page_content);
  145. sw.Flush();
  146. sw.Dispose();
  147. }
  148. catch
  149. { }
  150. }
  151. /// <summary>
  152. /// 过滤html代码
  153. /// </summary>
  154. /// <param name="Htmlstring"></param>
  155. public static string NoHTML(string Htmlstring) //去除HTML标记
  156. {
  157. if (Htmlstring == null || Htmlstring == string.Empty)
  158. {
  159. return "";
  160. }
  161. Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
  162. Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
  163. //Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
  164. Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
  165. Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
  166. Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
  167. Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
  168. Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
  169. Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
  170. Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
  171. Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
  172. Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
  173. Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
  174. Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
  175. Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
  176. Htmlstring = Regex.Replace(Htmlstring, @"&.*?;", "", RegexOptions.IgnoreCase);
  177. Htmlstring = Htmlstring.Replace("<", "〈");
  178. Htmlstring = Htmlstring.Replace(">", "〉");
  179. //Htmlstring = Htmlstring.Replace("\r\n", "");
  180. //Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
  181. return Htmlstring;
  182. }
  183. public static bool IsIncludeChinese(string str)
  184. {
  185. Regex r = new Regex(@"[\u4E00-\u9FA5]", RegexOptions.IgnoreCase);
  186. if (r.IsMatch(str))
  187. {
  188. return true;
  189. }
  190. else
  191. {
  192. return false;
  193. }
  194. }
  195. public static bool IsInt(string numberString)
  196. {
  197. if (string.IsNullOrEmpty(numberString))
  198. {
  199. return false;
  200. }
  201. Regex rCode = new Regex("^\\d+$");
  202. if (!rCode.IsMatch(numberString))
  203. {
  204. return false;
  205. }
  206. else
  207. {
  208. return true;
  209. }
  210. }
  211. public static string CheckInt(string numberString)
  212. {
  213. if (string.IsNullOrEmpty(numberString))
  214. {
  215. return "0";
  216. }
  217. Regex rCode = new Regex("^\\d+$");
  218. if (!rCode.IsMatch(numberString))
  219. {
  220. return "0";
  221. }
  222. else
  223. {
  224. return numberString;
  225. }
  226. }
  227. public static DateTime CheckDateTime(string numberString)
  228. {
  229. if (string.IsNullOrEmpty(numberString))
  230. {
  231. return DateTime.Now;
  232. }
  233. DateTime result;
  234. if (DateTime.TryParse(numberString, out result))
  235. {
  236. return result;
  237. }
  238. else
  239. {
  240. return DateTime.Now;
  241. }
  242. }
  243. public static bool ChkDateTime(string numberString)
  244. {
  245. if (string.IsNullOrEmpty(numberString))
  246. {
  247. return false;
  248. }
  249. DateTime result;
  250. if (DateTime.TryParse(numberString, out result))
  251. {
  252. return true;
  253. }
  254. else
  255. {
  256. return false;
  257. }
  258. }
  259. public static string CheckNull(string numberString)
  260. {
  261. if (string.IsNullOrEmpty(numberString))
  262. {
  263. return "";
  264. }
  265. else
  266. {
  267. return numberString;
  268. }
  269. }
  270. public static string CheckUrl(string str)
  271. {
  272. if (str == null || str == string.Empty)
  273. {
  274. return "";
  275. }
  276. Regex rCode = new Regex(@"((http|ftp|https)://)(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\&%_\./-~-]*)?");
  277. if (!rCode.IsMatch(str))
  278. {
  279. return "";
  280. }
  281. else
  282. {
  283. return str;
  284. }
  285. }
  286. public static string CheckEmail(string str)
  287. {
  288. if (str == null || str == string.Empty)
  289. {
  290. return "";
  291. }
  292. Regex rCode = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
  293. if (!rCode.IsMatch(str))
  294. {
  295. return "";
  296. }
  297. else
  298. {
  299. return str;
  300. }
  301. }
  302. public static string CheckMobile(string str)
  303. {
  304. if (str == null || str == string.Empty)
  305. {
  306. return "";
  307. }
  308. Regex rCode = new Regex(@"^1[3456789]\d{9}$");
  309. if (!rCode.IsMatch(str))
  310. {
  311. return "";
  312. }
  313. else
  314. {
  315. return str;
  316. }
  317. }
  318. public static string CheckIdCard(string str)
  319. {
  320. if (str == null || str == string.Empty)
  321. {
  322. return "";
  323. }
  324. Regex rCode = new Regex(@"^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$");
  325. if (!rCode.IsMatch(str))
  326. {
  327. return "";
  328. }
  329. else
  330. {
  331. return str;
  332. }
  333. }
  334. public static bool IsNum(string numberString)
  335. {
  336. if (string.IsNullOrEmpty(numberString))
  337. {
  338. return false;
  339. }
  340. Regex rCode = new Regex(@"^\d+(\.\d+)?$");
  341. if (!rCode.IsMatch(numberString))
  342. {
  343. return false;
  344. }
  345. else
  346. {
  347. return true;
  348. }
  349. }
  350. public static string CheckNum(string numberString)
  351. {
  352. if (string.IsNullOrEmpty(numberString))
  353. {
  354. return "0";
  355. }
  356. Regex rCode = new Regex(@"^\d+(\.\d+)?$");
  357. if (!rCode.IsMatch(numberString))
  358. {
  359. return "0";
  360. }
  361. else
  362. {
  363. return numberString;
  364. }
  365. }
  366. public static string CheckString(string str)
  367. {
  368. if (string.IsNullOrEmpty(str))
  369. {
  370. return "";
  371. }
  372. str = str.Replace("'", "&acute;");
  373. str = str.Replace("\"", "&quot;");
  374. //str = str.Replace(" ", "&nbsp;");
  375. str = str.Replace("<", "&lt;");
  376. str = str.Replace(">", "&gt;");
  377. str = str.Replace("(", "(");
  378. str = str.Replace(")", ")");
  379. str = ToDBC(str);
  380. return str;
  381. }
  382. public static string unCheckString(string str)
  383. {
  384. if (str == null || str == string.Empty)
  385. {
  386. return "";
  387. }
  388. str = str.Replace("&acute;", "'");
  389. str = str.Replace("&quot;", "\"");
  390. //str = str.Replace("&nbsp;", " ");
  391. str = str.Replace("&lt;", "<");
  392. str = str.Replace("&gt;", ">");
  393. str = str.Replace("(", "(");
  394. str = str.Replace(")", ")");
  395. return str;
  396. }
  397. public static string CheckString2(string str)
  398. {
  399. if (str == null || str == string.Empty)
  400. {
  401. return "";
  402. }
  403. str = ToDBC(str);
  404. str = Regex.Replace(str, @"<script.*?>[\s\S]*?</script>", "", RegexOptions.IgnoreCase);
  405. str = Regex.Replace(str, @"<script.*?>", "", RegexOptions.IgnoreCase);
  406. str = Regex.Replace(str, @"<object.*?>[\s\S]*?</object>", "", RegexOptions.IgnoreCase);
  407. str = Regex.Replace(str, @"<object.*?>", "", RegexOptions.IgnoreCase);
  408. str = Regex.Replace(str, @"<iframe.*?>[\s\S]*?</iframe>", "", RegexOptions.IgnoreCase);
  409. str = Regex.Replace(str, @"<frameset.*?>[\s\S]*?</frameset>", "", RegexOptions.IgnoreCase);
  410. str = Regex.Replace(str, @"<frameset.*?>", "", RegexOptions.IgnoreCase);
  411. str = Regex.Replace(str, @"<frame.*?>[\s\S]*?</frame>", "", RegexOptions.IgnoreCase);
  412. str = Regex.Replace(str, @"<frame.*?>", "", RegexOptions.IgnoreCase);
  413. str = Regex.Replace(str, @"<form.*?>[\s\S]*?</form>", "", RegexOptions.IgnoreCase);
  414. str = Regex.Replace(str, @"<input.*?>", "", RegexOptions.IgnoreCase);
  415. str = Regex.Replace(str, @"<select.*?>[\s\S]*?</select>", "", RegexOptions.IgnoreCase);
  416. str = Regex.Replace(str, @"<textarea.*?>[\s\S]*?</textarea>", "", RegexOptions.IgnoreCase);
  417. str = Regex.Replace(str, @"<button.*?>", "", RegexOptions.IgnoreCase);
  418. str = Regex.Replace(str, @"<noframes.*?>[\s\S]*?</noframes>", "", RegexOptions.IgnoreCase);
  419. str = Regex.Replace(str, @"<noframes.*?>", "", RegexOptions.IgnoreCase);
  420. return str;
  421. }
  422. public static string GetSession(HttpContext context, string strName)
  423. {
  424. var value = context.Session.GetString(strName);
  425. if (string.IsNullOrEmpty(value))
  426. {
  427. value = "";
  428. }
  429. return value;
  430. }
  431. public static void WriteSession(HttpContext context, string strName, string strValue)
  432. {
  433. context.Session.SetString(strName, strValue);
  434. }
  435. public static void DelSession(HttpContext context, string strName)
  436. {
  437. context.Session.Remove(strName);
  438. }
  439. public static string rootIndex = System.AppDomain.CurrentDomain.BaseDirectory;
  440. private static string Read(string absoluteFileLocation)
  441. {
  442. string result = "";
  443. if (System.IO.File.Exists(absoluteFileLocation))
  444. {
  445. using (FileStream fs = new FileStream(absoluteFileLocation, FileMode.Open, FileAccess.Read))
  446. {
  447. using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8))
  448. {
  449. try
  450. {
  451. result = sr.ReadToEnd();
  452. //dbconn.InsertCache(absoluteFileLocation, result, 30);
  453. }
  454. catch
  455. { }
  456. }
  457. }
  458. }
  459. return result;
  460. }
  461. public static string getPath(string path_str)
  462. {
  463. string result = AppContext.BaseDirectory + path_str;
  464. return result;
  465. }
  466. public static string ReadInstance(string path_str)
  467. {
  468. //string path = System.IO.Path.Combine(rootIndex, path_str).Replace('/', System.IO.Path.DirectorySeparatorChar);
  469. string path = getPath(path_str);
  470. string content = "";
  471. content = Read(path);
  472. return content;
  473. }
  474. public static string ReadInstanceNoAuth(string path_str)
  475. {
  476. //string path = System.IO.Path.Combine(rootIndex, path_str).Replace('/', System.IO.Path.DirectorySeparatorChar);
  477. string path = getPath(path_str);
  478. string content = "";
  479. content = Read(path);
  480. return content;
  481. }
  482. public static string ReadInstanceByFull(string path_str)
  483. {
  484. string content = "";
  485. content = Read(path_str);
  486. return content;
  487. }
  488. public static void WritePage(string path_str, string file_name, string page_content)
  489. {
  490. try
  491. {
  492. string path = getPath(path_str);
  493. if (!Directory.Exists(path))
  494. {
  495. Directory.CreateDirectory(path);
  496. }
  497. Encoding nobom = new UTF8Encoding(false, false);
  498. StreamWriter sw = new StreamWriter(path + "/" + file_name, false, nobom);
  499. sw.Write(page_content);
  500. sw.Flush();
  501. sw.Dispose();
  502. }
  503. catch
  504. { }
  505. }
  506. public static void WritePageFullPath(string path_str, string file_name, string page_content)
  507. {
  508. try
  509. {
  510. if (!Directory.Exists(path_str))
  511. {
  512. Directory.CreateDirectory(path_str);
  513. }
  514. Encoding nobom = new UTF8Encoding(false, false);
  515. StreamWriter sw = new StreamWriter(path_str + file_name, false, nobom);
  516. sw.Write(page_content);
  517. sw.Flush();
  518. sw.Dispose();
  519. }
  520. catch
  521. { }
  522. }
  523. public static void send_email(string mailTitle, string mailTo, string mailContent, string file_path, string host, int port, string username, string pwd, string displayname)
  524. {
  525. try
  526. {
  527. MailAddress from = new MailAddress(username, displayname); //邮件的发件人
  528. MailMessage mail = new MailMessage();
  529. //设置邮件的标题
  530. mail.Subject = mailTitle;
  531. mail.SubjectEncoding = Encoding.UTF8;
  532. //设置邮件的发件人
  533. //Pass:如果不想显示自己的邮箱地址,这里可以填符合mail格式的任意名称,真正发mail的用户不在这里设定,这个仅仅只做显示用
  534. mail.From = from;
  535. //设置邮件的收件人
  536. string address = "";
  537. string displayName = "";
  538. /**/
  539. /* 这里这样写是因为可能发给多个联系人,每个地址用 ; 号隔开
  540. 一般从地址簿中直接选择联系人的时候格式都会是 :用户名1 < mail1 >; 用户名2 < mail 2>;
  541. 因此就有了下面一段逻辑不太好的代码
  542. 如果永远都只需要发给一个收件人那么就简单了 mail.To.Add("收件人mail");
  543. */
  544. string[] mailNames = (mailTo + ";").Split(';');
  545. foreach (string name in mailNames)
  546. {
  547. if (name != string.Empty)
  548. {
  549. if (name.IndexOf('<') > 0)
  550. {
  551. displayName = name.Substring(0, name.IndexOf('<'));
  552. address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
  553. }
  554. else
  555. {
  556. displayName = string.Empty;
  557. address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
  558. }
  559. mail.To.Add(new MailAddress(address, displayName));
  560. }
  561. }
  562. //设置邮件的抄送收件人
  563. //这个就简单多了,如果不想快点下岗重要文件还是CC一份给领导比较好
  564. //mail.CC.Add(new MailAddress("Manage@hotmail.com", "尊敬的领导"));
  565. //设置邮件的内容
  566. mail.Body = mailContent;
  567. //设置邮件的格式
  568. mail.BodyEncoding = Encoding.UTF8;
  569. mail.IsBodyHtml = true;
  570. //设置邮件的发送级别
  571. mail.Priority = MailPriority.Normal;
  572. //设置邮件的附件,将在客户端选择的附件先上传到服务器保存一个,然后加入到mail中
  573. //string fileName = file_path;
  574. //fileName = "D:/UpFile/" + fileName.Substring(fileName.LastIndexOf("/") + 1);
  575. //txtUpFile.PostedFile.SaveAs(fileName); // 将文件保存至服务器
  576. //mail.Attachments.Add(new Attachment(fileName));
  577. mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
  578. SmtpClient client = new SmtpClient();
  579. //设置用于 SMTP 事务的主机的名称,填IP地址也可以了
  580. //client.Host = "smtp.163.com";
  581. client.Host = host;
  582. //设置用于 SMTP 事务的端口,默认的是 25
  583. //client.Port = 25;
  584. client.Port = port;
  585. client.UseDefaultCredentials = false;
  586. client.EnableSsl = true;
  587. //这里才是真正的邮箱登陆名和密码,比如我的邮箱地址是 hbgx@hotmail, 我的用户名为 hbgx ,我的密码是 xgbh
  588. client.Credentials = new System.Net.NetworkCredential(username, pwd);
  589. client.DeliveryMethod = SmtpDeliveryMethod.Network;
  590. client.Send(mail);
  591. }
  592. catch (Exception ex)
  593. {
  594. Function.WriteLog(ex.ToString());
  595. }
  596. }
  597. public static string GetWebRequest(string url)
  598. {
  599. return GetWebRequest(url, new Dictionary<string, string>());
  600. }
  601. public static string GetWebRequest(string url, Dictionary<string, string> header, bool statusCode = false)
  602. {
  603. string result = "";
  604. try
  605. {
  606. HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create(url);
  607. webReq.Method = "GET";
  608. webReq.KeepAlive = true;
  609. webReq.Timeout = 1200000;
  610. webReq.ContentType = "text/html";//application/x-www-form-urlencoded
  611. if (header.Count > 0)
  612. {
  613. foreach (string key in header.Keys)
  614. {
  615. webReq.Headers.Add(key, header[key]);
  616. }
  617. }
  618. webReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
  619. using (HttpWebResponse response = (HttpWebResponse)webReq.GetResponse())
  620. {
  621. using (StreamReader reader = new StreamReader(response.GetResponseStream()))
  622. {
  623. result = reader.ReadToEnd();
  624. if (statusCode)
  625. {
  626. result += "|" + response.StatusCode;
  627. }
  628. //function.WriteLog(context.Request.QueryString["mobile"] + " " + reader.ReadToEnd());
  629. }
  630. if (response != null)
  631. response.Close();
  632. }
  633. }
  634. catch (Exception ex)
  635. {
  636. result = ex.ToString();
  637. }
  638. return result;
  639. }
  640. public static string get_Random(int num)
  641. {
  642. string[] str = new string[num];
  643. string serverCode = "";
  644. //生成随机生成器
  645. Random random = new Random(GetRandomSeed());
  646. for (int i = 0; i < num; i++)
  647. {
  648. str[i] = random.Next(10).ToString().Substring(0, 1);
  649. }
  650. foreach (string s in str)
  651. {
  652. serverCode += s;
  653. }
  654. return serverCode;
  655. }
  656. public static int get_Random(int min, int max)
  657. {
  658. int serverCode = 0;
  659. Random random = new Random(GetRandomSeed());
  660. serverCode = random.Next(max - min) + min;
  661. return serverCode;
  662. }
  663. public static string get_Random_string(int count)
  664. {
  665. string str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  666. string result = "";
  667. for (int i = 0; i < count; i++)
  668. {
  669. Random r = new Random(GetRandomSeed());
  670. int serverCode = r.Next(str.Length - 0) + 0;
  671. result += str.Substring(serverCode, 1);
  672. }
  673. return result;
  674. }
  675. public static int GetRandomSeed()
  676. {
  677. //字节数组,用于存储
  678. byte[] bytes = new byte[4];
  679. //创建加密服务,实现加密随机数生成器
  680. System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
  681. //加密数据存入字节数组
  682. rng.GetBytes(bytes);
  683. //转成整型数据返回,作为随机数生成种子
  684. return BitConverter.ToInt32(bytes, 0);
  685. }
  686. public static string get_weekday(DateTime date)
  687. {
  688. string[] week = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  689. return week[(int)date.DayOfWeek];
  690. }
  691. public static string get_substr(string s, int length)
  692. {
  693. byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s);
  694. int n = 0; // 表示当前的字节数
  695. int i = 0; // 要截取的字节数
  696. for (; i < bytes.GetLength(0) && n < length; i++)
  697. {
  698. // 偶数位置,如0、2、4等,为UCS2编码中两个字节的第一个字节
  699. if (i % 2 == 0)
  700. {
  701. n++; // 在UCS2第一个字节时n加1
  702. }
  703. else
  704. {
  705. // 当UCS2编码的第二个字节大于0时,该UCS2字符为汉字,一个汉字算两个字节
  706. if (bytes[i] > 0)
  707. {
  708. n++;
  709. }
  710. }
  711. }
  712. // 如果i为奇数时,处理成偶数
  713. if (i % 2 == 1)
  714. {
  715. // 该UCS2字符是汉字时,去掉这个截一半的汉字
  716. if (bytes[i] > 0)
  717. i = i - 1;
  718. // 该UCS2字符是字母或数字,则保留该字符
  719. else
  720. i = i + 1;
  721. }
  722. return System.Text.Encoding.Unicode.GetString(bytes, 0, i);
  723. }
  724. public static DateTime ConvertIntDateTime(double d)
  725. {
  726. DateTime time = DateTime.MinValue;
  727. DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  728. time = startTime.AddSeconds(d);
  729. return time;
  730. }
  731. public static DateTime ConvertIntDateTimeMini(long TimeStamp)
  732. {
  733. System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
  734. return startTime.AddTicks(TimeStamp * 10000);
  735. }
  736. public static int ConvertDateTimeInt(DateTime time)
  737. {
  738. double intResult = 0;
  739. DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  740. TimeSpan ts = time - startTime;
  741. intResult = Math.Round(ts.TotalSeconds, 0);
  742. return int.Parse(intResult.ToString());
  743. }
  744. public static long GetCurTimestamp()
  745. {
  746. var ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  747. long times = Convert.ToInt64(ts.TotalMilliseconds);
  748. return times;
  749. }
  750. public static DateTime checkDateTimeNull(DateTime? datetime)
  751. {
  752. if (datetime != null)
  753. {
  754. return datetime.Value;
  755. }
  756. return DateTime.Now;
  757. }
  758. public static bool IsDate(string datetime)
  759. {
  760. DateTime check = DateTime.Now;
  761. return DateTime.TryParse(datetime + " 00:00:00", out check);
  762. }
  763. public static bool IsDateTime(string datetime)
  764. {
  765. DateTime check = DateTime.Now;
  766. return DateTime.TryParse(datetime, out check);
  767. }
  768. /// <summary>
  769. /// 获取时间戳
  770. /// </summary>
  771. /// <returns></returns>
  772. public static string getTimeStamp()
  773. {
  774. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  775. return Convert.ToInt64(ts.TotalSeconds).ToString();
  776. }
  777. public static string get_timespan(DateTime s, string show_type)
  778. {
  779. string result = get_timespan(s, DateTime.Now, show_type);
  780. return result;
  781. }
  782. public static string get_timespan(DateTime s, DateTime e, string show_type)
  783. {
  784. string result = "";
  785. if (e > s)
  786. {
  787. int total = 0;
  788. TimeSpan ts = e - s;
  789. switch (show_type)
  790. {
  791. case "d":
  792. result = ts.Days.ToString() + "天";
  793. break;
  794. case "h":
  795. if (ts.Days > 0)
  796. {
  797. total += ts.Days * 24;
  798. }
  799. total += ts.Hours;
  800. result = total.ToString() + "小时";
  801. break;
  802. case "m":
  803. if (ts.Days > 0)
  804. {
  805. total += ts.Days * 24 * 60;
  806. }
  807. if (ts.Hours > 0)
  808. {
  809. total += ts.Hours * 60;
  810. }
  811. total += ts.Hours;
  812. result = total.ToString() + "分钟";
  813. break;
  814. case "s":
  815. if (ts.Days > 0)
  816. {
  817. total += ts.Days * 24 * 60 * 60;
  818. }
  819. if (ts.Hours > 0)
  820. {
  821. total += ts.Hours * 60 * 60;
  822. }
  823. if (ts.Minutes > 0)
  824. {
  825. total += ts.Hours * 60;
  826. }
  827. total += ts.Hours;
  828. result = total.ToString() + "秒";
  829. break;
  830. case "time":
  831. if (ts.Days > 1)
  832. {
  833. result = s.ToString("yyyy-MM-dd");
  834. }
  835. else
  836. {
  837. if (ts.Days > 0)
  838. {
  839. result += ts.Days + "天";
  840. }
  841. if (ts.Hours > 0)
  842. {
  843. result += ts.Hours + "小时";
  844. }
  845. if (ts.Minutes > 0)
  846. {
  847. result += ts.Minutes + "分钟";
  848. }
  849. if (string.IsNullOrEmpty(result))
  850. {
  851. result = "刚刚";
  852. }
  853. else
  854. {
  855. result += "前";
  856. }
  857. }
  858. break;
  859. default: break;
  860. }
  861. }
  862. return result;
  863. }
  864. // 半角转全角
  865. public static string ToSBC(string input)
  866. {
  867. char[] c = input.ToCharArray();
  868. for (int i = 0; i < c.Length; i++)
  869. {
  870. if (c[i] == 32)
  871. {
  872. c[i] = (char)12288;
  873. continue;
  874. }
  875. if (c[i] < 127)
  876. c[i] = (char)(c[i] + 65248);
  877. }
  878. return new string(c);
  879. }
  880. // 全角转半角
  881. public static string ToDBC(string input)
  882. {
  883. char[] c = input.ToCharArray();
  884. for (int i = 0; i < c.Length; i++)
  885. {
  886. if (c[i] == 12288)
  887. {
  888. c[i] = (char)32;
  889. continue;
  890. }
  891. if (c[i] > 65280 && c[i] < 65375)
  892. c[i] = (char)(c[i] - 65248);
  893. }
  894. return new string(c);
  895. }
  896. public static string PostWebRequest(string postUrl, string paramData, string ContentType = "application/x-www-form-urlencoded", bool statusCode = false)
  897. {
  898. //return PostWebRequest(postUrl, paramData, new Dictionary<string, string>());
  899. string ret = string.Empty;
  900. try
  901. {
  902. byte[] postData = Encoding.UTF8.GetBytes(paramData);
  903. // 设置提交的相关参数
  904. HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest;
  905. Encoding myEncoding = Encoding.UTF8;
  906. request.Method = "POST";
  907. request.KeepAlive = false;
  908. request.AllowAutoRedirect = true;
  909. request.ContentType = ContentType;
  910. //request.ContentType = "multipart/form-data; boundary=" + boundary;
  911. request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
  912. request.ContentLength = postData.Length;
  913. // 提交请求数据
  914. System.IO.Stream outputStream = request.GetRequestStream();
  915. outputStream.Write(postData, 0, postData.Length);
  916. outputStream.Close();
  917. HttpWebResponse response;
  918. Stream responseStream;
  919. StreamReader reader;
  920. string srcString;
  921. response = request.GetResponse() as HttpWebResponse;
  922. responseStream = response.GetResponseStream();
  923. reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
  924. srcString = reader.ReadToEnd();
  925. ret = srcString; //返回值赋值
  926. reader.Close();
  927. if (statusCode)
  928. {
  929. ret += "|" + response.StatusCode;
  930. }
  931. }
  932. catch (Exception ex)
  933. {
  934. ret = "fail";
  935. WriteLog(ex.ToString(), "PostWebRequest");
  936. }
  937. return ret;
  938. }
  939. public static string PostWebRequest(string postUrl, string paramData, Dictionary<string, string> header, string Method, string ContentType = "application/x-www-form-urlencoded", bool statusCode = false)
  940. {
  941. //return PostWebRequest(postUrl, paramData, new Dictionary<string, string>());
  942. string ret = string.Empty;
  943. try
  944. {
  945. byte[] postData = Encoding.UTF8.GetBytes(paramData);
  946. // 设置提交的相关参数
  947. HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest;
  948. Encoding myEncoding = Encoding.UTF8;
  949. request.Method = Method;
  950. request.KeepAlive = false;
  951. request.AllowAutoRedirect = true;
  952. request.ContentType = ContentType;
  953. //request.ContentType = "multipart/form-data; boundary=" + boundary;
  954. request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
  955. request.ContentLength = postData.Length;
  956. if (header.Count > 0)
  957. {
  958. foreach (string key in header.Keys)
  959. {
  960. request.Headers.Add(key, header[key]);
  961. }
  962. }
  963. // 提交请求数据
  964. System.IO.Stream outputStream = request.GetRequestStream();
  965. outputStream.Write(postData, 0, postData.Length);
  966. outputStream.Close();
  967. HttpWebResponse response;
  968. Stream responseStream;
  969. StreamReader reader;
  970. string srcString;
  971. response = request.GetResponse() as HttpWebResponse;
  972. responseStream = response.GetResponseStream();
  973. reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
  974. srcString = reader.ReadToEnd();
  975. ret = srcString; //返回值赋值
  976. reader.Close();
  977. if (statusCode)
  978. {
  979. ret += "|" + response.StatusCode;
  980. }
  981. }
  982. catch (Exception ex)
  983. {
  984. ret = ex.ToString();
  985. WriteLog(ex.ToString(), "PostWebRequest");
  986. }
  987. return ret;
  988. }
  989. public static string DeleteWithBody(string url, string jsonBody, Dictionary<string, string> headers = null, bool statusCode = false)
  990. {
  991. try
  992. {
  993. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  994. request.Method = "DELETE";
  995. request.Timeout = 10000;
  996. request.ContentType = "application/json;charset=utf-8";
  997. if (headers != null)
  998. {
  999. foreach (var h in headers)
  1000. request.Headers.Add(h.Key, h.Value);
  1001. }
  1002. // 写入json body
  1003. byte[] buffer = System.Text.Encoding.UTF8.GetBytes(jsonBody);
  1004. request.ContentLength = buffer.Length;
  1005. using Stream reqStream = request.GetRequestStream();
  1006. reqStream.Write(buffer, 0, buffer.Length);
  1007. using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  1008. using StreamReader sr = new StreamReader(response.GetResponseStream());
  1009. string ret = sr.ReadToEnd();
  1010. if (statusCode)
  1011. {
  1012. ret += "|" + response.StatusCode;
  1013. }
  1014. return ret;
  1015. }
  1016. catch (Exception ex)
  1017. {
  1018. return ex.ToString();
  1019. }
  1020. }
  1021. /// <summary>
  1022. /// 从ftp服务器上获得文件夹列表
  1023. /// </summary>
  1024. /// <param name="RequedstPath">服务器下的相对路径</param>
  1025. /// <returns></returns>
  1026. public static List<string> GetFtpDirctoryList(string path, string username, string password)
  1027. {
  1028. List<string> strs = new List<string>();
  1029. try
  1030. {
  1031. string uri = path; //目标路径 path为服务器地址
  1032. FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
  1033. // ftp用户名和密码
  1034. reqFTP.Credentials = new NetworkCredential(username, password);
  1035. reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
  1036. WebResponse response = reqFTP.GetResponse();
  1037. StreamReader reader = new StreamReader(response.GetResponseStream());//中文文件名
  1038. string line = reader.ReadLine();
  1039. while (line != null)
  1040. {
  1041. if (line.Contains("<DIR>"))
  1042. {
  1043. string msg = line.Substring(line.LastIndexOf("<DIR>") + 5).Trim();
  1044. strs.Add(msg);
  1045. }
  1046. line = reader.ReadLine();
  1047. }
  1048. reader.Close();
  1049. response.Close();
  1050. return strs;
  1051. }
  1052. catch (Exception ex)
  1053. {
  1054. Function.WriteLog(DateTime.Now + ":" + ex.ToString(), "从ftp服务器上获得文件夹列表异常");
  1055. }
  1056. return strs;
  1057. }
  1058. /// <summary>
  1059. /// 从ftp服务器上获得文件列表
  1060. /// </summary>
  1061. /// <param name="RequedstPath">服务器下的相对路径</param>
  1062. /// <returns></returns>
  1063. public static List<string> GetFtpFileList(string path, string username, string password)
  1064. {
  1065. List<string> strs = new List<string>();
  1066. try
  1067. {
  1068. string uri = path; //目标路径 path为服务器地址
  1069. FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
  1070. // ftp用户名和密码
  1071. reqFTP.Credentials = new NetworkCredential(username, password);
  1072. reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
  1073. WebResponse response = reqFTP.GetResponse();
  1074. StreamReader reader = new StreamReader(response.GetResponseStream());//中文文件名
  1075. string line = reader.ReadLine();
  1076. while (line != null)
  1077. {
  1078. if (!line.Contains("<DIR>"))
  1079. {
  1080. string msg = line.Substring(39).Trim();
  1081. strs.Add(msg);
  1082. }
  1083. line = reader.ReadLine();
  1084. }
  1085. reader.Close();
  1086. response.Close();
  1087. return strs;
  1088. }
  1089. catch (Exception ex)
  1090. {
  1091. Function.WriteLog(DateTime.Now + ":" + ex.ToString(), "从ftp服务器上获得文件列表异常");
  1092. }
  1093. return strs;
  1094. }
  1095. //从ftp服务器上下载文件
  1096. public static string FtpDownload(string path, string fileName, string username, string password)
  1097. {
  1098. FtpWebRequest reqFTP;
  1099. string savePath = "";
  1100. try
  1101. {
  1102. string filePath = getPath("/FtpDownloadFile/" + fileName);
  1103. FileStream outputStream = new FileStream(filePath, FileMode.Create);
  1104. reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(path + fileName));
  1105. reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
  1106. reqFTP.UseBinary = true;
  1107. reqFTP.Credentials = new NetworkCredential(username, password);
  1108. reqFTP.UsePassive = false;
  1109. FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
  1110. Stream ftpStream = response.GetResponseStream();
  1111. long cl = response.ContentLength;
  1112. int bufferSize = 2048;
  1113. int readCount;
  1114. byte[] buffer = new byte[bufferSize];
  1115. readCount = ftpStream.Read(buffer, 0, bufferSize);
  1116. while (readCount > 0)
  1117. {
  1118. outputStream.Write(buffer, 0, readCount);
  1119. readCount = ftpStream.Read(buffer, 0, bufferSize);
  1120. }
  1121. ftpStream.Close();
  1122. outputStream.Close();
  1123. response.Close();
  1124. savePath = "/FtpDownloadFile/" + fileName;
  1125. }
  1126. catch (Exception ex)
  1127. {
  1128. Function.WriteLog(DateTime.Now + ":" + ex.ToString(), "从ftp服务器上下载文件异常");
  1129. }
  1130. return savePath;
  1131. }
  1132. public static string base64StringToImage(string base64String, string path, string filename)
  1133. {
  1134. string fullpath = getPath(path);
  1135. if (!System.IO.Directory.Exists(fullpath))
  1136. {
  1137. System.IO.Directory.CreateDirectory(fullpath);
  1138. }
  1139. byte[] arr = Convert.FromBase64String(base64String);
  1140. System.IO.File.WriteAllBytes(fullpath + filename, arr);
  1141. return path + filename;
  1142. }
  1143. public static String BuildQueryString(SortedList<String, String> kvp)
  1144. {
  1145. return String.Join("&", kvp.Select(item => String.Format("{0}={1}", item.Key.Trim(), item.Value)).ToArray());
  1146. }
  1147. #region 获取网络文件内容
  1148. public static string GetNetFileContent(string url)
  1149. {
  1150. string textContent = "";
  1151. using (var client = new WebClient())
  1152. {
  1153. try
  1154. {
  1155. textContent = client.DownloadString(url); // 通过 DownloadString 方法获取网页内容
  1156. }
  1157. catch (Exception ex)
  1158. {
  1159. WriteLog(DateTime.Now.ToString() + "\n" + url + "\n" + ex.ToString() + "\n\n", "获取网络文件内容异常");
  1160. }
  1161. }
  1162. return textContent;
  1163. }
  1164. public static byte[] GetNetFileData(string url)
  1165. {
  1166. byte[] textContent = new byte[] { };
  1167. using (var client = new WebClient())
  1168. {
  1169. try
  1170. {
  1171. textContent = client.DownloadData(url); // 通过 DownloadString 方法获取网页内容
  1172. }
  1173. catch (Exception ex)
  1174. {
  1175. WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "获取网络文件流异常");
  1176. }
  1177. }
  1178. return textContent;
  1179. }
  1180. #endregion
  1181. public static void DownloadNetFile(string url, string savePath)
  1182. {
  1183. using (var client = new WebClient())
  1184. {
  1185. try
  1186. {
  1187. string dir = savePath.Substring(0, savePath.LastIndexOf("/"));
  1188. if (!System.IO.Directory.Exists(dir))
  1189. {
  1190. System.IO.Directory.CreateDirectory(dir);
  1191. }
  1192. client.DownloadFile(url, savePath); // 通过 DownloadString 方法获取网页内容
  1193. }
  1194. catch (Exception ex)
  1195. {
  1196. WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "下载网络文件异常");
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }