Browse Source

添加授权

mengjie 7 years ago
parent
commit
78ea189988

+ 5 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Configs/system.config

@@ -43,4 +43,9 @@
43 43
   <add key="WechatRemark" value="为回报广大群众提供的信息,特此发放红包以兹鼓励"/>-->
44 44
   <!-- ================== 4:性能监控 - 配置语音文件盘符 ================== -->
45 45
   <add key="VideoHardDisc" value="D" />
46
+  <!-- ================== 5:系统授权 ================== -->
47
+  <!--到期提醒天数-->
48
+  <add key="AuthRemindDay" value="30" />
49
+  <!--到期日期-->
50
+  <add key="AuthDate" value="2018-10-20 23:59:59" />
46 51
 </appSettings>

+ 3 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/Login/LoginController.cs

@@ -70,7 +70,9 @@ namespace CallCenterApi.Interface.Controllers
70 70
                     CacheHelper.Insert(token, currentUserInfo, 10080, System.Web.Caching.CacheItemPriority.NotRemovable);
71 71
                     return Success("登录成功", new
72 72
                     {
73
-                        token = token
73
+                        token,
74
+                        date = Configs.GetValue("AuthDate"),
75
+                        days = CallCenter.Utility.Common.CommonHelper.GetRemainingDay()
74 76
                     });
75 77
 
76 78
 

+ 4 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/UserAccountController.cs

@@ -1,4 +1,5 @@
1 1
 using CallCenter.Utility;
2
+using CallCenter.Utility.Common;
2 3
 using CallCenterApi.Common;
3 4
 using CallCenterApi.DB;
4 5
 using CallCenterApi.Interface.Controllers.Base;
@@ -465,7 +466,9 @@ namespace CallCenterApi.Interface.Controllers
465 466
                 var obj = new
466 467
                 {
467 468
                     user = userModel,
468
-                    role = roleModel
469
+                    role = roleModel,
470
+                    date = Configs.GetValue("AuthDate"),
471
+                    days = CommonHelper.GetRemainingDay()
469 472
                 };
470 473
                 res = Success("获取成功", obj);
471 474
             }

+ 17 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Global.asax.cs

@@ -1,4 +1,5 @@
1
-using CallCenterApi.Common;
1
+using CallCenter.Utility;
2
+using CallCenterApi.Common;
2 3
 using CallCenterApi.Interface.Models.Common;
3 4
 using System;
4 5
 using System.Collections.Generic;
@@ -27,6 +28,21 @@ namespace CallCenterApi.Interface
27 28
             HttpApplication app = (HttpApplication)sender;
28 29
             var context = app.Context;
29 30
             if (context == null) throw new ArgumentNullException("context");
31
+            try
32
+            {
33
+                var date = DateTime.Parse(Configs.GetValue("AuthDate"));
34
+                if (date < DateTime.Now)
35
+                {
36
+                    context.Response.Write(new AjaxResult { state = ResultTypes.error.ToString(), message = "授权过期,请联系系统厂家。" }.ToJson());
37
+                    context.Response.End();
38
+                }
39
+            }
40
+            catch (Exception ex)
41
+            {
42
+                var log = LogFactory.GetLogger(this.GetType().ToString());
43
+                log.Error(Configs.GetValue("AuthDate"));
44
+                log.Error(ex.ToString());
45
+            }
30 46
             var token = context.Request["token"];
31 47
             if (string.IsNullOrWhiteSpace(token)) return;
32 48
             try

+ 7 - 2
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/obj/Release/Package/PackageTmp/Configs/system.config

@@ -22,9 +22,9 @@
22 22
   <!-- 设置微信需要的问卷id -->
23 23
   <add key="WXPagerID" value="8" />
24 24
   <!-- 设置微信appid -->
25
-  <add key="WechatAppid" value="wxe03366d8c63d9b09" />
25
+  <add key="WechatAppid" value="wx44a8844db00267b3" />
26 26
   <!-- 设置微信appsecret -->
27
-  <add key="WechatAppsecret" value="3e42313935a4d6dc8b450172b8be2765" />
27
+  <add key="WechatAppsecret" value="70da5c4bd7fbbc11496d849183e8b29f" />
28 28
   <!-- 微信支付分配的商户号 --><!--
29 29
   <add key="WechatMchid" value="1493808312"/>
30 30
   --><!-- 商户的API密钥 --><!--
@@ -43,4 +43,9 @@
43 43
   <add key="WechatRemark" value="为回报广大群众提供的信息,特此发放红包以兹鼓励"/>-->
