222
schangxiang@126.com
2025-06-09 51c7ba2285c44af268858099871946e0b91dda55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
{
    /// <summary>
    /// 授权帮助类
    /// </summary>
    public class AuthorizeHelper
    {
 
        private static AuthorizeClass authorizeClass = new AuthorizeClass();
 
        /// <summary>
        /// 对外开放的授权验证方法
        /// </summary>
        /// <returns>false:验证失败,需要终止方法执行</returns>
        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;
            }
        }
 
 
        /// <summary>
        /// 验证授权
        /// </summary>
        /// <returns></returns>
        public static AuthorizeFunRetEntity ValidateLicense()
        {
            var ret = RequestHelper.GetHttpRequest<AuthorizeFunRetEntity>("http://localhost:7777/", "WareAuthorize?waringDays=10");
 
            return ret;
        }
 
        /// <summary>
        /// 今天是否已经验证过了
        /// </summary>
        /// <returns></returns>
        private static bool IsHasAuthorizeForToDay()
        {
            var curDay = DateTime.Now.ToString("yyyyMMdd");
            if (curDay == authorizeClass.CurDay && authorizeClass.IsHasAuthorize == true)
            {
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 赋值验证对象
        /// </summary>
        /// <returns></returns>
        private static void SetAuthorizeClass(bool isHasAuthorize)
        {
            var curDay = DateTime.Now.ToString("yyyyMMdd");
            authorizeClass.CurDay = curDay;
            authorizeClass.IsHasAuthorize = isHasAuthorize;
        }
 
    }
}