Browse Source

iOS推送通知修改

jiangjc 1 month ago
parent
commit
13fa3990c5

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

@@ -31,6 +31,7 @@ using MathNet.Numerics;
 using static OASystem.API.OAMethodLib.JWTHelper;
 using Org.BouncyCastle.Asn1.Ocsp;
 using OASystem.API.OAMethodLib.APNs;
+using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
 
 namespace OASystem.API.Controllers
 {
@@ -200,7 +201,8 @@ namespace OASystem.API.Controllers
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.DailyPayment, title, content, userIds, 0);
 
-                await APNsTools.iOS_PushNotifications1("051", $"日付费用审核", "", content);
+                PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = "", uid = "21" };
+                await APNsTools.iOS_PushNotifications1("051", "日付费用审核", "", content, true, "ExpenseAuditWebView", h5);
             }
             catch (Exception ex)
             {
@@ -243,7 +245,8 @@ namespace OASystem.API.Controllers
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.DailyPayment, title, content, userIds, 0);
 
-                await APNsTools.iOS_PushNotifications1("051", $"日付费用审核", "", content);
+                PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = "", uid = "21" };
+                await APNsTools.iOS_PushNotifications1("051", "日付费用审核", "", content, true, "ExpenseAuditWebView", h5);
             }
             catch (Exception ex)
             {

+ 15 - 8
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -2768,7 +2768,8 @@ FROM
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
 
-                await APNsTools.iOS_PushNotifications1("051", $"机票费用审核", "", content);
+                PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21" };
+                await APNsTools.iOS_PushNotifications1("051", $"机票费用审核", "", content, true, "ExpenseAuditWebView", h5);
 
             }
             catch (Exception ex)
@@ -4267,7 +4268,8 @@ FROM
 
                 await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
 
-                await APNsTools.iOS_PushNotifications1("051", $"商邀费用审核", "", content);
+                PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21" };
+                await APNsTools.iOS_PushNotifications1("051", $"商邀费用审核", "", content, true, "ExpenseAuditWebView", h5);
             }
             catch (Exception ex)
             {
@@ -7291,9 +7293,9 @@ FROM
                 if (dto.Status == 1) content = $"[新增-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
                 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 APNsTools.iOS_PushNotifications1("051", $"签证费用审核", "", content);
+                await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
+                PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21" };
+                await APNsTools.iOS_PushNotifications1("051", $"签证费用审核", "", content, true, "ExpenseAuditWebView", h5);
             }
             catch (Exception ex)
             {
@@ -7666,7 +7668,9 @@ 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 APNsTools.iOS_PushNotifications1("051", "OP费用审核", "", content);
+                    PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21" };
+                    await APNsTools.iOS_PushNotifications1("051", $"OP费用审核", "", content, true, "ExpenseAuditWebView", h5);
+
                 }
                 catch (Exception ex)
                 {
@@ -11208,7 +11212,8 @@ ORDER by  gctggrc.id DESC
 
                 try
                 {
-                    var iosRes1 = await APNsTools.iOS_PushNotifications1("051", title, "", content);
+                    PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21" };
+                    await APNsTools.iOS_PushNotifications1("051", title, "", content, true, "ExpenseAuditWebView", h5);
                     //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】Start");
                     //var iosRes = await APNsTools.iOS_PushNotifications("051", title, "", content);
                     //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】End Response:[{JsonConvert.SerializeObject(iosRes)}]");
@@ -13343,7 +13348,9 @@ 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 APNsTools.iOS_PushNotifications1("051", $"保险费用审核", "", content);
+
+                PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21" };
+                await APNsTools.iOS_PushNotifications1("051", "保险费用审核", "", content, true, "ExpenseAuditWebView", h5);
             }
             catch (Exception ex)
             {

+ 45 - 16
OASystem/OASystem.Api/OAMethodLib/APNs/APNsService.cs

@@ -40,7 +40,7 @@ namespace OASystem.API.OAMethodLib.APNs
         //private static readonly HttpClient _httpClientFactory = new HttpClient { BaseAddress = new Uri("https://api.push.apple.com:443/3/device/") };
         private readonly IConfiguration _configuration;
         //private readonly IHttpClientFactory _httpClientFactory;
-        public APNsService(ILogger<APNsService> logger,IConfiguration configuration)
+        public APNsService(ILogger<APNsService> logger, IConfiguration configuration)
         {
             this._configuration = configuration;
             //this._httpClientFactory = httpClientFactory;
@@ -100,7 +100,7 @@ namespace OASystem.API.OAMethodLib.APNs
             }
 
             var kid = _configuration["apple:kid"];
-           //var securityKey = _configuration["apple:securityKey"].Replace("\n", "");
+            //var securityKey = _configuration["apple:securityKey"].Replace("\n", "");
             var securityKey = string.Format("MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQglyUl7hjI75YJUVMbZLN6TpkiFzuTXUN+UIjuJA7+y8ugCgYIKoZIzj0DAQehRANCAAS8GR7lKNst4KENCp45OXCMyiytvzK0qdRBrx0l+bMaHjiU+Upfox82G+Xy4wd8hI+0wMDh341aNelqEdYUUx3O");
             var iss = _configuration["apple:iss"];
             var claims = new Claim[]
@@ -143,11 +143,12 @@ namespace OASystem.API.OAMethodLib.APNs
             {
                 return msg += $"[GetnerateAPNsJWTToken] --> ExMsg:[{ex.Message}]";
             }
-            
+
             return APNsService.token;
         }
 
-        public async Task<Result>  PushNotification1(string apnsTopic, string deviceToken, NotificationType type, string title, string subtitle, string body)
+
+        public async Task<Result> PushNotification1(string apnsTopic, string deviceToken, NotificationType type, string title, string subtitle, string body, bool isTarget, string viewCode, PageParam_PriceAuditH5 pageParam)
         {
             var res = new Result() { Code = 0, Msg = "", Data = "" };
 
@@ -155,10 +156,10 @@ namespace OASystem.API.OAMethodLib.APNs
             CurlResources.Init();
             var global = CurlNative.Init();
             var easy = CurlNative.Easy.Init();
-            string content=string.Empty;
+            string content = string.Empty;
             try
             {
-                var token = GetnerateAPNsJWTToken(); 
+                var token = GetnerateAPNsJWTToken();
 
                 var dataCopier = new DataCallbackCopier();
 
@@ -178,18 +179,42 @@ namespace OASystem.API.OAMethodLib.APNs
                     Version = new Version(2, 0)
                 };
 
-                var notContent = new
+                if (isTarget)
                 {
-                    aps = new
+                    var notContent = new
                     {
-                        alert = new
+                        aps = new
                         {
-                            title = title,
-                            subtitle = subtitle,
-                            body = body
+                            alert = new
+                            {
+                                title = title,
+                                subtitle = subtitle,
+                                body = body
+                            }
+                        },
+                        ViewCode = viewCode,
+                        PageParam = pageParam
+                    };
+                    var contentJson = new StringContent(System.Text.Json.JsonSerializer.Serialize(notContent), System.Text.Encoding.UTF8, Application.Json);
+                    CurlNative.Easy.SetOpt(easy, CURLoption.POSTFIELDS, System.Text.Json.JsonSerializer.Serialize(notContent));
+                }
+                else
+                {
+                    var notContent = new
+                    {
+                        aps = new
+                        {
+                            alert = new
+                            {
+                                title = title,
+                                subtitle = subtitle,
+                                body = body
+                            }
                         }
-                    }
-                };
+                    };
+                    var contentJson = new StringContent(System.Text.Json.JsonSerializer.Serialize(notContent), System.Text.Encoding.UTF8, Application.Json);
+                    CurlNative.Easy.SetOpt(easy, CURLoption.POSTFIELDS, System.Text.Json.JsonSerializer.Serialize(notContent));
+                }
 
                 var headers = CurlNative.Slist.Append(SafeSlistHandle.Null, $"Authorization: Bearer {token}");
                 CurlNative.Slist.Append(headers, $"apns-topic: {apnsTopic}");
