星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ProductVerification.xaml.cs 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. using XHWK.Model;
  17. using XHWK.WKTool.DAL;
  18. namespace XHWK.WKTool
  19. {
  20. /// <summary>
  21. /// ProductVerification.xaml 的交互逻辑
  22. /// </summary>
  23. /*
  24. 本地解密 解密成功 日期在有效期内 ,判断当天是否调用添加历史接口,没有则调用
  25. 解密失败 或解密获取的时间 过期 , 跳到输入code 激活界面
  26. */
  27. public partial class ProductVerification : Window
  28. {
  29. private readonly Interface registerController = new Interface();
  30. private int serverReturnCode = 0;
  31. public ProductVerification()
  32. {
  33. InitializeComponent();
  34. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  35. this.Topmost = true;
  36. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationDecryptServering, InvokeActivationDecryptServerCompate);
  37. }
  38. /// <summary>
  39. /// 激活信息--验证签名是否过期-调用
  40. /// </summary>
  41. /// <returns></returns>
  42. private object InvokeActivationDecryptServering()
  43. {
  44. return APP.ServerMsg;
  45. }
  46. /// <summary>
  47. /// 激活信息--验证签名是否过期-返回结果
  48. /// </summary>
  49. /// <returns></returns>
  50. public void InvokeActivationDecryptServerCompate(object obj)
  51. {
  52. //解析
  53. try
  54. {
  55. APP.Signature = System.IO.File.ReadAllText(APP.dataPath + "signature.txt", Encoding.Default);
  56. string decrypt = DataProvider.TripleDESDecrypt(APP.Signature, APP.secretKey);
  57. decrypt = decrypt.Replace("\u0001", "").Replace("\u0007","").Trim();
  58. Model_Signatures msgBean = JsonHelper.JsonToObj<Model_Signatures>(decrypt);
  59. long currentTimeTimestamp = DataProvider.TimestampTotalSeconds(); //当前时间 时间戳
  60. if (msgBean.endtime > currentTimeTimestamp)//条件成立 解析成功 code 在有效期内
  61. {
  62. if (File.Exists(APP.dataPath + "signatureTime.txt"))
  63. {
  64. string signatureTime = System.IO.File.ReadAllText(APP.dataPath + "signatureTime.txt", Encoding.Default);
  65. string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
  66. if (signatureTime != currentTime)
  67. {
  68. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
  69. }
  70. }
  71. Dispatcher.Invoke(new Action(() =>
  72. {
  73. CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
  74. win.Show();
  75. Close();
  76. }));
  77. }
  78. else//时间失效
  79. {
  80. Dispatcher.Invoke(new Action(() =>
  81. {
  82. KeyVerification wins = new KeyVerification
  83. {
  84. Topmost = true
  85. };
  86. wins.ShowDialog();
  87. Close();
  88. }));
  89. }
  90. }
  91. catch (Exception ex) //解析失败 输code
  92. {
  93. LogHelper.WriteErrLog("ProductVerification(解析失败)" + ex.Message, ex);
  94. Dispatcher.Invoke(new Action(() =>
  95. {
  96. KeyVerification wins = new KeyVerification
  97. {
  98. Topmost = true
  99. };
  100. wins.ShowDialog();
  101. Close();
  102. }));
  103. }
  104. }
  105. /// <summary>
  106. /// 激活信息--添加激活历史-调用
  107. /// </summary>
  108. /// <returns></returns>
  109. private object InvokeActivationAddHistoryServering()
  110. {
  111. serverReturnCode = registerController.ActivationAddHistory();
  112. return APP.ServerMsg;
  113. }
  114. /// <summary>
  115. /// 激活信息--添加激活历史-返回结果
  116. /// </summary>
  117. /// <returns></returns>
  118. public void InvokeActivationAddHistoryServerCompate(object obj)
  119. {
  120. if (!Directory.Exists(APP.dataPath))
  121. {
  122. Directory.CreateDirectory(APP.dataPath);
  123. }
  124. string ApplicationData = APP.dataPath + "signatureTime.txt";
  125. string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
  126. System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期
  127. }
  128. /// <summary>
  129. /// 关闭弹窗
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. private void close_click(object sender, RoutedEventArgs e)
  134. {
  135. closeAction();
  136. }
  137. /// <summary>
  138. /// 退出程序
  139. /// </summary>
  140. private void closeAction()
  141. {
  142. Dispatcher.Invoke(new Action(() =>
  143. {
  144. System.Environment.Exit(0);
  145. }));
  146. }
  147. ~ProductVerification()
  148. {
  149. Console.WriteLine("{0}被销毁", this);
  150. Dispose(false);
  151. }
  152. public void Dispose()
  153. {
  154. Console.WriteLine("{0}被手动销毁", this);
  155. Dispose(true);
  156. GC.SuppressFinalize(this);
  157. }
  158. private bool disposed;
  159. protected void Dispose(bool disposing)
  160. {
  161. Console.WriteLine("{0}被自动销毁", this);
  162. if (!disposed)
  163. {
  164. if (disposing)
  165. {
  166. //托管资源释放
  167. }
  168. //非托管资源释放
  169. // ...
  170. }
  171. disposed = true;
  172. }
  173. }
  174. }