44 44
   <!-- ================== 4:性能监控 - 配置语音文件盘符 ================== -->
45 45
   <add key="VideoHardDisc" value="D" />
46
+  <!-- ================== 5:系统授权 ================== -->
47
+  <!--到期提醒天数-->
48
+  <add key="AuthRemindDay" value="30" />
49
+  <!--到期日期-->
50
+  <add key="AuthDate" value="2018-10-20 23:59:59" />
46 51
 </appSettings>

+ 21 - 0
codegit/CallCenterCommon/CallCenter.Utility/Common/CommonHelper.cs

@@ -245,5 +245,26 @@ namespace CallCenter.Utility.Common
245 245
             //return gb2312.GetString(bs);
246 246
             return bs;
247 247
         }
248
+
249
+        public static string GetRemainingDay()
250
+        {
251
+            try
252
+            {
253
+                string days = "0";
254
+                var date = DateTime.Parse(Configs.GetValue("AuthDate"));
255
+                int remindday = Int32.Parse(Configs.GetValue("AuthRemindDay"));
256
+                var subtime = date.Subtract(DateTime.Now);
257
+                if (subtime.TotalDays <= remindday)
258
+                {
259
+                    days = Math.Floor(subtime.TotalDays).ToString();
260
+                }
261
+
262
+                return days;
263
+            }
264
+            catch (Exception ex)
265
+            {
266
+                return "0";
267
+            }
268
+        }
248 269
     }
249 270
 }

+ 39 - 20
codegit/CallCenterCommon/CallCenter.Utility/Configs/Configs.cs

@@ -4,15 +4,15 @@ namespace CallCenter.Utility
4 4
 {
5 5
     public static class Configs
6 6
     {
7
-        public static System.Xml.XmlDocument xDoc;
8
-        public static System.Xml.XmlNode xNode;
7
+        //public static System.Xml.XmlDocument xDoc;
8
+        //public static System.Xml.XmlNode xNode;
9 9
 
10
-        static Configs()
11
-        {
12
-            xDoc = new System.Xml.XmlDocument();
13
-            xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
14
-            xNode = xDoc.SelectSingleNode("//appSettings");
15
-        }
10
+        //static Configs()
11
+        //{
12
+        //    xDoc = new System.Xml.XmlDocument();
13
+        //    xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
14
+        //    xNode = xDoc.SelectSingleNode("//appSettings");
15
+        //}
16 16
 
17 17
 
18 18
 
@@ -22,8 +22,18 @@ namespace CallCenter.Utility
22 22
         /// <param name="key"></param>
23 23
         public static string GetValue(string key)
24 24
         {
25
-            var xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
26
-            return xElem1?.GetAttribute("value") ?? "";
25
+            try
26
+            {
27
+                System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
28
+                xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
29
+                System.Xml.XmlNode xNode = xDoc.SelectSingleNode("//appSettings");
30
+                var xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
31
+                return xElem1?.GetAttribute("value") ?? "";
32
+            }
33
+            catch
34
+            {
35
+                return "";
36
+            }
27 37
         }
28 38
         /// <summary>
29 39
         /// 根据Key修改Value
@@ -33,18 +43,27 @@ namespace CallCenter.Utility
33 43
         public static void SetValue(string key, string value)
34 44
         {
35 45
 
36
-            System.Xml.XmlElement xElem1;
37
-            System.Xml.XmlElement xElem2;
38
-            xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
39
-            if (xElem1 != null) xElem1.SetAttribute("value", value);
40
-            else
46
+            try
41 47
             {
42
-                xElem2 = xDoc.CreateElement("add");
43
-                xElem2.SetAttribute("key", key);
44
-                xElem2.SetAttribute("value", value);
45
-                xNode.AppendChild(xElem2);
48
+                System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
49
+                xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
50
+                System.Xml.XmlNode xNode = xDoc.SelectSingleNode("//appSettings");
51
+                //System.Xml.XmlNode xNode;
52
+                System.Xml.XmlElement xElem1;
53
+                System.Xml.XmlElement xElem2;
54
+                xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
55
+                if (xElem1 != null) xElem1.SetAttribute("value", value);
56
+                else
57
+                {
58
+                    xElem2 = xDoc.CreateElement("add");
59
+                    xElem2.SetAttribute("key", key);
60
+                    xElem2.SetAttribute("value", value);
61
+                    xNode.AppendChild(xElem2);
62
+                }
63
+                xDoc.Save(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
46 64
             }
47
-            xDoc.Save(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
65
+            catch
66
+            { }
48 67
         }
49 68
     }
50 69
 }