@@ -197,8 +222,7 @@ namespace OASystem.API.OAMethodLib.APNs
 
                 CurlNative.Easy.SetOpt(easy, CURLoption.HTTPHEADER, headers.DangerousGetHandle());
 
-                var contentJson = new StringContent(System.Text.Json.JsonSerializer.Serialize(notContent), System.Text.Encoding.UTF8, Application.Json);
-                CurlNative.Easy.SetOpt(easy, CURLoption.POSTFIELDS, System.Text.Json.JsonSerializer.Serialize(notContent));
+
 
                 //Your set of ciphers, full list is here https://curl.se/docs/ssl-ciphers.html
                 CurlNative.Easy.SetOpt(easy, CURLoption.SSL_CIPHER_LIST, "ECDHE-RSA-AES256-GCM-SHA384");
@@ -356,5 +380,10 @@ namespace OASystem.API.OAMethodLib.APNs
 
     }
 
+    public class PageParam_PriceAuditH5
+    {
+        public string diid { get; set; }
+        public string uid { get; set; }
+    }
 
 }

+ 2 - 2
OASystem/OASystem.Api/OAMethodLib/APNs/APNsTools.cs

@@ -37,7 +37,7 @@ namespace OASystem.API.OAMethodLib.APNs
             return rst2;
         }
 
-        public static async Task<Result> iOS_PushNotifications1(string Numbers, string title, string subtitle, string body)
+        public static async Task<Result> iOS_PushNotifications1(string Numbers, string title, string subtitle, string body, bool isTarget, string viewCode, PageParam_PriceAuditH5 pageParam)
         {
 
             Result rst2 = new Result() { Code = -1, Msg = "" };
@@ -50,7 +50,7 @@ namespace OASystem.API.OAMethodLib.APNs
                 //var rst = new Sys_DeviceToken() { DeviceToken = "08be7ba1ee42ecf36f695fd6b795b5e203295eaed0ba3857276141dbeee025ff" }
                 if (rst != null)
                 {
-                    rst2 =await  _APNsService.PushNotification1("com.panamerican.oa2024", rst.DeviceToken, NotificationType.Alert, title, subtitle, body);
+                    rst2 = await _APNsService.PushNotification1("com.panamerican.oa2024", rst.DeviceToken, NotificationType.Alert, title, subtitle, body, isTarget, viewCode, pageParam);
                 }
 
             }

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

@@ -30,7 +30,7 @@
         /// <param name="subtitle">子标题</param>
         /// <param name="body">通知内容</param>
         /// <returns></returns>
-        Task<Result> PushNotification1(string apnsTopic, string deviceToken, NotificationType type, string title, string subtitle, string body);
+        Task<Result> PushNotification1(string apnsTopic, string deviceToken, NotificationType type, string title, string subtitle, string body, bool isTarget, string viewCode, PageParam_PriceAuditH5 pageParam);
 
     }
 }