星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ProductVerification.xaml.cs 6.1KB

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