$ch = curl_init('https://fcm.googleapis.com/fcm/send/');
curl_setopt($ch, CURLOPT_HEADER, ['Content-Type:application/json', 'Authorization:key=253*******92']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ["to" => 'cKZHw****Z6s:APA91bGTJ8AO91xP8V7VjV*********************************IdoigREyYPZnFNfGEl6GMK0nd1Qyslbil47VMREdefI3SCEUdJHwAEF26jFRXYPgdGBMxLOucJ51CI-ud1',
"data" => ["title" => "Portugal vs. Denmark",
"text" => "5 to 1"]]);
curl_exec($ch);
curl_close($ch);
Id пользователя получаю, все есть. Но при попытке отправить curl запрос(POST). Для передачи сообщения пользователю. Получаю сообщение
https://fcm.googleapis.com/fcm/send/
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0
Date: Sun, 07 Mar 2021 01:04:32 GMT
Content-Length: 135
Alt-Svc: h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Connection: close
A valid push subscription endpoint should be specified in the URL as such: https://fcm.googleapis.com/wp/dHIoDxE7Hdg:APA91bH1Zj0kNa...
https://gcm-http.googleapis.com/gcm/send
HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=UTF-8
Date: Sun, 07 Mar 2021 01:06:10 GMT
Expires: Sun, 07 Mar 2021 01:06:10 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-XSS-Protection: 1; mode=block
Server: GSE
Alt-Svc: h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked
Error=DeprecatedEndpoint1
В первом случаи 404 ошибка, во втором 301. Что не так выполняю?
Способ получения id подписки
function urlBase64ToUint8Array(base64String) {
let rawData = window.atob((base64String + '='.repeat((4 - base64String.length % 4) % 4)).replace(/\-/g, '+').replace(/_/g, '/')),
outputArray = new Uint8Array(rawData.length);
for (var i = 0; i < rawData.length; ++i)
outputArray[i] = rawData.charCodeAt(i);
return outputArray;
}
navigator.serviceWorker.register('/sw.js').then(() => {return navigator.serviceWorker.ready;}).then(reg => reg.pushManager.subscribe({userVisibleOnly: true, applicationServerKey: urlBase64ToUint8Array('BAVR1KZoitVgsfJ8ICyp4XE0H4riw8SRIjr26F4TqM7HUrl5f3clkOMLNu_xZkQB__eJ7f_GRmpdC--BZjqmzcA')}).then(sub => {
console.log(sub.endpoint);
}
));
Как я понял, необходимо брать
f-dlS9a_QLk:APA91bEkp83uEx3Y3Tj-_myhkbo7Vyo9RTpN1DtuKGBOPWTBixiuUA0UR_2GXw5t4VY0BH9WmNOycONcQzv_6Rbsx8XRbeFXzYCYe-sQOqYrBWkaH_eoMoRxhYyKtWkpAsUF7vquHrz
это и будет ключ подписки пользователя.