How use php curl to send push message in Firefox -


i have implemented push notifications chrome, , in point when need send push message gcm, used following php function:

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 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); } 

(i have stored subscriptions previously)

i think can firefox, using url: https://updates.push.services.mozilla.com/push

but don't know have do.

i need register website mozilla that, in google?

please help!

my own solution, (a colleague has helped bug in curl request mozilla), working now

function send_push_message($subscriptionids){  if (empty($subscriptionids)) return false; $chs = $schrome = array(); $mh = curl_multi_init(); foreach ($subscriptionids $subscription){     $i = count($chs);     switch ($subscription["browser"]){         case "firefox":             $chs[ $i ] = curl_init();             curl_setopt($chs[ $i ], curlopt_url, "https://updates.push.services.mozilla.com/push/".$subscription["id"] );             curl_setopt($chs[ $i ], curlopt_put, true);             curl_setopt($chs[ $i ], curlopt_httpheader, array( "ttl: 86400" ) );             curl_setopt($chs[ $i ], curlopt_returntransfer, true);             curl_setopt($chs[ $i ], curlopt_ssl_verifypeer, false);              curl_multi_add_handle($mh, $chs[ $i ]);         break;         case "chrome":             $schrome[] = $subscription["id"];         break;         } } if (!empty($schrome)){     $i = count($chs);     $chs[ $i ] = curl_init();     curl_setopt($chs[ $i ], curlopt_url, "https://android.googleapis.com/gcm/send" );     curl_setopt($chs[ $i ], curlopt_post, true);     curl_setopt($chs[ $i ], curlopt_httpheader, array( "authorization: key=my_key", "content-type: application/json" ) );     curl_setopt($chs[ $i ], curlopt_returntransfer, true);     curl_setopt($chs[ $i ], curlopt_ssl_verifypeer, false);     curl_setopt($chs[ $i ], curlopt_postfields, json_encode( array( "registration_ids" => $schrome ) ) );     curl_multi_add_handle($mh, $chs[ $i ]); }  {     curl_multi_exec($mh, $running);     curl_multi_select($mh); } while ($running > 0);  ($i = 0; $i < count($chs); $i++){     curl_multi_remove_handle($mh, $chs[ $i ]); }              curl_multi_close($mh); } 

($subscriptionids array of arrays 2 keys: id , browser)


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -