xf 6 сар өмнө
parent
commit
f9ae23c6c2

+ 11 - 3
src/Hotline.Api/Controllers/TestController.cs

@@ -126,9 +126,10 @@ public class TestController : BaseController
     //private readonly ICacheManager<User> _cache;
     //private readonly ICacheManager<User> _cache;
     private readonly ICalcExpireTime _expireTime;
     private readonly ICalcExpireTime _expireTime;
     private readonly IOptions<CityBaseConfiguration> _cityBaseConfiguration;
     private readonly IOptions<CityBaseConfiguration> _cityBaseConfiguration;
+    private readonly ISessionContextProvider _sessionContextProvider;
 
 
 
 
-	public TestController(
+    public TestController(
         //INewRockClient client,
         //INewRockClient client,
         ILogger<TestController> logger,
         ILogger<TestController> logger,
         //IAuthorizeGenerator authorizeGenerator,
         //IAuthorizeGenerator authorizeGenerator,
@@ -178,7 +179,8 @@ ICallApplication callApplication,
         IOptionsSnapshot<AppConfiguration> appOptions,
         IOptionsSnapshot<AppConfiguration> appOptions,
         ISystemSettingCacheManager systemSettingCacheManager,
         ISystemSettingCacheManager systemSettingCacheManager,
         ICalcExpireTime expireTime,
         ICalcExpireTime expireTime,
-        IOptions<CityBaseConfiguration> cityBaseConfiguration
+        IOptions<CityBaseConfiguration> cityBaseConfiguration,
+        ISessionContextProvider sessionContextProvider
 		)
 		)
     {
     {
         _logger = logger;
         _logger = logger;
@@ -229,7 +231,8 @@ ICallApplication callApplication,
         _systemSettingCacheManager = systemSettingCacheManager;
         _systemSettingCacheManager = systemSettingCacheManager;
         _expireTime = expireTime;
         _expireTime = expireTime;
         _cityBaseConfiguration = cityBaseConfiguration;
         _cityBaseConfiguration = cityBaseConfiguration;
-	}
+        _sessionContextProvider = sessionContextProvider;
+    }
 
 
 
 
     [HttpGet("time")]
     [HttpGet("time")]
@@ -685,6 +688,11 @@ ICallApplication callApplication,
     [HttpGet("t4")]
     [HttpGet("t4")]
     public async Task<string> Test4()
     public async Task<string> Test4()
     {
     {
+        var a = _sessionContext.RequiredUserId;
+        var a1 = _sessionContextProvider.SessionContext.RequiredUserId;
+        _sessionContextProvider.SwitchTo(TestSessionContext.Key);
+        var b = _sessionContextProvider.SessionContext.RequiredUserId;
+
         return DateTime.Now.ToString("O");
         return DateTime.Now.ToString("O");
     }
     }
 
 

+ 3 - 1
src/Hotline.Api/StartupExtensions.cs

@@ -23,12 +23,14 @@ using Hotline.CallCenter.Configs;
 using Hotline.Wex;
 using Hotline.Wex;
 using Hotline.Application.CallCenter.Calls;
 using Hotline.Application.CallCenter.Calls;
 using Hotline.Application.CallCenter;
 using Hotline.Application.CallCenter;
+using Hotline.Authentications;
 using Hotline.CallCenter.Calls;
 using Hotline.CallCenter.Calls;
 using Swashbuckle.AspNetCore.SwaggerUI;
 using Swashbuckle.AspNetCore.SwaggerUI;
 using Hotline.Configurations;
 using Hotline.Configurations;
 using Hotline.DI;
 using Hotline.DI;
 using Hotline.Share.Tools;
 using Hotline.Share.Tools;
 using Hotline.Settings.TimeLimitDomain.ExpireTimeSupplier;
 using Hotline.Settings.TimeLimitDomain.ExpireTimeSupplier;
+using XF.Domain.Authentications;
 
 
 namespace Hotline.Api;
 namespace Hotline.Api;
 
 
