qinchaoyue 2 weeks ago
parent
commit
d8d1a39bcc

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

@@ -220,7 +220,7 @@ internal static class StartupExtensions
         services.AddScoped<IExpireTimeSupplier, WorkDaySupplier>();
         services.AddScoped<IExpireTimeSupplier, HourSupplier>();
 
-        services.AddWeChatService();
+        services.AddWeChatService(configuration);
 
         services.AddScoped<IGuiderSystemService, TiqnQueService>();
 

+ 19 - 10
src/Hotline.Api/config/appsettings.Test.json

@@ -1,12 +1,21 @@
 {
-  "ConnectionStrings": {
-    "Hotline": "PORT=5432;DATABASE=hotline_test;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;",
-    //"Hotline1": "PORT=5432;DATABASE=hotline_dev;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;"
-  },
-  "Cache": {
-    "Host": "110.188.24.182",
-    "Port": 50179,
-    "Password": "fengwo123!$!$",
-    "Database": 2 //hotline:3, dev:5, test:2, demo:4
-  }
+    "ConnectionStrings": {
+        "Hotline": "PORT=5432;DATABASE=hotline_test;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;"
+        //"Hotline1": "PORT=5432;DATABASE=hotline_dev;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;"
+    },
+    "Cache": {
+        "Host": "110.188.24.182",
+        "Port": 50179,
+        "Password": "fengwo123!$!$",
+        "Database": 2 //hotline:3, dev:5, test:2, demo:4
+    },
+    "SenparcWeixinSetting": {
+        "IsDebug": true,
+
+        //小程序
+        "WxOpenAppId": "wx22e6092dd504b567",
+        "WxOpenAppSecret": "bb29f684a9ea6b9d136062d68e867831"
+        //"WxOpenToken": "#{WxOpenToken}#",
+        //"WxOpenEncodingAESKey": "#{WxOpenEncodingAESKey}#"
+    }
 }

+ 6 - 5
src/Hotline.WeChat/Hotline.WeChat.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFramework>net8.0</TargetFramework>
@@ -7,10 +7,11 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Senparc.Weixin" Version="6.19.1" />
-    <PackageReference Include="Senparc.Weixin.AspNet" Version="1.3.1" />
-    <PackageReference Include="Senparc.Weixin.Open" Version="4.20.0" />
-    <PackageReference Include="Senparc.Weixin.WxOpen" Version="3.20.1" />
+    <PackageReference Include="Senparc.CO2NET.Cache.CsRedis" Version="2.2.0.1" />
+    <PackageReference Include="Senparc.Weixin" Version="6.22.0" />
+    <PackageReference Include="Senparc.Weixin.AspNet" Version="1.4.9" />
+    <PackageReference Include="Senparc.Weixin.Open" Version="4.21.11" />
+    <PackageReference Include="Senparc.Weixin.WxOpen" Version="3.23.4" />
   </ItemGroup>
 
   <ItemGroup>

+ 13 - 9
src/Hotline.WeChat/ServiceCollectionExtensions.cs

