TsgcWSAPIServer_WebPush › 事件 › OnWebPushSubscription
当浏览器在调用 PushManager.subscribe() 后向订阅端点发送 POST 请求时触发;接收端点、p256dh 密钥和 auth 密钥以在服务器端持久化。
property OnWebPushSubscription: TsgcWSWebPushSubscription;
// TsgcWSWebPushSubscription = procedure(Sender: TObject; aSubscription: TsgcHTTP_API_WebPush_PushSubscription; var ResponseCode: Integer) of object
—
组件已在内部 Subscriptions 列表中存储了新订阅,使其可通过 BroadcastNotification 访问。使用此事件将传入的订阅持久化到您自己的数据库,并/或应用服务器端验证(认证、速率限制、重复检测)。将 ResponseCode 设为返回给浏览器的 HTTP 状态码,成功时返回 200/201,拒绝时返回 4xx(例如用户未授权时返回 401)。
procedure TForm1.sgcWSAPIServer_WebPush1WebPushSubscription(Sender: TObject;
aSubscription: TsgcHTTP_API_WebPush_PushSubscription; var ResponseCode: Integer);
begin
SaveSubscriptionToDB(aSubscription.Endpoint,
aSubscription.PublicKey,
aSubscription.AuthSecret);
ResponseCode := 201;
end;