diff --git a/Program.cs b/Program.cs index 251e3ad..688919c 100644 --- a/Program.cs +++ b/Program.cs @@ -34,7 +34,8 @@ var app = builder.Build(); const string API_KEY = "UiHMqtaYLZzwBdcuS4RFmEGhgDO8N2eI"; app.Use(async (context, next) => { - var key = context.Request.Headers["X-API-Key"].FirstOrDefault(); + var key = context.Request.Headers["X-API-Key"].FirstOrDefault() + ?? context.Request.Query["key"].FirstOrDefault(); if (key != API_KEY) { context.Response.StatusCode = 401; diff --git a/README.md.md b/README.md.md index 1f900ef..e7212c3 100644 --- a/README.md.md +++ b/README.md.md @@ -121,6 +121,23 @@ const string API_KEY = "你的随机密码"; 修改后重新编译,将新的 `Mt5Bridge.dll` 覆盖到目标主机。 +### 更新 DLL(服务运行时) + +Bridge 作为后台服务运行时,文件被锁定无法直接覆盖。需要先停止再覆盖: + +```powershell +# 阻止任务计划再次触发 +Stop-ScheduledTask -TaskName "Mt5Bridge" + +# 强制结束当前进程 +taskkill /f /im dotnet.exe + +# 现在可以覆盖 Mt5Bridge.dll 了 + +# 重新启动 +Start-ScheduledTask -TaskName "Mt5Bridge" +``` + --- ## 四、端口映射(公网访问) @@ -180,12 +197,23 @@ Unregister-ScheduledTask -TaskName "Mt5Bridge" -Confirm:$false ## 六、API 接口 -所有接口均需在 Header 中携带 API Key: +所有接口均需认证,支持两种方式: +**方式一:Header(推荐,适用于代码调用)** ``` X-API-Key: 你的密码 ``` +**方式二:URL 参数(适用于浏览器直接访问)** +``` +?key=你的密码 +``` + +示例: +``` +http://IP:端口/health?key=你的密码 +``` + ### 健康检查 ``` @@ -407,6 +435,16 @@ GET /history/deals?date_from={from}&date_to={to}&symbol={symbol} ## 七、调用示例 +### 浏览器 + +直接在地址栏输入(带 `?key=` 参数): + +``` +http://IP:端口/health?key=你的密码 +http://IP:端口/account?key=你的密码 +http://IP:端口/symbols/XAUUSDc/tick?key=你的密码 +``` + ### PowerShell ```powershell diff --git a/bin/Debug/net8.0/Mt5Bridge.dll b/bin/Debug/net8.0/Mt5Bridge.dll index 0cd8ecf..f79b3e1 100644 Binary files a/bin/Debug/net8.0/Mt5Bridge.dll and b/bin/Debug/net8.0/Mt5Bridge.dll differ diff --git a/bin/Debug/net8.0/Mt5Bridge.exe b/bin/Debug/net8.0/Mt5Bridge.exe index 9b91761..eae3425 100644 Binary files a/bin/Debug/net8.0/Mt5Bridge.exe and b/bin/Debug/net8.0/Mt5Bridge.exe differ diff --git a/bin/Debug/net8.0/Mt5Bridge.pdb b/bin/Debug/net8.0/Mt5Bridge.pdb index 9b05231..25e0765 100644 Binary files a/bin/Debug/net8.0/Mt5Bridge.pdb and b/bin/Debug/net8.0/Mt5Bridge.pdb differ diff --git a/obj/Debug/net8.0/Mt5Bridge.AssemblyInfo.cs b/obj/Debug/net8.0/Mt5Bridge.AssemblyInfo.cs index 633a100..bf2f7aa 100644 --- a/obj/Debug/net8.0/Mt5Bridge.AssemblyInfo.cs +++ b/obj/Debug/net8.0/Mt5Bridge.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Mt5Bridge")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+279385d8fc1eedefb38ed10aca22ab8ff3708014")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ac1153c0914bcde0cebee04271eb48f6047e7c85")] [assembly: System.Reflection.AssemblyProductAttribute("Mt5Bridge")] [assembly: System.Reflection.AssemblyTitleAttribute("Mt5Bridge")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net8.0/Mt5Bridge.AssemblyInfoInputs.cache b/obj/Debug/net8.0/Mt5Bridge.AssemblyInfoInputs.cache index 3892643..f6bfd86 100644 --- a/obj/Debug/net8.0/Mt5Bridge.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/Mt5Bridge.AssemblyInfoInputs.cache @@ -1 +1 @@ -4235236514da1df525d2d1220aead15991cbafc6db41ab379c545a99c2487020 +3e51f6bbe9ff6ed0893f1911fc810b6691a001b8db244523b3de6ba0c5a11ab4 diff --git a/obj/Debug/net8.0/Mt5Bridge.dll b/obj/Debug/net8.0/Mt5Bridge.dll index 0cd8ecf..f79b3e1 100644 Binary files a/obj/Debug/net8.0/Mt5Bridge.dll and b/obj/Debug/net8.0/Mt5Bridge.dll differ diff --git a/obj/Debug/net8.0/Mt5Bridge.pdb b/obj/Debug/net8.0/Mt5Bridge.pdb index 9b05231..25e0765 100644 Binary files a/obj/Debug/net8.0/Mt5Bridge.pdb and b/obj/Debug/net8.0/Mt5Bridge.pdb differ diff --git a/obj/Debug/net8.0/apphost.exe b/obj/Debug/net8.0/apphost.exe index 9b91761..eae3425 100644 Binary files a/obj/Debug/net8.0/apphost.exe and b/obj/Debug/net8.0/apphost.exe differ diff --git a/obj/Debug/net8.0/ref/Mt5Bridge.dll b/obj/Debug/net8.0/ref/Mt5Bridge.dll index 519f3cb..e7ef212 100644 Binary files a/obj/Debug/net8.0/ref/Mt5Bridge.dll and b/obj/Debug/net8.0/ref/Mt5Bridge.dll differ diff --git a/obj/Debug/net8.0/refint/Mt5Bridge.dll b/obj/Debug/net8.0/refint/Mt5Bridge.dll index 519f3cb..e7ef212 100644 Binary files a/obj/Debug/net8.0/refint/Mt5Bridge.dll and b/obj/Debug/net8.0/refint/Mt5Bridge.dll differ