123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using Common.system;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using XHWK.Model;
- using XHWK.WKTool.DAL;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// ProductVerification.xaml 的交互逻辑
- /// </summary>
- /*
- 本地解密 解密成功 日期在有效期内 ,判断当天是否调用添加历史接口,没有则调用
- 解密失败 或解密获取的时间 过期 , 跳到输入code 激活界面
- */
- public partial class ProductVerification : Window
- {
- private readonly Interface registerController = new Interface();
- private int serverReturnCode = 0;
-
- public ProductVerification()
- {
- InitializeComponent();
- WindowStartupLocation = WindowStartupLocation.CenterScreen;
- this.Topmost = true;
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationDecryptServering, InvokeActivationDecryptServerCompate);
- }
- /// <summary>
- /// 激活信息--验证签名是否过期-调用
- /// </summary>
- /// <returns></returns>
- private object InvokeActivationDecryptServering()
- {
- return APP.ServerMsg;
- }
-
- /// <summary>
- /// 激活信息--验证签名是否过期-返回结果
- /// </summary>
- /// <returns></returns>
- public void InvokeActivationDecryptServerCompate(object obj)
- {
- //解析
- try
- {
- APP.Signature = System.IO.File.ReadAllText(APP.dataPath + "signature.txt", Encoding.Default);
- string decrypt = DataProvider.TripleDESDecrypt(APP.Signature, APP.secretKey);
- decrypt = decrypt.Replace("\u0001", "").Replace("\u0007","").Trim();
- Model_Signatures msgBean = JsonHelper.JsonToObj<Model_Signatures>(decrypt);
- long currentTimeTimestamp = DataProvider.TimestampTotalSeconds(); //当前时间 时间戳
- if (msgBean.endtime > currentTimeTimestamp)//条件成立 解析成功 code 在有效期内
- {
- if (File.Exists(APP.dataPath + "signatureTime.txt"))
- {
- string signatureTime = System.IO.File.ReadAllText(APP.dataPath + "signatureTime.txt", Encoding.Default);
- string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
- if (signatureTime != currentTime)
- {
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
- }
- }
- Dispatcher.Invoke(new Action(() =>
- {
- this.Hide();
- CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
- win.Show();
- Close();
- }));
- }
- else//时间失效
- {
- Dispatcher.Invoke(new Action(() =>
- {
- this.Hide();
- KeyVerification wins = new KeyVerification
- {
- Topmost = true
- };
- wins.ShowDialog();
- Close();
- }));
- }
- }
- catch (Exception ex) //解析失败 输code
- {
- LogHelper.WriteErrLog("ProductVerification(解析失败)" + ex.Message, ex);
- Dispatcher.Invoke(new Action(() =>
- {
- this.Hide();
- KeyVerification wins = new KeyVerification
- {
- Topmost = true
- };
- wins.ShowDialog();
- Close();
- }));
- }
-
- }
- /// <summary>
- /// 激活信息--添加激活历史-调用
- /// </summary>
- /// <returns></returns>
- private object InvokeActivationAddHistoryServering()
- {
- serverReturnCode = registerController.ActivationAddHistory();
- return APP.ServerMsg;
- }
-
- /// <summary>
- /// 激活信息--添加激活历史-返回结果
- /// </summary>
- /// <returns></returns>
- public void InvokeActivationAddHistoryServerCompate(object obj)
- {
- if (!Directory.Exists(APP.dataPath))
- {
- Directory.CreateDirectory(APP.dataPath);
- }
- string ApplicationData = APP.dataPath + "signatureTime.txt";
- string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
- System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期
- }
-
- /// <summary>
- /// 关闭弹窗
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void close_click(object sender, RoutedEventArgs e)
- {
- closeAction();
- }
- /// <summary>
- /// 退出程序
- /// </summary>
- private void closeAction()
- {
- Dispatcher.Invoke(new Action(() =>
- {
- System.Environment.Exit(0);
- }));
- }
-
- ~ProductVerification()
- {
- Console.WriteLine("{0}被销毁", this);
- Dispose(false);
- }
- public void Dispose()
- {
- Console.WriteLine("{0}被手动销毁", this);
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- private bool disposed;
- protected void Dispose(bool disposing)
- {
- Console.WriteLine("{0}被自动销毁", this);
- if (!disposed)
- {
- if (disposing)
- {
- //托管资源释放
-
- }
- //非托管资源释放
- // ...
- }
- disposed = true;
- }
- }
- }
|