using Common.system; using System; using System.IO; using System.Text; using System.Windows; using XHWK.Model; using XHWK.WKTool.DAL; namespace XHWK.WKTool { /// /// ProductVerification.xaml 的交互逻辑 /// 本地解密 解密成功 日期在有效期内 ,判断当天是否调用添加历史接口,没有则调用 /// 解密失败 或解密获取的时间 过期 , 跳到输入code 激活界面 /// public partial class ProductVerification { private readonly XhApi _registerController = new XhApi(); private int _serverReturnCode; public ProductVerification() { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; Topmost = true; App.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationDecryptServering, InvokeActivationDecryptServerCompate); } /// /// 激活信息--验证签名是否过期-调用 /// /// private object InvokeActivationDecryptServering() { return App.ServerMsg; } /// /// 激活信息--验证签名是否过期-返回结果 /// /// 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(); ModelSignatures msgBean = JsonHelper.JsonToObj(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(); //当前时间 if (signatureTime != currentTime) { App.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate); } } Dispatcher.Invoke( () => { Hide(); CreateWin win = new CreateWin(); win.Show(); Close(); } ); } else //时间失效 { Dispatcher.Invoke( () => { Hide(); KeyVerification wins = new KeyVerification { Topmost = true }; wins.ShowDialog(); Close(); } ); } } catch (Exception ex) //解析失败 输code { LogHelper.Logerror.Error("ProductVerification(解析失败)" + ex.Message, ex); Dispatcher.Invoke( () => { Hide(); KeyVerification wins = new KeyVerification { Topmost = true }; wins.ShowDialog(); Close(); } ); } } /// /// 激活信息--添加激活历史-调用 /// /// private object InvokeActivationAddHistoryServering() { _serverReturnCode = _registerController.ActivationAddHistory(); return App.ServerMsg; } /// /// 激活信息--添加激活历史-返回结果 /// /// 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(); //当前时间 System.IO.File.WriteAllText( applicationData, currentTime, Encoding.Default ); //存放签名验证日期 } /// /// 关闭弹窗 /// /// /// private void CloseClick(object sender, RoutedEventArgs e) { CloseAction(); } /// /// 退出程序 /// private void CloseAction() { Dispatcher.Invoke( () => { Application.Current.Shutdown(); } ); } ~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; } } }