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

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. /// 本地解密 解密成功 日期在有效期内 ,判断当天是否调用添加历史接口,没有则调用
  13. /// 解密失败 或解密获取的时间 过期 , 跳到输入code 激活界面
  14. /// </summary>
  15. public partial class ProductVerification
  16. {
  17. private readonly XhApi _registerController = new XhApi();
  18. private int _serverReturnCode;
  19. public ProductVerification()
  20. {
  21. InitializeComponent();
  22. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  23. Topmost = true;
  24. App.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationDecryptServering, InvokeActivationDecryptServerCompate);
  25. }
  26. /// <summary>
  27. /// 激活信息--验证签名是否过期-调用
  28. /// </summary>
  29. /// <returns></returns>
  30. private object InvokeActivationDecryptServering()
  31. {
  32. return App.ServerMsg;
  33. }
  34. /// <summary>
  35. /// 激活信息--验证签名是否过期-返回结果
  36. /// </summary>
  37. /// <returns></returns>
  38. public void InvokeActivationDecryptServerCompate(object obj)
  39. {
  40. //解析
  41. try
  42. {
  43. App.Signature = System.IO.File.ReadAllText(App.DataPath + "signature.txt", Encoding.Default);
  44. string decrypt = DataProvider.TripleDesDecrypt(App.Signature, App.secretKey);
  45. decrypt = decrypt.Replace("\u0001", "").Replace("\u0007", "").Trim();
  46. ModelSignatures msgBean = JsonHelper.JsonToObj<ModelSignatures>(decrypt);
  47. long currentTimeTimestamp = DataProvider.TimestampTotalSeconds(); //当前时间 时间戳
  48. if (msgBean.endtime > currentTimeTimestamp) //条件成立 解析成功 code 在有效期内
  49. {
  50. if (File.Exists(App.DataPath + "signatureTime.txt"))
  51. {
  52. string signatureTime = System.IO.File.ReadAllText(App.DataPath + "signatureTime.txt", Encoding.Default);
  53. string currentTime = DateTime.Now.ToLongDateString(); //当前时间
  54. if (signatureTime != currentTime)
  55. {
  56. App.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
  57. }
  58. }
  59. Dispatcher.Invoke(
  60. () =>
  61. {
  62. Hide();
  63. CreateWin win = new CreateWin();
  64. win.Show();
  65. Close();
  66. }
  67. );
  68. }
  69. else //时间失效
  70. {
  71. Dispatcher.Invoke(
  72. () =>
  73. {
  74. Hide();
  75. KeyVerification wins = new KeyVerification { Topmost = true };
  76. wins.ShowDialog();
  77. Close();
  78. }
  79. );
  80. }
  81. }
  82. catch (Exception ex) //解析失败 输code
  83. {
  84. LogHelper.Logerror.Error("ProductVerification(解析失败)" + ex.Message, ex);
  85. Dispatcher.Invoke(
  86. () =>
  87. {
  88. Hide();
  89. KeyVerification wins = new KeyVerification { Topmost = true };
  90. wins.ShowDialog();
  91. Close();
  92. }
  93. );
  94. }
  95. }
  96. /// <summary>
  97. /// 激活信息--添加激活历史-调用
  98. /// </summary>
  99. /// <returns></returns>
  100. private object InvokeActivationAddHistoryServering()
  101. {
  102. _serverReturnCode = _registerController.ActivationAddHistory();
  103. return App.ServerMsg;
  104. }
  105. /// <summary>
  106. /// 激活信息--添加激活历史-返回结果
  107. /// </summary>
  108. /// <returns></returns>
  109. public void InvokeActivationAddHistoryServerCompate(object obj)
  110. {
  111. if (!Directory.Exists(App.DataPath))
  112. {
  113. Directory.CreateDirectory(App.DataPath);
  114. }
  115. string applicationData = App.DataPath + "signatureTime.txt";
  116. string currentTime = DateTime.Now.ToLongDateString(); //当前时间
  117. System.IO.File.WriteAllText(
  118. applicationData,
  119. currentTime,
  120. Encoding.Default
  121. ); //存放签名验证日期
  122. }
  123. /// <summary>
  124. /// 关闭弹窗
  125. /// </summary>
  126. /// <param name="sender"></param>
  127. /// <param name="e"></param>
  128. private void CloseClick(object sender, RoutedEventArgs e)
  129. {
  130. CloseAction();
  131. }
  132. /// <summary>
  133. /// 退出程序
  134. /// </summary>
  135. private void CloseAction()
  136. {
  137. Dispatcher.Invoke(
  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. }