doukunsan5553 2016-03-28 12:31
浏览 48

如何执行Curl以在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;


    ?>
  • 写回答

1条回答 默认 最新

  • dqiatvbi61502 2016-03-30 12:52
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。