schangxiang@126.com
2025-04-04 be379ab0bf3acc85c135ceba5e6a0ce99c7bd58d
Api/Util/AuthorizeHelper.cs
@@ -1,4 +1,5 @@
using iWare.Authorize.Dto;
using Newtonsoft.Json;
using ProjectCode;
namespace iWare.Authorize
@@ -16,11 +17,16 @@
        {
            try
            {
                var licenseFolerName = input.LicenseFolerName;
                if (string.IsNullOrEmpty(licenseFolerName))
                {
                    licenseFolerName = "lic";
                }
                //1、获取mac地址
                var macAddresses = EnDecode.GetAllMacAddresses();
                //2、找到 授权文件
                string baseDir = AppDomain.CurrentDomain.BaseDirectory;
                DirectoryInfo theFolder = new DirectoryInfo(baseDir + @"\\AuthorizeFile\\lic");
                DirectoryInfo theFolder = new DirectoryInfo(baseDir + @"\\AuthorizeFile\\" + licenseFolerName);
                //遍历文件,读取第一个文件
                var files = theFolder.GetFiles();
                if (files.Length == 0)
@@ -33,12 +39,13 @@
                string rst = EnDecode.ReadAndValidateLicenseFile(firstFile.FullName);
                if (!string.IsNullOrEmpty(rst))
                {
                    AuthorizeFunRetEntity newRet = JsonConvert.DeserializeObject<AuthorizeFunRetEntity>(rst);
                    if (EnDecode.ValidatePermanentLicense(firstFile.FullName))
                    {
                        return AuthorizeFunRetEntity.Success("成功");
                        return AuthorizeFunRetEntity.Success("成功", newRet);
                    }
                    else
                        return ValidateLicenseForDev(firstFile.FullName, input);
                        return ValidateLicenseForDev(firstFile.FullName, input, newRet);
                }
                else
                {
@@ -57,8 +64,14 @@
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        private static AuthorizeFunRetEntity ValidateLicenseForDev(string filePath, ValidateLicenseInput input)
        private static AuthorizeFunRetEntity ValidateLicenseForDev(string filePath, ValidateLicenseInput input, AuthorizeFunRetEntity newRet)
        {
            var str_expiryDate = "";
            if (!string.IsNullOrEmpty(newRet.expiryDate))
            {
                str_expiryDate = Convert.ToDateTime(newRet.expiryDate).ToString("yyyy-MM-dd HH:mm:ss");
            }
            //读取 开发授权
            var val = EnDecode.ValidateDevLicense(filePath);
            if (val.IsValid)
@@ -66,16 +79,22 @@
                if (input != null && input.WaringDays != null)
                {
                    int waringDays = (int)input.WaringDays;
                    if (waringDays >= val.RemainingDays)
                    double _my_RemainingDays = Convert.ToDouble(val.RemainingDays.ToString("0.0"));
                    if (waringDays >= _my_RemainingDays)
                    {
                        return AuthorizeFunRetEntity.Success("成功", val.RemainingDays, $"授权剩余天数{val.RemainingDays}小于{waringDays}天");
                        return AuthorizeFunRetEntity.Success("成功", val.RemainingDays, $"授权剩余天数{_my_RemainingDays}小于{waringDays}天,到期日[{str_expiryDate}]");
                    }
                }
                return AuthorizeFunRetEntity.Success("成功", val.RemainingDays);
                return AuthorizeFunRetEntity.Success("成功", val.RemainingDays, newRet);
            }
            else
                return AuthorizeFunRetEntity.Fail("授权失败", val.RemainingDays);
            {
                if (string.IsNullOrEmpty(newRet.expiryDate))
                {
                    return AuthorizeFunRetEntity.Fail($"授权失败", val.RemainingDays, newRet);
                }
                return AuthorizeFunRetEntity.Fail($"授权失败,到期日[{str_expiryDate}]", val.RemainingDays, newRet);
            }
        }
    }