Sfoglia il codice sorgente

开放平台调整。

CrazyIter_Bin 3 anni fa
parent
commit
0cfa8bb518

+ 11 - 11
TEAMModelAPI/ApiTokenAttribute.cs

@@ -41,38 +41,38 @@ namespace TEAMModelOS.Filter
         /// <summary>
         /// <summary>
         /// 是否免费调用
         /// 是否免费调用
         /// </summary>
         /// </summary>
-        public bool free { get; set; }
+        ///public bool free { get; set; }
         /// <summary>
         /// <summary>
         /// 每次调用花费多少钱
         /// 每次调用花费多少钱
         /// </summary>
         /// </summary>
-        public decimal cost { get; set; }
+        ///public decimal cost { get; set; }
     }
     }
 
 
     public class ApiTokenAttribute : Attribute, IFilterFactory
     public class ApiTokenAttribute : Attribute, IFilterFactory
     {
     {
         public bool IsReusable => true;
         public bool IsReusable => true;
         public bool Limit { get; set; }
         public bool Limit { get; set; }
-        public string Permission { get; set; }
+        public string Auth { get; set; }
 
 
         public IFilterMetadata CreateInstance(IServiceProvider services)
         public IFilterMetadata CreateInstance(IServiceProvider services)
         {
         {
             var option = services.GetService<IOptions<Option>>();
             var option = services.GetService<IOptions<Option>>();
             var azureRedis = services.GetService<AzureRedisFactory>();
             var azureRedis = services.GetService<AzureRedisFactory>();
-            return new InternalAuthTokenFilter(option ,azureRedis, Permission,   Limit);
+            return new InternalAuthTokenFilter(option ,azureRedis, Auth,   Limit);
         }
         }
 
 
         private class InternalAuthTokenFilter : IResourceFilter
         private class InternalAuthTokenFilter : IResourceFilter
         {
         {
             private readonly Option _option;
             private readonly Option _option;
             //private readonly string _roles;
             //private readonly string _roles;
-            private readonly string _permission;
+            private readonly string _auth;
             private readonly bool _limit;
             private readonly bool _limit;
             private readonly AzureRedisFactory _azureRedis;
             private readonly AzureRedisFactory _azureRedis;
 
 
-            public InternalAuthTokenFilter(IOptions<Option> option, AzureRedisFactory azureRedis, string permission,bool limit)
+            public InternalAuthTokenFilter(IOptions<Option> option, AzureRedisFactory azureRedis, string auth, bool limit)
             {
             {
                 _option = option.Value;
                 _option = option.Value;
-                _permission = permission;
+                _auth = auth;
                 _limit = limit;
                 _limit = limit;
                 _azureRedis = azureRedis;
                 _azureRedis = azureRedis;
             }
             }
@@ -88,11 +88,11 @@ namespace TEAMModelOS.Filter
                     id = jwt.Payload.Sub;
                     id = jwt.Payload.Sub;
                     school = jwt.Payload.Azp;
                     school = jwt.Payload.Azp;
                     jti = jwt.Payload.Jti;
                     jti = jwt.Payload.Jti;
-                    var permissions = jwt.Claims.Where(c => c.Type == "permissions");
+                    var permissions = jwt.Claims.Where(c => c.Type.Equals("auth"));
                     ///当前请求的api的设置的permission值是否包含在 从jwt的获取["1","2","3","4","5"]值中
                     ///当前请求的api的设置的permission值是否包含在 从jwt的获取["1","2","3","4","5"]值中
-                    if (!string.IsNullOrWhiteSpace(_permission)&& permissions.Count()>0)
+                    if (!string.IsNullOrWhiteSpace(_auth)&& permissions.Count()>0)
                     {
                     {
-                       if (permissions.Select(x=>x.Value).Contains(_permission))
+                       if (permissions.Select(x=>x.Value).Contains(_auth))
                        {
                        {
                             pass = true;
                             pass = true;
                        }
                        }
@@ -104,7 +104,7 @@ namespace TEAMModelOS.Filter
                         if (_limit)
                         if (_limit)
                         {
                         {
                         }
                         }
-                    }
+                    } 
                 }
                 }
 
 
                 if (pass)
                 if (pass)

+ 14 - 1
TEAMModelAPI/Controllers/WeatherForecastController.cs

@@ -32,7 +32,7 @@ namespace TEAMModelAPI.Controllers
         }
         }
 
 
         [HttpGet]
         [HttpGet]
-        [ApiToken]
+        [ApiToken(Auth ="5")]
         public IEnumerable<WeatherForecast> Get()
         public IEnumerable<WeatherForecast> Get()
         {
         {
             var rng = new Random();
             var rng = new Random();
@@ -44,6 +44,19 @@ namespace TEAMModelAPI.Controllers
             })
             })
             .ToArray();
             .ToArray();
         }
         }
