trupti
trupti

Reputation: 463

How to execute Curl to send notification to users in Firefox

below is my code which i use to execute Push to Chrome Users , now I want to notification to firefox Users , and i know that it will be now targetted via url "https://updates.push.services.mozilla.com/push"

But I don't know what I have to do.

My Code working for Chrome is Provided below .

<?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;


    ?>

Upvotes: 0

Views: 1573

Answers (1)

Callahad
Callahad

Reputation: 1300

You should be able to POST, just like you are above, to the Firefox user's subscription endpoint. You don't need an API key. The only header you need to send is TTL: x where x is the number of seconds you'd like Mozilla to keep the message around in case we can't deliver it immediately.

Good resources for further reading:

Lastly, if you're using Firefox 47 (currently Developer Edition), we've got a whole new suite of tools for debugging Service Workers and Push that you can find at about:debugging#workers.

Upvotes: 1

Related Questions