jiangjc 1 month ago
parent
commit
8973e37e27

+ 3 - 2
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -30,6 +30,7 @@ using Org.BouncyCastle.Asn1.X509.Qualified;
 using MathNet.Numerics;
 using static OASystem.API.OAMethodLib.JWTHelper;
 using Org.BouncyCastle.Asn1.Ocsp;
+using OASystem.API.OAMethodLib.APNs;
 
 namespace OASystem.API.Controllers
 {
@@ -199,7 +200,7 @@ namespace OASystem.API.Controllers
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.DailyPayment, title, content, userIds, 0);
 
-                await GeneralMethod.iOS_PushNotifications("051", $"日付费用审核", "", content);
+                await APNsTools.iOS_PushNotifications("051", $"日付费用审核", "", content);
             }
             catch (Exception ex)
             {
@@ -242,7 +243,7 @@ namespace OASystem.API.Controllers
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.DailyPayment, title, content, userIds, 0);
 
-                await GeneralMethod.iOS_PushNotifications("051", $"日付费用审核", "", content);
+                await APNsTools.iOS_PushNotifications("051", $"日付费用审核", "", content);
             }
             catch (Exception ex)
             {

+ 9 - 7
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -14,6 +14,7 @@ using NPOI.SS.UserModel;
 using NPOI.SS.Util;
 using NPOI.XSSF.UserModel;
 using OASystem.API.OAMethodLib;
+using OASystem.API.OAMethodLib.APNs;
 using OASystem.API.OAMethodLib.File;
 using OASystem.API.OAMethodLib.Hub.HubClients;
 using OASystem.API.OAMethodLib.Hub.Hubs;
@@ -2767,7 +2768,7 @@ FROM
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
 
-                await GeneralMethod.iOS_PushNotifications("051", $"机票费用审核", "", content);
+                await APNsTools.iOS_PushNotifications("051", $"机票费用审核", "", content);
 
             }
             catch (Exception ex)
@@ -3659,7 +3660,7 @@ FROM
 
             await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
 
-            await GeneralMethod.iOS_PushNotifications("051", $"其他款项费用审核", "", content);
+            await APNsTools.iOS_PushNotifications("051", $"其他款项费用审核", "", content);
 
 
 
@@ -4264,7 +4265,7 @@ FROM
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
 
-                await GeneralMethod.iOS_PushNotifications("051", $"商邀费用审核", "", content);
+                await APNsTools.iOS_PushNotifications("051", $"商邀费用审核", "", content);
             }
             catch (Exception ex)
             {
@@ -7143,7 +7144,7 @@ FROM
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId); 
                 
-                await GeneralMethod.iOS_PushNotifications("051", $"签证费用审核", "", content);
+                await APNsTools.iOS_PushNotifications("051", $"签证费用审核", "", content);
             }
             catch (Exception ex)
             {
@@ -7516,7 +7517,7 @@ FROM
                     string content = $"[更新-OP费用录入填写详情({groupInfo?.TeamName ?? "-"})]一项费用:{(((ccpInfo.PayMoney * ccpInfo.DayRate) / 100) * ccpInfo.PayPercentage).ToString("#0.00")} CNY;";
 
                     await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
-                    await GeneralMethod.iOS_PushNotifications("051", "OP费用审核", "", content);
+                    await APNsTools.iOS_PushNotifications("051", "OP费用审核", "", content);
                 }
                 catch (Exception ex)
                 {
@@ -11060,7 +11061,8 @@ ORDER by  gctggrc.id DESC
 
                 try
                 {
-                    var iosRes = await GeneralMethod.iOS_PushNotifications("051", title, "", content);
+
+                    var iosRes = await APNsTools.iOS_PushNotifications("051", title, "", content);
                     Logs($"【iOS推送通知Exception2】End Response:[{JsonConvert.SerializeObject(iosRes)}]");
                 }
                 catch (Exception ex )
@@ -13195,7 +13197,7 @@ ORDER by  gctggrc.id DESC
                 else if (dto.Status == 2) content = $"[更新-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
-                await GeneralMethod.iOS_PushNotifications("051", $"保险费用审核", "", content);
+                await APNsTools.iOS_PushNotifications("051", $"保险费用审核", "", content);
             }
             catch (Exception ex)
             {

+ 0 - 3
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -2,7 +2,6 @@
 using FluentValidation;
 using Microsoft.AspNetCore.SignalR;
 using OASystem.API.OAMethodLib;
-using OASystem.API.OAMethodLib.APNsLib;
 using OASystem.API.OAMethodLib.Hub.HubClients;
 using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.QiYeWeChatAPI;
@@ -2344,8 +2343,6 @@ OPTION (MAXRECURSION 0); -- 允许无限递归      ";
             var jw = JsonView(false);
 
 
-            APNsLib.pushMsg("com.panamerican.oa2024", "9a624f38602a8d2cc12b8c44c3cb37633e246963ec2bfd7bca2094b59dc9f09c", NotificationType.Alert, "Ver.Production测试", "测试字标题", "测试内容");
-
             return Ok(jw);
         }
 

+ 2 - 4
OASystem/OASystem.Api/OAMethodLib/APNs/APNsService.cs

@@ -6,9 +6,8 @@ using static System.Net.Mime.MediaTypeNames;
 using Microsoft.Net.Http.Headers;
 using Microsoft.Extensions.Configuration;
 using NPOI.SS.Formula.Functions;
-using Serilog;
 
