【问题标题】:Fetch Multiple Device Tokens From Db and Send FCm using PHP从 Db 获取多个设备令牌并使用 PHP 发送 FCm
【发布时间】:2017-07-23 09:01:27
【问题描述】:

我必须从 Db 获取设备令牌并将其发送到多个设备 现在我有查询从数据库中获取多个设备令牌

$queryname1 = "SELECT device_id FROM  register where id IN ($particpants)";
    $resultname1 = mysql_query($queryname1) or die('Errant query:  ' . $queryname1);
          $idarray = array();
               while ($idrows = mysql_fetch_assoc($resultname1))
              {
                  $idarray = $idrows['device_id'];
              }

我的 FCm 代码在下面,我无法在此处向我们发送我的代码的 fcm 通知

    define("API_ACCESS_KEY", "********"); 
$registrationIds=$idarray;
         $msg = array
              (
            'body'  => 'Body  Of Notification',
            'title' => 'Title Of Notification',
                    'icon'  => 'myicon',/*Default Icon*/
                    'sound' => 'mySound'/*Default sound*/
              );
        $fields = array
                (
                    'to'        => $registrationIds,
                    'notification'  => $msg
                );
                //print_r($fields);
                //exit;

        //'registration_ids'  => array($registrationIDs),
        $headers = array
                (
                    'Authorization: key=' . API_ACCESS_KEY,
                    'Content-Type: application/json'
                );
    #Send Reponse To FireBase Server    
            $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;

【问题讨论】:

    标签: php mysql firebase firebase-cloud-messaging


    【解决方案1】:

    为 FCM 代码创建一个函数并在循环中调用该函数。

    前:

     while ($idrows = mysql_fetch_assoc($resultname1)){
         $idarray = $idrows['device_id'];
         sendNotification($idrows['device_id']);
     }
    

    Insde sendNotification() 输入你的 FCM 代码。

    【讨论】:

      猜你喜欢
      • 2017-04-01
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      相关资源
      最近更新 更多