feat: 添加推送通知功能,支持订阅和发送通知
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
27
WebApi/Controllers/NotificationController.cs
Normal file
27
WebApi/Controllers/NotificationController.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace WebApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class NotificationController(INotificationService notificationService) : ControllerBase
|
||||
{
|
||||
[HttpGet("vapid-public-key")]
|
||||
public async Task<IActionResult> GetVapidPublicKey()
|
||||
{
|
||||
var key = await notificationService.GetVapidPublicKeyAsync();
|
||||
return Ok(new { publicKey = key });
|
||||
}
|
||||
|
||||
[HttpPost("subscribe")]
|
||||
public async Task<IActionResult> Subscribe([FromBody] PushSubscriptionEntity subscription)
|
||||
{
|
||||
await notificationService.SubscribeAsync(subscription);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost("test")]
|
||||
public async Task<IActionResult> TestNotification([FromQuery] string message)
|
||||
{
|
||||
await notificationService.SendNotificationAsync(message);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,4 @@ global using Microsoft.AspNetCore.Mvc;
|
||||
global using WebApi.Controllers.Dto;
|
||||
global using Repository;
|
||||
global using Entity;
|
||||
global using System.Text.Json;
|
||||
global using System.Text;
|
||||
global using System.Text.Json.Serialization;
|
||||
@@ -6,6 +6,11 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"NotificationSettings": {
|
||||
"Subject": "mailto:sunchengsuncheng@gmail.com",
|
||||
"PublicKey": "BL47vTtPwIb3vUsErdSQ0UtzTXFs2DJkdAefxTVSHGOlqoJOhKsHVgxoUsWt0YILYMe9R-cocG8Vd0zyj_eEfKM",
|
||||
"PrivateKey": "wBMHddu7F3hK9ZodyYKF0F-Xf1_HeHLIo8ZddCrkINM"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=database/EmailBill.db"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user