-namespace OASystem.API.OAMethodLib.APNsLib
+namespace OASystem.API.OAMethodLib.APNs
 {
     public enum NotificationType : int
     {
@@ -29,11 +28,10 @@ namespace OASystem.API.OAMethodLib.APNsLib
         private readonly IConfiguration _configuration;
         private readonly IHttpClientFactory _httpClientFactory;
         private readonly Serilog.ILogger _logger;
-        public APNsService(IConfiguration configuration, Serilog.ILogger logger, IHttpClientFactory httpClientFactory)
+        public APNsService(IConfiguration configuration, IHttpClientFactory httpClientFactory)
         {
             this._configuration = configuration;
             this._httpClientFactory = httpClientFactory;
-            this._logger = logger;
 
             //APNsService.baseUrl = this._configuration["apple:pushNotificationServer"];
             APNsService.baseUrl = this._configuration["apple:pushNotificationServer_Production"];

+ 25 - 0
OASystem/OASystem.Api/OAMethodLib/APNs/APNsTools.cs

@@ -0,0 +1,25 @@
+using EyeSoft.Runtime.InteropServices;
+using OASystem.Domain.Entities.Groups;
+using OASystem.Infrastructure.Repositories.Login;
+
+namespace OASystem.API.OAMethodLib.APNs
+{
+    public static class APNsTools
+    {
+        private static readonly DeviceTokenRepository _deviceTokenRep = AutofacIocManager.Instance.GetService<DeviceTokenRepository>();
+        //private static readonly IAPNsService _APNsService = AutofacIocManager.Instance.GetService<IAPNsService>();
+
+        public static async Task<Result> iOS_PushNotifications(string Numbers, string title, string subtitle, string body)
+        {
+            var _APNsService = AutofacIocManager.Instance.GetService<IAPNsService>();
+            var rst = await _deviceTokenRep.Query(s => s.Number == Numbers).FirstAsync();
+            //var rst = new Sys_DeviceToken() { DeviceToken = "08be7ba1ee42ecf36f695fd6b795b5e203295eaed0ba3857276141dbeee025ff" };
+            Result rst2 = new Result() { Code = -1, Msg = "" };
+            if (rst != null)
+            {
+                rst2 = await _APNsService.PushNotification("com.panamerican.oa2024", rst.DeviceToken, NotificationType.Alert, title, subtitle, body);
+            }
+            return rst2;
+        }
+    }
+}

+ 1 - 1
OASystem/OASystem.Api/OAMethodLib/APNs/IAPNsService.cs

@@ -1,4 +1,4 @@
-namespace OASystem.API.OAMethodLib.APNsLib
+namespace OASystem.API.OAMethodLib.APNs
 {
     public interface IAPNsService
     {

+ 3 - 12
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -5,7 +5,7 @@ using Aspose.Words.Layout;
 using Aspose.Words.Saving;
 using Microsoft.AspNetCore.SignalR;
 using Microsoft.International.Converters.PinYinConverter;
-using OASystem.API.OAMethodLib.APNsLib;
+using OASystem.API.OAMethodLib.APNs;
 using OASystem.API.OAMethodLib.File;
 using OASystem.API.OAMethodLib.Hub.HubClients;
 using OASystem.API.OAMethodLib.Hub.Hubs;
@@ -38,8 +38,7 @@ namespace OASystem.API.OAMethodLib
         private static readonly SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
         private static readonly TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
         private static readonly MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
-        private static readonly DeviceTokenRepository _deviceTokenRep = AutofacIocManager.Instance.GetService<DeviceTokenRepository>();
-        private static readonly IAPNsService _APNsService = AutofacIocManager.Instance.GetService<IAPNsService>();
+        
         private static readonly IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
 
         private readonly static string[] weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
@@ -4446,15 +4445,7 @@ namespace OASystem.API.OAMethodLib
 
         #region iOS推送通知
 
-        public static async Task<Result> iOS_PushNotifications(string Numbers, string title, string subtitle, string body)
-        {
-            var rst = await _deviceTokenRep.Query(s => s.Number == Numbers).SingleAsync();
-            Result rst2 = new Result() { Code = -1, Msg = "" };
-            if (rst != null) {
-                rst2 = await _APNsService.PushNotification("com.panamerican.oa2024", rst.DeviceToken, NotificationType.Alert, title, subtitle, body);
-            }
-            return rst2;
-        }
+        
 
 
         #endregion

+ 5 - 2
OASystem/OASystem.Api/Program.cs

@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
 using Microsoft.Extensions.DependencyInjection.Extensions;
 using OASystem.API.Middlewares;
 using OASystem.API.OAMethodLib;
-using OASystem.API.OAMethodLib.APNsLib;
+using OASystem.API.OAMethodLib.APNs;
 using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.JuHeAPI;
 using OASystem.API.OAMethodLib.QiYeWeChatAPI;
@@ -336,11 +336,14 @@ builder.Services.AddSingleton<ALiYunPostMessageJob>();
 builder.Services.AddSingleton<TaskJob>();
 builder.Services.AddSingleton<TaskNewsFeedJob>();
 //# new business
+builder.Services.AddControllersWithViews();
+builder.Services.AddSingleton<IAPNsService, APNsService>();
+
 builder.Services.AddSingleton<IJobFactory, IOCJobFactory>();
 
 #endregion
 
-builder.Services.AddSingleton<IAPNsService,APNsService>();
+
 
 #region SignalR
 builder.Services.AddSignalR()