| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.AspNetCore.Mvc.Filters;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using dodohold.core;
- namespace molilian.core
- {
- public partial class NotifyCore
- {
- static string _base_url = string.Empty;
- static string _anpush_url = string.Empty;
- static NotifyCore()
- {
- _anpush_url = Environment.GetEnvironmentVariable("ANPush");
- string? publish_url = Environment.GetEnvironmentVariable("NtfyServer");
- if (!string.IsNullOrEmpty(publish_url))
- {
- _base_url = publish_url;
- }
- }
- // 同步版本保持不变
- public static void Notify(string message)
- {
- if (!string.IsNullOrEmpty(_base_url))
- {
- NifyPlus.Send(_base_url, new NifyMessage { message = message });
- }
- }
- // 新增异步版本
- public static async Task NotifyAsync(string message)
- {
- if (!string.IsNullOrEmpty(_base_url))
- {
- await NifyPlus.SendAsync(_base_url, new NifyMessage { message = message });
- }
- }
- // 同步版本保持不变
- public static void Notify(NifyMessage message)
- {
- if (!string.IsNullOrEmpty(_base_url))
- {
- NifyPlus.Send(_base_url, message);
- }
- }
- // 新增异步版本
- public static async Task NotifyAsync(NifyMessage message)
- {
- if (!string.IsNullOrEmpty(_base_url))
- {
- await NifyPlus.SendAsync(_base_url, message);
- }
- }
- // 同步版本保持不变
- public static void AnPushNotify(string title, string content)
- {
- #if DEBUG
- #else
- if (!string.IsNullOrEmpty(_anpush_url))
- {
- string url = _anpush_url;
- url = url.Replace("{title}", title?.UrlEncode());
- url = url.Replace("{content}", content?.UrlEncode());
- try
- {
- url.HttpRequest();
- }
- catch (Exception ex) { }
- }
- #endif
- }
- // 新增异步版本
- public static async Task AnPushNotifyAsync(string title, string content)
- {
- #if DEBUG
- await Task.CompletedTask;
- #else
- if (!string.IsNullOrEmpty(_anpush_url))
- {
- string url = _anpush_url;
- url = url.Replace("{title}", title?.UrlEncode());
- url = url.Replace("{content}", content?.UrlEncode());
- try
- {
- await Task.Run(() => url.HttpRequest());
- }
- catch (Exception ex) { }
- }
- #endif
- }
- }
- }
|