diff --git a/AssetManager.API/AssetManager.API.csproj b/AssetManager.API/AssetManager.API.csproj
index 4a3dd4b..4571a3a 100644
--- a/AssetManager.API/AssetManager.API.csproj
+++ b/AssetManager.API/AssetManager.API.csproj
@@ -19,4 +19,10 @@
+
+
+ PreserveNewest
+
+
+
diff --git a/AssetManager.API/Program.cs b/AssetManager.API/Program.cs
index 34b9bed..53d8c1c 100644
--- a/AssetManager.API/Program.cs
+++ b/AssetManager.API/Program.cs
@@ -6,6 +6,9 @@ using System.Text;
var builder = WebApplication.CreateBuilder(args);
+// 初始化SqlSugar配置
+AssetManager.Data.SqlSugarConfig.Initialize(builder.Configuration);
+
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
diff --git a/AssetManager.API/appsettings.json b/AssetManager.API/appsettings.json
index 3c153a6..a570f9e 100644
--- a/AssetManager.API/appsettings.json
+++ b/AssetManager.API/appsettings.json
@@ -7,6 +7,18 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
- "DefaultConnection": "server=localhost;Database=assetmanager;Uid=root;Pwd=your_password;CharSet=utf8mb4;"
+ "Default": "server=localhost;Database=assetmanager;Uid=root;Pwd=your_password;CharSet=utf8mb4;"
+ },
+ "Jwt": {
+ "SecretKey": "your-strong-secret-key-here-2026",
+ "Issuer": "AssetManager",
+ "Audience": "AssetManager"
+ },
+ "Wechat": {
+ "AppId": "wx245f0f3ebcfcf5a7",
+ "AppSecret": "809c740129bc8b434177ce12ef292dd0"
+ },
+ "Tiingo": {
+ "ApiKey": "bd00fee76d3012b047473078904001b33322cb46"
}
}
diff --git a/AssetManager.Data/SqlSugarConfig.cs b/AssetManager.Data/SqlSugarConfig.cs
index fd67de2..49924c9 100644
--- a/AssetManager.Data/SqlSugarConfig.cs
+++ b/AssetManager.Data/SqlSugarConfig.cs
@@ -1,14 +1,34 @@
using SqlSugar;
+using Microsoft.Extensions.Configuration;
namespace AssetManager.Data;
-public class SqlSugarConfig
+public static class SqlSugarConfig
{
+ private static IConfiguration? _configuration;
+
+ ///
+ /// 初始化配置(在Program.cs中调用)
+ ///
+ public static void Initialize(IConfiguration configuration)
+ {
+ _configuration = configuration;
+ }
+
public static ISqlSugarClient GetSqlSugarClient()
{
+ if (_configuration == null)
+ {
+ throw new InvalidOperationException("SqlSugarConfig has not been initialized. Call Initialize() first.");
+ }
+
+ // 从配置读取连接字符串,支持环境变量和appsettings.json
+ var connectionString = _configuration.GetConnectionString("Default")
+ ?? throw new InvalidOperationException("Connection string 'Default' not found in configuration.");
+
return new SqlSugarScope(new ConnectionConfig()
{
- ConnectionString = "server=43.167.226.216;Database=assetmanager;Uid=AssetManager;Pwd=2XpcnYGTpB5BhJyG;CharSet=utf8mb4;",
+ ConnectionString = connectionString,
DbType = DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,
diff --git a/AssetManager.Infrastructure/Services/MarketDataService.cs b/AssetManager.Infrastructure/Services/MarketDataService.cs
index 1f72357..ea124a7 100644
--- a/AssetManager.Infrastructure/Services/MarketDataService.cs
+++ b/AssetManager.Infrastructure/Services/MarketDataService.cs
@@ -19,12 +19,14 @@ public class MarketDataService : IMarketDataService
///
/// 日志记录器
/// HTTP 客户端工厂
- public MarketDataService(ILogger logger, IHttpClientFactory httpClientFactory)
+ public MarketDataService(ILogger logger, IHttpClientFactory httpClientFactory, IConfiguration configuration)
{
_logger = logger;
_httpClient = httpClientFactory.CreateClient();
- // TODO: 从配置读取 Tiingo API Key
- _tiingoApiKey = Environment.GetEnvironmentVariable("TIINGO_API_KEY") ?? "bd00fee76d3012b047473078904001b33322cb46";
+ // 从配置读取 Tiingo API Key,优先环境变量
+ _tiingoApiKey = Environment.GetEnvironmentVariable("TIINGO_API_KEY")
+ ?? configuration["Tiingo:ApiKey"]
+ ?? "bd00fee76d3012b047473078904001b33322cb46";
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Token {_tiingoApiKey}");
}
diff --git a/AssetManager.Services/Services/WechatService.cs b/AssetManager.Services/Services/WechatService.cs
index adb4698..206dcfd 100644
--- a/AssetManager.Services/Services/WechatService.cs
+++ b/AssetManager.Services/Services/WechatService.cs
@@ -1,6 +1,7 @@
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
+using Microsoft.Extensions.Configuration;
namespace AssetManager.Services.Services;
@@ -10,11 +11,11 @@ public class WechatService
private readonly string _appId;
private readonly string _appSecret;
- public WechatService(HttpClient httpClient)
+ public WechatService(HttpClient httpClient, IConfiguration configuration)
{
_httpClient = httpClient;
- _appId = "wx245f0f3ebcfcf5a7"; // 替换为实际的微信小程序AppId
- _appSecret = "809c740129bc8b434177ce12ef292dd0"; // 替换为实际的微信小程序AppSecret
+ _appId = configuration["Wechat:AppId"] ?? "wx245f0f3ebcfcf5a7";
+ _appSecret = configuration["Wechat:AppSecret"] ?? "809c740129bc8b434177ce12ef292dd0";
}
public async Task GetOpenIdAsync(string code)