@@ -19,16 +19,12 @@ using Senparc.Weixin.Entities;
 namespace Hotline.WeChat;
 public static class ServiceCollectionExtensions
 {
-    public static IServiceCollection AddWeChatService(this IServiceCollection services)
+    private readonly static string Name = "SenparcWeixinSetting";
+    private readonly static string KeyName = "WxOpenAppId";
+    public static IServiceCollection AddWeChatService(this IServiceCollection services, ConfigurationManager configuration)
     {
-        var configuration = new ConfigurationManager();
-        configuration.AddInMemoryCollection(new Dictionary<string, string>
-        {
-            { "SenparcWeixinSetting:WxOpenAppId", "#{WxOpenAppId}#" },
-            { "SenparcWeixinSetting:WxOpenAppSecret", "#{WxOpenAppSecret}#" },
-            { "SenparcWeixinSetting:WxOpenToken", "#{WxOpenToken}#" },
-            { "SenparcWeixinSetting:WxOpenEncodingAESKey", "#{WxOpenEncodingAESKey}#" }
-        });
+        var config = configuration.GetSection(Name);
+        if (config.GetSection(KeyName).Value == null) return services;
         services.AddMemoryCache();
         services.AddSenparcWeixin(configuration);
         return services;
@@ -36,6 +32,14 @@ public static class ServiceCollectionExtensions
 
     public static void UseWeChat(this WebApplication app)
     {
+        if (app.Configuration.GetSection(Name).GetSection(KeyName).Value == null) return;
+        //var c = app.Configuration.GetSection("Cache");
+        //var redisConfigurationStr = $"{c.GetSection("Host").Value}:{c.GetSection("Port").Value},password={c.GetSection("Password").Value},connectTimeout=1000,connectRetry=2,syncTimeout=10000,defaultDatabase={c.GetSection("Database").Value}";
+        //app.UseSenparcGlobal(app.Environment, null, globalRegister =>
+        //{
+        //    Senparc.CO2NET.Cache.CsRedis.Register.SetConfigurationOption(redisConfigurationStr);
+        //    Senparc.CO2NET.Cache.CsRedis.Register.UseKeyValueRedisNow();
+        //});
         var registerService = app.UseSenparcWeixin(app.Environment,
           null /* 不为 null 则覆盖 appsettings  中的 SenpacSetting 配置*/,
           null /* 不为 null 则覆盖 appsettings  中的 SenpacWeixinSetting 配置*/,

+ 15 - 3
src/Hotline/Caching/Services/SystemSettingCacheManager.cs

@@ -1,8 +1,11 @@
 using Hotline.Caching.Interfaces;
 using Hotline.Settings;
 using Hotline.Share.Tools;
+using Hotline.ThirdAccountDomainServices.Interfaces;
+using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json.Linq;
+using System.Reflection.Metadata.Ecma335;
 using XF.Domain.Cache;
 using XF.Domain.Dependency;
 using XF.Domain.Exceptions;
@@ -16,12 +19,14 @@ namespace Hotline.Caching.Services
         private readonly ILogger<SystemSettingCacheManager> _logger;
         private readonly ITypedCache<SystemSetting> _cacheSystemSetting;
         private readonly IRepository<SystemSetting> _systemSettingRepository;
+        private readonly IServiceProvider _serviceProvider;
 
-        public SystemSettingCacheManager(ITypedCache<SystemSetting> cacheSystemSetting, IRepository<SystemSetting> systemSettingRepository, ILogger<SystemSettingCacheManager> logger)
+        public SystemSettingCacheManager(ITypedCache<SystemSetting> cacheSystemSetting, IRepository<SystemSetting> systemSettingRepository, ILogger<SystemSettingCacheManager> logger, IServiceProvider serviceProvider)
         {
             _cacheSystemSetting = cacheSystemSetting;
             _systemSettingRepository = systemSettingRepository;
             _logger = logger;
+            _serviceProvider = serviceProvider;
         }
 
         public SystemSetting? GetSetting(string code)
@@ -203,8 +208,15 @@ namespace Hotline.Caching.Services
         /// <summary>
         /// 随手拍功能开关
         /// </summary>
-        public bool Snapshot =>
-            GetOrDefault("08dd0eca-66b8-4c98-8dec-0c76c29d77e3", SettingConstants.Snapshot, "随手拍功能开关", false, "随手拍功能开关");
+        public bool Snapshot
+        {
+            get
+            {
+                var switchBtn = GetOrDefault("08dd0eca-66b8-4c98-8dec-0c76c29d77e3", SettingConstants.Snapshot, "随手拍功能开关", false, "随手拍功能开关");
+                if (_serviceProvider.GetService<IThirdIdentiyService>() == null) return false;
+                return switchBtn;
+            }
+        }
 
         /// <summary>
         /// 是否开启自动填写办理意见至汇总节点