using iWare.Authorize; using iWareCC_WC2CC.Authorize.Dto; using iWareCCCommon; using iWareModel; using Newtonsoft.Json; using ProjectCode; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection.Emit; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace iWareCC_WC2CC.Common.Helper { /// /// 授权帮助类 /// public class AuthorizeHelper { private static AuthorizeClass authorizeClass = new AuthorizeClass(); /// /// 对外开放的授权验证方法 /// /// false:验证失败,需要终止方法执行 public static bool Pul_ValidateLicense() { try { //增加授权 var ret = AuthorizeHelper.ValidateLicense(); if (ret.result) { if (!string.IsNullOrEmpty(ret.warnMsg)) { if (AuthorizeHelper.IsHasAuthorizeForToDay() == false) { MessageBox.Show("警告:" + ret.warnMsg); //1天出现一次 AuthorizeHelper.SetAuthorizeClass(true); } } } else { AuthorizeHelper.SetAuthorizeClass(false);//重置当天授权 MessageBox.Show("授权失败:" + ret.resMsg); return false; } return true; } catch (Exception ex) { AuthorizeHelper.SetAuthorizeClass(false);//重置当天授权 MessageBox.Show("授权异常:" + ex.Message); return false; } } /// /// 验证授权 /// /// public static AuthorizeFunRetEntity ValidateLicense() { var ret = RequestHelper.GetHttpRequest("http://localhost:7777/", "WareAuthorize?waringDays=10"); return ret; } /// /// 今天是否已经验证过了 /// /// private static bool IsHasAuthorizeForToDay() { var curDay = DateTime.Now.ToString("yyyyMMdd"); if (curDay == authorizeClass.CurDay && authorizeClass.IsHasAuthorize == true) { return true; } return false; } /// /// 赋值验证对象 /// /// private static void SetAuthorizeClass(bool isHasAuthorize) { var curDay = DateTime.Now.ToString("yyyyMMdd"); authorizeClass.CurDay = curDay; authorizeClass.IsHasAuthorize = isHasAuthorize; } } }