星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductVerification.xaml.cs 6.1KB

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