@@ -74,7 +76,7 @@ internal static class StartupExtensions
             .AddScoped(typeof(IPasswordHasher<>), typeof(PasswordHasher<>))
             .AddScoped(typeof(IPasswordHasher<>), typeof(PasswordHasher<>))
             .AddHttpClient()
             .AddHttpClient()
             ;
             ;
-
+        //services.AddKeyedScoped<ISessionContext, TestSessionContext>(TestSessionContext.Key);
         //cache
         //cache
         services.AddCache(d =>
         services.AddCache(d =>
         {
         {

+ 0 - 44
src/Hotline.Api/config/appsettings.Development.json

@@ -145,53 +145,9 @@
       "VirtualHost": "fwt-master"
       "VirtualHost": "fwt-master"
     }
     }
   },
   },
-  //"SmsAccountInfo": {
-  //  "MessageServerUrl": "http://webservice.fway.com.cn:1432/FWebService.asmx/FWay_Service", //短信发送地址
-  //  "AccountUser": "CS12345", //短信系统账号
-  //  "AccountPwd": "9EE3899305A8FC97D6146CAC6B802E6F", //短信系统密码
-  //  "ReturnAccountUser": "fwkj", //短信回传账号
-  //  "ReturnAccountPwd": "fwkj12" //短信回传密码
-  //},
   "FwClient": {
   "FwClient": {
     "ClientId": "hotline",
     "ClientId": "hotline",
     "ClientSecret": "08db29cc-0da0-4adf-850c-1b2689bd535d"
     "ClientSecret": "08db29cc-0da0-4adf-850c-1b2689bd535d"
   }
   }
-  //"ConfigCenter": {
-  //  "ServerAddresses": [ "http://110.188.24.28:8848" ],
-  //  "Namespace": "17503980-9b0d-4d3e-8e35-c842c41fb888", //debug
-  //  "ServiceName": "hotline"
-  //},
-  //"Tr": {
-  //  //"Address": "http://internal.ttf-cti.com:8080",
-  //  //"Username": "yscs",
-  //  //"Password": "123456",
-  //  "Address": "http://222.213.23.229:29003/",
-  //  "Username": "root",
-  //  "Password": "12345678aa",
-  //  "Ip": "222.213.23.229"
-  //},
-  ////智能回访
-  //"AiVisit": {
-  //  "Url": "http://118.122.73.80:19061",
-  //  "Appkey": "MTAwMDAx",
-  //  "ServiceVersion": "V1.0.0" //接口版本号
-  //},
-  ////智能质检
-  //"AiQuality": {
-  //  "Url": "http://118.122.73.80:19072/" // 正式
-  //  //"Url": "http://118.122.73.80:19072/", // 测试
-  //},
-  ////企业服务
-  //"Enterprise": {
-  //  "AddressUrl": "http://10.12.185.227:8834/",
-  //  "ClientId": "1462598736",
-  //  "ClientSecret": "6nZtVK4rKfnsncGymUHB",
-  //  "TenantId": "000000"
-  //},
-
-  //"SendSms": {
-  //  "Url": "http://localhost:50108/api/v1/PushMessage/addwaitmsg"
-  //}
-
 
 
 }
 }

+ 50 - 1
src/Hotline/Authentications/ProvinceSessionContext.cs

@@ -1,10 +1,13 @@
 using Hotline.Configurations;
 using Hotline.Configurations;