+        [HttpGet("aaaa")]
+        [ApiToken(Auth = "4")]
+        public IEnumerable<WeatherForecast> Getaaaa()
+        {
+            var rng = new Random();
+            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+            {
+                Date = DateTime.Now.AddDays(index),
+                TemperatureC = rng.Next(-20, 55),
+                Summary = Summaries[rng.Next(Summaries.Length)]
+            })
+            .ToArray();
+        }
 
 
         /// <summary>
         /// <summary>
         /// 删除prefix  不管是内容 模块还是其他试题试卷 评测 问卷投票等都在使用。
         /// 删除prefix  不管是内容 模块还是其他试题试卷 评测 问卷投票等都在使用。

+ 1 - 1
TEAMModelAPI/appsettings.Development.json

@@ -12,7 +12,7 @@
     "LocationNum": "1",
     "LocationNum": "1",
     "HostName": "localhost:5001",
     "HostName": "localhost:5001",
     "AllowedHosts": [ "localhost", "*.teammodel.cn", "*.teammodel.net", "*.habookaclass.biz", "test" ],
     "AllowedHosts": [ "localhost", "*.teammodel.cn", "*.teammodel.net", "*.habookaclass.biz", "test" ],
-    "Issuer": "www.teammodel.cn",
+    "Issuer": "localhost:5001",
     "JwtSecretKey": "fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA=",
     "JwtSecretKey": "fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA=",
     "Exp": 86400,
     "Exp": 86400,
     "IdTokenSalt": "8263692E2213497BB55E74792B7900B4",
     "IdTokenSalt": "8263692E2213497BB55E74792B7900B4",

+ 41 - 0
TEAMModelOS.SDK/Models/Table/OpenApi.cs

@@ -49,6 +49,28 @@ namespace TEAMModelOS.SDK.Models
         /// r,w,d,l
         /// r,w,d,l
         /// </summary>
         /// </summary>
         public string type { get; set; }
         public string type { get; set; }
+        /// <summary>
+        /// minute  分钟,表示按分钟限流,多少分钟内只能访问多少次,
+        /// hour    小时,表示按小时限流,多少小时内只能访问多少次,
+        /// day     天数,表示按天数限流,多少天数内只能访问多少次,
+        /// </summary>
+        public string policy { get; set; }
+        /// <summary>
+        /// policy 策略,分钟,小时,天数对应的时长
+        /// </summary>
+        public int duration { get; set; }
+        /// <summary>
+        /// policy 策略,分钟,小时,天数对应的时长(duration) 可以访问的次数
+        /// </summary>
+        public int times { get; set; }
+        /// <summary>
+        /// 是否免费调用
+        /// </summary>
+        ///public bool free { get; set; }
+        /// <summary>
+        /// 每次调用花费多少钱
+        /// </summary>
+        ///public decimal cost { get; set; }
     }
     }
     [TableName(Name = "OpenApi")]
     [TableName(Name = "OpenApi")]
     public class Webhook : TableEntity
     public class Webhook : TableEntity
@@ -97,6 +119,7 @@ namespace TEAMModelOS.SDK.Models
         /// 授权信息
         /// 授权信息
         /// </summary>
         /// </summary>
         public List<int> auths { get; set; } = new List<int>();
         public List<int> auths { get; set; } = new List<int>();
+        public List<ApiInfo> apiInfos { get; set; } = new List<ApiInfo>();
         public List<int> webhooks { get; set; } = new List<int>();
         public List<int> webhooks { get; set; } = new List<int>();
         /// <summary>
         /// <summary>
         /// 学校编码
         /// 学校编码
@@ -118,9 +141,27 @@ namespace TEAMModelOS.SDK.Models
         /// 0禁用,1正常,2 token封禁
         /// 0禁用,1正常,2 token封禁
         /// </summary>
         /// </summary>
         public int status { get; set; }
         public int status { get; set; }
+
         public OpenApp()
         public OpenApp()
         {
         {
             pk = "OpenApp";
             pk = "OpenApp";
         }
         }
     }
     }
+    public class ApiInfo {
+        /// <summary>
+        /// minute  分钟,表示按分钟限流,多少分钟内只能访问多少次,
+        /// hour    小时,表示按小时限流,多少小时内只能访问多少次,
+        /// day     天数,表示按天数限流,多少天数内只能访问多少次,
+        /// </summary>
+        public string policy { get; set; }
+        /// <summary>
+        /// policy 策略,分钟,小时,天数对应的时长
+        /// </summary>
+        public int duration { get; set; }
+        /// <summary>
+        /// policy 策略,分钟,小时,天数对应的时长(duration) 可以访问的次数
+        /// </summary>
+        public int times { get; set; }
+        public int auth { get; set; }
+    }
 }
 }