duan198123 2017-01-24 04:01
浏览 78

如何使用Firebase和PHP向使用我的应用安装的所有设备发送通知?

I'm making an existing application which includes notification when there is new content.

Notification is sent to all the gadgets that have installed the application.

How to do it using FCM and PHP?

  • 写回答

1条回答 默认 最新

  • doupang9614 2017-01-24 05:59
    关注

    Here is the PHP code to send notification using FCM.

    <?php
    define('API_ACCESS_KEY', ''); // API access key from Firebase Console
    $registrationIds = array(''); //Token IDs of devices
    
    $msg = array
    (
        'text'  => 'Test Text',
        'title'     => 'Test Title',
    );
    
    $fields = array
    (
        'to'    => $registrationIds[0],
        'notification'      => $msg,
        "priority"=> "high"
    );
    
    $headers = array
    (
        'Authorization: key=' . API_ACCESS_KEY,
        'Content-Type: application/json',
    );
    
    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/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;
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?