0
我真的使用Rails和https://github.com/zaru/webpush宝石,并已根据本指南 https://rossta.net/blog/web-push-notifications-from-rails.htmlChrome通知 - 400个UnauthorizedRegistration
我设法注册ServiceWorker并获得订阅配置的东西。我将它保存这样的控制器
endpoint = params[:subscription][:endpoint]
p256dh = params[:subscription][:keys][:p256dh]
auth = params[:subscription][:keys][:auth]
current_user.gcm_endpoint = endpoint
current_user.gcm_p256dh = p256dh
current_user.gcm_auth = auth
后来我发送消息是这样的:
message = {
title: "Title",
body: "This is a test notification",
icon: "images/my-128.png"
}
Webpush.payload_send(
endpoint: current_user.gcm_endpoint,
message: JSON.generate(message),
p256dh: current_user.gcm_p256dh,
auth: current_user.gcm_auth,
ttl: 600,
api_key: "<MY API KEY>"
)
我已经配置并激活帐户谷歌控制台。我已打开GCM API并添加了正确的密钥。但不管我做什么,我都会收到这400个错误代码。而且我在Google控制台中没有统计信息 - 就像没有对我的API调用进行调用一样。
请参阅[此](https://support.google.com/cloud/answer/6310037?hl=zh-CN) –