WebPush 服务器
从 Delphi 服务器发送 WebPush 通知。内置 VAPID 签名、AES128GCM 有效载荷加密,以及规范要求的订阅管理端点。
从 Delphi 服务器发送 WebPush 通知。内置 VAPID 签名、AES128GCM 有效载荷加密,以及规范要求的订阅管理端点。
WebPush 依赖方组件 — 注册订阅、加密有效载荷(RFC 8291)、使用 VAPID 签名请求(RFC 8292),并将通知推送至用户的推送端点。
TsgcWSAPIServer_WebPush
Windows, macOS, Linux, iOS, Android
Enterprise
配置 VAPID 密钥对,附加内嵌的 TsgcWebPush_Client(或直接使用),然后以订阅端点和有效载荷调用 SendNotification。
uses
sgcWebSocket, sgcWebSocket_Server_APIs;
var
Server: TsgcWebSocketHTTPServer;
WebPush: TsgcWSAPIServer_WebPush;
begin
Server := TsgcWebSocketHTTPServer.Create(nil);
Server.Port := 8443;
Server.SSL := True;
WebPush := TsgcWSAPIServer_WebPush.Create(nil);
WebPush.Server := Server;
WebPush.VAPID.Subject := 'mailto:admin@example.com';
WebPush.VAPID.PrivateKey.LoadFromFile('vapid-priv.pem');
WebPush.VAPID.PublicKey.LoadFromFile ('vapid-pub.pem');
Server.Active := True;
// later, when you have a subscription record
WebPush.SendNotification(
'https://fcm.googleapis.com/wp/...', // endpoint
'p256dh-public-key', // from PushSubscription.getKey(p256dh)
'auth-secret', // from PushSubscription.getKey(auth)
'{"title":"Hello","body":"Notification body"}');
end;
完整的 WebPush 中继 — 管理订阅并发送经 VAPID 签名、AES128GCM 加密的通知。
在内嵌 HTTP 服务器上托管 POST /webpush/subscribe 与 DELETE /webpush/unsubscribe 接口,使浏览器客户端能够向您注册其 PushSubscription。
遵循 RFC 8292,组件使用 ES256 JWT 为每次推送签名,并在 Crypto-Key 头部包含 VAPID 公钥。联系人主体(mailto:)可配置。
实现 RFC 8291 消息加密:通过 ECDH 与用户的 p256dh 派生共享密钥,计算 HKDF 派生密钥,并使用 AES128GCM 加密。
将有效载荷填充至推荐最大值,以防止从密文推断消息长度 — 符合浏览器推送服务的预期。
TsgcWebPush_Client 是一个仅负责发送通知而不托管订阅的配套组件 — 适用于订阅信息存储于独立服务的场景。
标准的 TTL、Urgency 和 Topic 头部作为方法参数公开,让您能够告知推送服务未送达通知的保留时长。
该组件实现的协议权威来源。