diff --git a/Class/HttpServer.cs b/Class/HttpServer.cs index 15c24ad..a40d924 100644 --- a/Class/HttpServer.cs +++ b/Class/HttpServer.cs @@ -22,7 +22,14 @@ namespace SunlightAggregationTerminal.Class DataReceived.ServerPassword = Password; DataReceived.ServerTerminal = Terminal; - await HttpClient(DataReceived.ServerIP); + if (string.IsNullOrWhiteSpace(ip)) + { + App.GlobalData.LogNo = false; + } + else + { + await HttpClient(DataReceived.ServerIP); + } } public static async Task HttpClient(string url) @@ -52,13 +59,13 @@ namespace SunlightAggregationTerminal.Class await e.InvokeNext(); }); }); - config.ConfigurePlugins(a => + /*config.ConfigurePlugins(a => { a.UseReconnection(options => { options.PollingInterval = TimeSpan.FromSeconds(3); }); - }); + });*/ #endregion //配置config @@ -79,14 +86,11 @@ namespace SunlightAggregationTerminal.Class Dat = Dat }; - var t = JsonSerializer.Serialize(dat); - var p = httpclient.RemoteIPHost.Host; - var request = new HttpRequest(); - request.SetContent(new StringHttpContent(t, Encoding.UTF8, "application/scjson")) + request.SetContent(new StringHttpContent(JsonSerializer.Serialize(dat), Encoding.UTF8, "application/scjson")) .InitHeaders() .SetUrl("/api/user-report") - .SetHost(p) + .SetHost(httpclient.RemoteIPHost.Host) .AsPost(); // 创建一个超时操作,10秒后取消 diff --git a/Class/SQLiteConfig.cs b/Class/SQLiteConfig.cs index 5b0d4f8..ef3bd81 100644 --- a/Class/SQLiteConfig.cs +++ b/Class/SQLiteConfig.cs @@ -118,6 +118,12 @@ namespace SunlightAggregationTerminal.Class string sql = "ALTER TABLE Users ADD COLUMN ServerID TEXT;"; SQLitedata.ExecuteNonQuery(sql, null); } + // 检查 ServerID + if (!existingColumns.Contains("ServerHTTP")) + { + string sql = "ALTER TABLE Users ADD COLUMN ServerHTTP TEXT;"; + SQLitedata.ExecuteNonQuery(sql, null); + } // 检查 Group if (!existingColumns.Contains("Groups")) { @@ -250,7 +256,12 @@ namespace SunlightAggregationTerminal.Class { string sql = "ALTER TABLE Server ADD COLUMN ServerID TEXT;"; SQLitedata.ExecuteNonQuery(sql, null); - } + } + if (!existingColumns.Contains("ServerHTTP")) + { + string sql = "ALTER TABLE Server ADD COLUMN ServerHTTP TEXT;"; + SQLitedata.ExecuteNonQuery(sql, null); + } } } // --- 逻辑分支 表不存在,直接创建 --- @@ -266,6 +277,7 @@ namespace SunlightAggregationTerminal.Class Enterprise TEXT, Department TEXT, ServerID TEXT, + ServerHTTP TEXT, Groups TEXT, ProxyID TEXT, LogNo BOOL DEFAULT (0), @@ -307,7 +319,8 @@ namespace SunlightAggregationTerminal.Class CREATE TABLE Server ( START BOOL DEFAULT (0), Server TEXT, - ServerID TEXT + ServerID TEXT, + ServerHTTP TEXT );"; // 复用现有的 ExecuteNonQuery 方法 diff --git a/InfoDetail.xaml.cs b/InfoDetail.xaml.cs index 636c54e..93bccda 100644 --- a/InfoDetail.xaml.cs +++ b/InfoDetail.xaml.cs @@ -16,8 +16,6 @@ public partial class InfoDetail : ContentPage InfoProbuctItems.Add(new ProbuctItem { ProductName="cs", ProductCode="cs", ProductState="", ProductInf="" }); InfoProbuctItems.Add(new ProbuctItem { ProductName = "c23s", ProductCode = "cweds", ProductState = "", ProductInf = "" }); - InfoProbuctItems.Add(new ProbuctItem { ProductName = "arf", ProductCode = "af", ProductState = "", ProductInf = "" }); - InfoProbuctItems.Add(new ProbuctItem { ProductName = "afars", ProductCode = "cs", ProductState = "", ProductInf = "" }); @@ -26,6 +24,7 @@ public partial class InfoDetail : ContentPage CardCollectionView_history.ItemsSource = InfoDyelotDetailsItems; } + //设备信息 private void Button_real(object sender, EventArgs e) { _real.IsVisible = true; @@ -34,6 +33,7 @@ public partial class InfoDetail : ContentPage _control.IsVisible = false; } + //设备内容 private void Button_machine(object sender, EventArgs e) { _real.IsVisible = false; @@ -42,6 +42,7 @@ public partial class InfoDetail : ContentPage _control.IsVisible = false; } + //历史 private void Button_history(object sender, EventArgs e) { _real.IsVisible = false; @@ -50,6 +51,7 @@ public partial class InfoDetail : ContentPage _control.IsVisible = false; } + //远程 private async void Button_control(object sender, EventArgs e) { _real.IsVisible = false; diff --git a/Models/AppModels.cs b/Models/AppModels.cs index d46468d..e62d7c4 100644 --- a/Models/AppModels.cs +++ b/Models/AppModels.cs @@ -34,6 +34,7 @@ namespace SunlightAggregationTerminal.Models App.GlobalData.Department = dat.Field("Department") ?? ""; App.GlobalData.Groups = dat.Field("Groups") ?? ""; App.GlobalData.ServerID = dat.Field("ServerID") ?? ""; + App.GlobalData.ServerHTTP = dat.Field("ServerHTTP") ?? ""; App.GlobalData.ProxyID = dat.Field("ProxyID") ?? ""; App.GlobalData.LogNo = Convert.ToBoolean(dat.Field("LogNo")); App.GlobalData.LocalAreaNetworkMode = Convert.ToBoolean(dat.Field("LocalAreaNetworkMode")); @@ -83,7 +84,7 @@ namespace SunlightAggregationTerminal.Models else { //http - HttpServer.Configuration(App.GlobalData.ServerID, + HttpServer.Configuration(App.GlobalData.ServerHTTP, App.GlobalData.User, App.GlobalData.UserPassword, GetAppUniqueId()); } diff --git a/Models/DataModel.cs b/Models/DataModel.cs index d1554b2..78c3414 100644 --- a/Models/DataModel.cs +++ b/Models/DataModel.cs @@ -23,6 +23,8 @@ namespace SunlightAggregationTerminal.Models [ObservableProperty] public partial string ServerID { get; set; } [ObservableProperty] + public partial string ServerHTTP { get; set; } + [ObservableProperty] public partial string Groups { get; set; } [ObservableProperty] public partial string ProxyID { get; set; } diff --git a/Platforms/Android/NotificationService.cs b/Platforms/Android/NotificationService.cs new file mode 100644 index 0000000..7345fa9 --- /dev/null +++ b/Platforms/Android/NotificationService.cs @@ -0,0 +1,81 @@ +using Android.App; +using Android.Content; +using Android.OS; +using AndroidX.Core.App; +using SunlightAggregationTerminal; +// 使用 global:: 强制指定原生安卓的命名空间 +using AndroidApp = global::Android.App; + +namespace SunlightAggregationTerminal.Platforms.Android +{ + public class NotificationService : INotificationService + { + const string channelId = "default_channel"; + const string channelName = "Default Notifications"; + const string channelDescription = "Default notification channel"; + + public void SendNotification(string title, string message, int notificationId = 0) + { + // 1. 创建通知渠道(仅 Android 8.0 / API 26 及以上需要) +#pragma warning disable CA1416 // 暂时关闭平台兼容性警告 + if (Build.VERSION.SdkInt >= BuildVersionCodes.O) + { + var channel = new AndroidApp.NotificationChannel(channelId, channelName, NotificationImportance.Default) + { + Description = channelDescription + }; + + // 修复点:获取系统服务并处理可能的 null 值 + // 如果 GetSystemService 返回 null,则直接 return 终止方法,防止后续崩溃 + var notificationManager = AndroidApp.Application.Context.GetSystemService(Context.NotificationService) as AndroidApp.NotificationManager; + if (notificationManager == null) return; + + notificationManager.CreateNotificationChannel(channel); + } +#pragma warning restore CA1416 // 恢复平台兼容性警告 + + // 2. 构建通知内容 + var intent = new Intent(AndroidApp.Application.Context, typeof(MainActivity)); + intent.AddFlags(ActivityFlags.ClearTop); + +#pragma warning disable CA1416 + // PendingIntent 同样建议做安全获取 + var pendingIntent = PendingIntent.GetActivity(AndroidApp.Application.Context, 0, intent, PendingIntentFlags.Immutable | PendingIntentFlags.UpdateCurrent); +#pragma warning restore CA1416 // 恢复平台兼容性警告 + + NotificationCompat.Builder notificationBuilder; + + // 核心兼容处理:根据系统版本选择不同的 Builder 构造方法 + if (Build.VERSION.SdkInt >= BuildVersionCodes.O) + { + // Android 8.0+:必须传入 channelId + notificationBuilder = new NotificationCompat.Builder(AndroidApp.Application.Context, channelId); + } + else + { +#pragma warning disable CS0618 + // Android 5.0 ~ 7.x:不支持 channelId,使用旧版单参数构造方法 + notificationBuilder = new NotificationCompat.Builder(AndroidApp.Application.Context); +#pragma warning restore CS0618 + } + + var notification = notificationBuilder! + .SetContentTitle(title)! + .SetContentText(message)! + // 请确保你的 Resources/drawable 文件夹下有这个图标 + //.SetSmallIcon(Resource.Drawable.abc_vector_test)! + .SetAutoCancel(true)! + .SetContentIntent(pendingIntent); + + // 如果是 Android 5.0 (API 21) 及以上,还可以设置锁屏可见等特性 + if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) + { + notification!.SetVisibility(NotificationCompat.VisibilityPublic); + } + + // 3. 发送通知 + var compatManager = NotificationManagerCompat.From(AndroidApp.Application.Context); + compatManager!.Notify(notificationId, notification!.Build()); + } + } +} \ No newline at end of file diff --git a/ProfilePage.xaml b/ProfilePage.xaml index 03c6c79..baa54cf 100644 --- a/ProfilePage.xaml +++ b/ProfilePage.xaml @@ -2,6 +2,8 @@ -