4
发送推送消息
我已经实现推送通知浏览器,并在当我需要发送推送消息给GCM的地步,我用下面的PHP函数:如何使用PHP卷曲在Firefox
function send_push_message($subscription_ids){
// Set GCM endpoint
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $subscription_ids,
);
$headers = array(
'Authorization: key=API_KEY',
'Content-Type: application/json'
);
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Push msg send failed in curl: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
}
(我已经存储了以前的订阅)
我认为我可以做这样的事情的Firefox,使用这个网址:https://updates.push.services.mozilla.com/push
但我不知道我必须做的。
我需要用Mozilla注册我的网站才能做到这一点,就像在谷歌?
请帮忙!
您确定它适用于Firefox吗?我做了同样的事情,但没有奏效。当您发送请求时,您从Mozilla服务器获得的响应格式是什么? –
是的,现在正在我的应用程序中工作。当我通过CURL(curl -X PUT https://updates.push.services.mozilla.com/push/-browser-endpoint-)测试mozilla服务器并且一切正常时,服务器响应是空的。 –
@WilderBatistaGonzález,在Mozilla中我无法发送推送通知,你能帮我吗? –