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

ProductVerification.xaml.cs 6.4KB

4 роки тому
4 роки тому
4 роки тому
4 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. this.Hide();
  74. CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
  75. win.Show();
  76. Close();
  77. }));
  78. }
  79. else//时间失效
  80. {
  81. Dispatcher.Invoke(new Action(() =>
  82. {
  83. this.Hide();
  84. KeyVerification wins = new KeyVerification
  85. {
  86. Topmost = true
  87. };
  88. wins.ShowDialog();
  89. Close();
  90. }));
  91. }
  92. }
  93. catch (Exception ex) //解析失败 输code
  94. {
  95. LogHelper.WriteErrLog("ProductVerification(解析失败)" + ex.Message, ex);
  96. Dispatcher.Invoke(new Action(() =>
  97. {
  98. this.Hide();
  99. KeyVerification wins = new KeyVerification
  100. {
  101. Topmost = true
  102. };
  103. wins.ShowDialog();
  104. Close();
  105. }));
  106. }
  107. }
  108. /// <summary>
  109. /// 激活信息--添加激活历史-调用
  110. /// </summary>
  111. /// <returns></returns>
  112. private object InvokeActivationAddHistoryServering()
  113. {
  114. serverReturnCode = registerController.ActivationAddHistory();
  115. return APP.ServerMsg;
  116. }
  117. /// <summary>
  118. /// 激活信息--添加激活历史-返回结果
  119. /// </summary>
  120. /// <returns></returns>
  121. public void InvokeActivationAddHistoryServerCompate(object obj)
  122. {
  123. if (!Directory.Exists(APP.dataPath))
  124. {
  125. Directory.CreateDirectory(APP.dataPath);
  126. }
  127. string ApplicationData = APP.dataPath + "signatureTime.txt";
  128. string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
  129. System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期
  130. }
  131. /// <summary>
  132. /// 关闭弹窗
  133. /// </summary>
  134. /// <param name="sender"></param>
  135. /// <param name="e"></param>
  136. private void close_click(object sender, RoutedEventArgs e)
  137. {
  138. closeAction();
  139. }
  140. /// <summary>
  141. /// 退出程序
  142. /// </summary>
  143. private void closeAction()
  144. {
  145. Dispatcher.Invoke(new Action(() =>
  146. {
  147. System.Environment.Exit(0);
  148. }));
  149. }
  150. ~ProductVerification()
  151. {
  152. Console.WriteLine("{0}被销毁", this);
  153. Dispose(false);
  154. }
  155. public void Dispose()
  156. {
  157. Console.WriteLine("{0}被手动销毁", this);
  158. Dispose(true);
  159. GC.SuppressFinalize(this);
  160. }
  161. private bool disposed;
  162. protected void Dispose(bool disposing)
  163. {
  164. Console.WriteLine("{0}被自动销毁", this);
  165. if (!disposed)
  166. {
  167. if (disposing)
  168. {
  169. //托管资源释放
  170. }
  171. //非托管资源释放
  172. // ...
  173. }
  174. disposed = true;
  175. }
  176. }
  177. }