XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

STHApplication

【MAUI】寄当家——安卓端交易管理系统

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/STHApplication

fix: allow HTTP access to configured server host

aded5cc
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

6 个文件 +30 -10
Modified README.md +1 -1
@@ -16,7 +16,7 @@ Android .NET MAUI 应用与独立 ASP.NET Core 登录授权服务器。管理员
16 16 .\tools\start-server.ps1
17 17 ```
18 18
19 服务器地址硬编码在 `src/JiDangJia/Services/ServerSettings.cs` 的 `BaseUrl` 常量中,APP 无修改入口,也不读取用户地址设置。当前本地测试构建固定为 `http://10.0.2.2:5188`,Android 模拟器直接连接这台电脑的服务器。部署到其他地址时只能修改该常量后重新编译;USB 真机调试可改为 `http://127.0.0.1:5188` 并使用 `adb reverse tcp:5188 tcp:5188`,正式发布改为部署后的 HTTPS 地址。本项目没有向公网部署服务器。
19 服务器地址硬编码在 `src/JiDangJia/Services/ServerSettings.cs` 的 `BaseUrl` 常量中,APP 无修改入口,也不读取用户地址设置。当前构建使用用户提供的 `http://175.178.121.98:5188`。部署到其他地址时修改该常量后重新编译并安装;使用 HTTP 时,还需将主机加入 Android 的 `network_security_config.xml` 允许列表,详见 [服务器部署](docs/服务器部署.md)。本机模拟器可改为 `http://10.0.2.2:5188`;USB 真机调试可改为 `http://127.0.0.1:5188` 并使用 `adb reverse tcp:5188 tcp:5188`,正式发布改为部署后的 HTTPS 地址。
20 20
21 21 ## APP 功能
22 22
Modified artifacts/SHA256.json +6 -6
@@ -1,17 +1,17 @@
1 1 [
2 2 {
3 3 "name": "寄当家-2.1.0.apk",
4 "bytes": 66185893,
5 "sha256": "48d7ec7723bc35bd6cc666ce8ba731795f336fe715863e99800cde1d1d6ab884"
4 "bytes": 65847051,
5 "sha256": "2b2fe47c03010b8be7883909562ee36df7128a897af654cad5f3ea3f4781f905"
6 6 },
7 7 {
8 8 "name": "寄当家-服务器-Windows.zip",
9 "bytes": 49621241,
10 "sha256": "87674d753c1e3f20d34cf3bc83f67d901935e19533dd6e79e3af094def27916c"
9 "bytes": 49621900,
10 "sha256": "4faef0828826be105de0317485711108987e9110a664d783303f1689d005e536"
11 11 },
12 12 {
13 13 "name": "寄当家-源码.zip",
14 "bytes": 1148118,
15 "sha256": "fbd0810446dc8c13f71b862fee58bb32c30c118011079061280f9d612f1fa412"
14 "bytes": 1151367,
15 "sha256": "42f1c1391beddb5dfba7abe87df89094a4c3dcf8b65c5be1515d59908a374ccb"
16 16 }
17 17 ]
Added artifacts/verification/server-connectivity.txt +9 -0
@@ -0,0 +1,9 @@
1 PASS: 2026-10-02 Asia/Shanghai
2 Endpoint: http://175.178.121.98:5188
3 TCP 5188: connected
4 GET /api/health: HTTP 200; status=ok; version=2.1.0
5 Debug build: 0 warnings, 0 errors; separate output directory to avoid Visual Studio file locks
6 Pixel 7 / Android 16 / API 36: updated Debug APK installed with existing app data retained
7 Native APP login with a nonexistent test account: server error "账号或密码错误" received
8 Real administrator credentials were not used or changed
9 Release APK: successfully rebuilt and signed; network-security-config includes 175.178.121.98
Modified docs/服务器部署.md +4 -0
@@ -17,6 +17,10 @@ dotnet server/JiDangJia.Server.dll --urls http://127.0.0.1:5188 --DataDirectory
17 17
18 18 通过 Nginx 或其他代理配置已获有效证书的 HTTPS 域名,代理到 `127.0.0.1:5188`。开发者将 `src/JiDangJia/Services/ServerSettings.cs` 的 `BaseUrl` 修改为实际 HTTPS 根地址后重新编译 APP。该地址无用户配置入口。登录和卡密接口使用 Bearer 令牌;管理接口只接受管理员会话,不需要对外提供网页后台。
19 19
20 使用 HTTP 地址测试时,还需在 `src/JiDangJia/Platforms/Android/Resources/xml/network_security_config.xml` 的 `cleartextTrafficPermitted="true"` 区域添加服务器主机。`<domain>` 只填写 IP 或域名,不含 `http://`、端口或路径;例如 `<domain>175.178.121.98</domain>`。这个主机允许列表随 APK 打包,仅修改 `BaseUrl` 或热重载页面无法更新,必须重新构建并安装 APP。有效证书的 HTTPS 地址不需要加入 HTTP 允许列表,参见 [Android 网络安全配置](https://developer.android.com/privacy-and-security/security-config#CleartextTrafficPermitted)。
21
22 排查时先访问实际服务器的 `/api/health`。2026 年 10 月 2 日检查 `http://175.178.121.98:5188/api/health` 返回 HTTP 200,版本 2.1.0,TCP 5188 可以连接;当时 APP 的 HTTP 主机列表没有此 IP,因此客户端网络配置阻止了请求。本次已添加该主机,并重新编译安装至 Pixel 7 / API 36 模拟器。APP 使用不存在的测试账户发起登录后,界面收到服务器返回的「账号或密码错误」,验证请求已到达登录接口;该检查未使用真实管理员凭证。
23
20 24 将进程配置为 Windows 服务或 systemd 服务,数据目录授予运行账户读写权限。只部署一个写入 SQLite 的服务器实例;扩容为多实例时应迁移到共享数据库。
21 25
22 26 ## 备份与更新
Modified src/JiDangJia/Platforms/Android/Resources/xml/network_security_config.xml +7 -1
@@ -1,5 +1,11 @@
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <network-security-config>
3 3 <base-config cleartextTrafficPermitted="false"><trust-anchors><certificates src="system" /></trust-anchors></base-config>
4 <domain-config cleartextTrafficPermitted="true"><domain>10.0.2.2</domain><domain>localhost</domain><domain>127.0.0.1</domain><domain>192.168.31.22</domain></domain-config>
4 <domain-config cleartextTrafficPermitted="true">
5 <domain>10.0.2.2</domain>
6 <domain>localhost</domain>
7 <domain>127.0.0.1</domain>
8 <domain>192.168.31.22</domain>
9 <domain>175.178.121.98</domain>
10 </domain-config>
5 11 </network-security-config>
Modified src/JiDangJia/Services/ServerSettings.cs +3 -2
@@ -2,6 +2,7 @@ namespace JiDangJia.Services;
2 2
3 3 public static class ServerSettings
4 4 {
5 // Android 模拟器访问宿主机的本地服务器。变更部署地址后必须重新编译 APP。
6 public const string BaseUrl = "http://10.0.2.2:5188";
5 // 服务器固定地址。变更部署地址后必须重新编译 APP。
6 // 使用 HTTP 时,还需将主机加入 Android 的 network_security_config.xml 允许列表。
7 public const string BaseUrl = "http://175.178.121.98:5188";
7 8 }