2016-03-28 26 views
0

は私がChromeユーザーにプッシュを実行するために使用するコードです。今Firefoxユーザーに通知したいと思うので、今度はURL「https://updates.push.services.mozilla.com/push "Curlを実行してFirefoxのユーザーに通知を送信する方法

しかし、私は何をしなければならないのか分かりません。

Chromeで動作するマイコードは以下のとおりです。

<?php 
    include('header.php'); 

    define('API_ACCESS_KEY', '[API-KEY comes here]'); 

    $sql="SELECT * FROM user_data"; 
    $result = mysqli_query($conn, $sql) or die ('Error'.mysqli_error($conn)); 
    $registrationIds=array(); 
    while($row=mysqli_fetch_assoc($result)){ 

     $registrationIds[] = $row['allow']; 
    } 
    $ids=json_encode($registrationIds); 
    $fields = array 
    (
     'registration_ids' => $registrationIds 
    ); 

    $headers = array 
    (
     'Authorization: key=' . API_ACCESS_KEY, 
     'Content-Type: application/json' 
    ); 

    $ch = curl_init(); 
    curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); 
    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)); 
    $result = curl_exec($ch); 
    curl_close($ch); 

    echo $result; 


    ?> 

答えて

1

上記のように、Firefoxユーザーの購読エンドポイントにPOSTできるようにする必要があります。 APIキーは必要ありません。送信する必要があるヘッダはTTL: xです。xは、すぐに配信できない場合に備えてMozillaにメッセージを保存させたい秒数です。さらに読書のための

良いリソース:

最後に、Firefox 47(現在のDeveloper Edition)をお使いの場合、about:debugging#workersにあるa whole new suite of tools for debugging Service Workers and Pushが見つかりました。

関連する問題