+using Microsoft.Extensions.Options;
 using XF.Domain.Authentications;
 using XF.Domain.Authentications;
 
 
 namespace Hotline.Authentications
 namespace Hotline.Authentications
 {
 {
     public class ProvinceSessionContext : ISessionContext
     public class ProvinceSessionContext : ISessionContext
     {
     {
+        public const string Key = "ProvinceSessionContext";
+
         public ProvinceSessionContext(CityProvinceConfiguration config)
         public ProvinceSessionContext(CityProvinceConfiguration config)
         {
         {
             UserId = config.UserId;
             UserId = config.UserId;
@@ -26,7 +29,7 @@ namespace Hotline.Authentications
         /// <exception cref="AuthenticationException"></exception>
         /// <exception cref="AuthenticationException"></exception>
         public string RequiredUserId => UserId ?? throw new ArgumentNullException();
         public string RequiredUserId => UserId ?? throw new ArgumentNullException();
         //取消写入
         //取消写入
-		public string? UserName { get; set; }
+        public string? UserName { get; set; }
         public string? Phone { get; set; }
         public string? Phone { get; set; }
 
 
         /// <summary>
         /// <summary>
@@ -52,4 +55,50 @@ namespace Hotline.Authentications
         /// </summary>
         /// </summary>
         public string? StaffNo { get; set; }
         public string? StaffNo { get; set; }
     }
     }
+
+    public class TestSessionContext : ISessionContext
+    {
+        public const string Key = "TestSessionContext";
+
+        public TestSessionContext(IOptions<CityBaseConfiguration> options)
+        {
+            UserId = options.Value.CityProvince.UserId;
+        }
+
+        /// <summary>
+        /// Id of current tenant or null for host
+        /// </summary>
+        public string? UserId { get; set; }
+
+        /// <summary>
+        /// Id of current user or throw Exception for guest
+        /// </summary>
+        /// <exception cref="AuthenticationException"></exception>
+        public string RequiredUserId { get; }
+        public string? UserName { get; set; }
+        public string? Phone { get; set; }
+
+        /// <summary>
+        /// Roles
+        /// </summary>
+        public string[] Roles { get; set; }
+        public string? OrgId { get; set; }
+        public string RequiredOrgId { get; }
+        public string? OrgName { get; set; }
+        public int OrgLevel { get; set; }
+        public string? OrgAreaCode { get; set; }
+        public bool OrgIsCenter { get; set; }
+
+        /// <summary>
+        /// 部门行政区划名称
+        /// </summary>
+        public string? OrgAreaName { get; set; }
+        public string? AreaId { get; set; }
+        public string? ClientId { get; set; }
+
+        /// <summary>
+        /// 工号
+        /// </summary>
+        public string? StaffNo { get; set; }
+    }
 }
 }

+ 11 - 7
src/Hotline/Authentications/SessionContextProvider.cs

@@ -1,4 +1,5 @@
 using Hotline.Configurations;
 using Hotline.Configurations;
+using Microsoft.Extensions.DependencyInjection;
 using XF.Domain.Authentications;
 using XF.Domain.Authentications;
 using XF.Domain.Dependency;
 using XF.Domain.Dependency;
 
 
@@ -6,19 +7,22 @@ namespace Hotline.Authentications;
 
 
 public class SessionContextProvider : ISessionContextProvider, IScopeDependency
 public class SessionContextProvider : ISessionContextProvider, IScopeDependency
 {
 {
+    private readonly IServiceProvider _serviceProvider;
     public ISessionContext SessionContext { get; set; }
     public ISessionContext SessionContext { get; set; }
 
 
-    public SessionContextProvider(ISessionContext sessionContext)
+    public SessionContextProvider(IServiceProvider serviceProvider, ISessionContext sessionContext)
     {
     {
+        _serviceProvider = serviceProvider;
         SessionContext = sessionContext;
         SessionContext = sessionContext;
     }
     }
 
 
-    public void Switch(string key)
+    public void SwitchTo(string key)
     {
     {
-        SessionContext = new ProvinceSessionContext(new CityProvinceConfiguration
-        {
-            UserId = "123",
-            UserName = "abc"
-        });
+        //SessionContext = new ProvinceSessionContext(new CityProvinceConfiguration
+        //{
+        //    UserId = "123",
+        //    UserName = "abc"
+        //});
+        SessionContext = _serviceProvider.GetRequiredKeyedService<ISessionContext>(key);
     }
     }
 }
 }

+ 1 - 1
src/XF.Domain/Authentications/ISessionContextProvider.cs

@@ -10,6 +10,6 @@ namespace XF.Domain.Authentications
     {
     {
         public ISessionContext SessionContext { get; set; }
         public ISessionContext SessionContext { get; set; }
 
 
-        public void Switch(string key);
+        public void SwitchTo(string key);
     }
     }
 }
 }