NotifyCore.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc.Controllers;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using dodohold.core;
  9. namespace molilian.core
  10. {
  11. public partial class NotifyCore
  12. {
  13. static string _base_url = string.Empty;
  14. static string _anpush_url = string.Empty;
  15. static NotifyCore()
  16. {
  17. _anpush_url = Environment.GetEnvironmentVariable("ANPush");
  18. string? publish_url = Environment.GetEnvironmentVariable("NtfyServer");
  19. if (!string.IsNullOrEmpty(publish_url))
  20. {
  21. _base_url = publish_url;
  22. }
  23. }
  24. public static void Notify(string message)
  25. {
  26. if (!string.IsNullOrEmpty(_base_url))
  27. {
  28. NifyPlus.Send(_base_url, new NifyMessage { message = message });
  29. }
  30. }
  31. public static void Notify(NifyMessage message)
  32. {
  33. if (!string.IsNullOrEmpty(_base_url))
  34. {
  35. NifyPlus.Send(_base_url, message);
  36. }
  37. }
  38. public static void AnPushNotify(string title, string content)
  39. {
  40. #if DEBUG
  41. #else
  42. if (!string.IsNullOrEmpty(_anpush_url))
  43. {
  44. string url = _anpush_url;
  45. url = url.Replace("{title}", title?.UrlEncode());
  46. url = url.Replace("{content}", content?.UrlEncode());
  47. try
  48. {
  49. url.HttpRequest();
  50. }
  51. catch (Exception ex) { }
  52. }
  53. #endif
  54. }
  55. }
  56. }