APNsTools.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using EyeSoft.Runtime.InteropServices;
  2. using OASystem.API.Controllers;
  3. using OASystem.API.OAMethodLib.Hub.Hubs;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Infrastructure.Repositories.Login;
  6. namespace OASystem.API.OAMethodLib.APNs
  7. {
  8. public static class APNsTools
  9. {
  10. private static readonly DeviceTokenRepository _deviceTokenRep = AutofacIocManager.Instance.GetService<DeviceTokenRepository>();
  11. //private static readonly IAPNsService _APNsService = AutofacIocManager.Instance.GetService<IAPNsService>();
  12. public static async Task<Result> iOS_PushNotifications(string Numbers, string title, string subtitle, string body)
  13. {
  14. Result rst2 = new Result() { Code = -1, Msg = "" };
  15. try
  16. {
  17. var _APNsService = AutofacIocManager.Instance.GetService<IAPNsService>();
  18. var rst = await _deviceTokenRep.Query(s => s.Number == Numbers).FirstAsync();
  19. //var rst = new Sys_DeviceToken() { DeviceToken = "08be7ba1ee42ecf36f695fd6b795b5e203295eaed0ba3857276141dbeee025ff" }
  20. if (rst != null)
  21. {
  22. rst2 = await _APNsService.PushNotification("com.panamerican.oa2024", rst.DeviceToken, NotificationType.Alert, title, subtitle, body);
  23. }
  24. }
  25. catch (Exception ex)
  26. {
  27. }
  28. return rst2;
  29. }
  30. public static async Task<Result> iOS_PushNotifications1(string Numbers, string title, string subtitle, string body, bool isTarget, string viewCode, PageParam_PriceAuditH5 pageParam)
  31. {
  32. Result rst2 = new Result() { Code = -1, Msg = "" };
  33. try
  34. {
  35. var _APNsService = AutofacIocManager.Instance.GetService<IAPNsService>();
  36. var rst = await _deviceTokenRep.Query(s => s.Number == Numbers).FirstAsync();
  37. //var rst = new Sys_DeviceToken() { DeviceToken = "08be7ba1ee42ecf36f695fd6b795b5e203295eaed0ba3857276141dbeee025ff" }
  38. if (rst != null)
  39. {
  40. rst2 = await _APNsService.PushNotification1("com.panamerican.oa2024", rst.DeviceToken, NotificationType.Alert, title, subtitle, body, isTarget, viewCode, pageParam);
  41. }
  42. }
  43. catch (Exception ex)
  44. {
  45. rst2.Msg = $"[iOS_PushNotifications1] --> MSG:{ex.Message}";
  46. rst2.Msg = $"[iOS_PushNotifications1] --> InnerException:{ex.InnerException .Message}";
  47. }
  48. return rst2;
  49. }
  50. }
  51. }