星火微课系统客户端
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

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 XhApi registerController = new XhApi();
  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. ModelSignatures msgBean = JsonHelper.JsonToObj<ModelSignatures>(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.Logerror.Error("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 CloseClick(object sender, RoutedEventArgs e)
  128. {
  129. CloseAction();
  130. }
  131. /// <summary>
  132. /// 退出程序
  133. /// </summary>
  134. private void CloseAction()
  135. {
  136. Dispatcher.Invoke
  137. (
  138. () =>
  139. {
  140. Application.Current.Shutdown();
  141. }
  142. );
  143. }
  144. ~ProductVerification()
  145. {
  146. //Console.WriteLine("{0}被销毁", this);
  147. Dispose(false);
  148. }
  149. public void Dispose()
  150. {
  151. //Console.WriteLine("{0}被手动销毁", this);
  152. Dispose(true);
  153. GC.SuppressFinalize(this);
  154. }
  155. private bool disposed;
  156. protected void Dispose(bool disposing)
  157. {
  158. //Console.WriteLine("{0}被自动销毁", this);
  159. if (!disposed)
  160. {
  161. if (disposing)
  162. {
  163. //托管资源释放
  164. }
  165. //非托管资源释放
  166. // ...
  167. }
  168. disposed = true;
  169. }
  170. }
  171. }