从 db 获取多个设备令牌并使用 PHP 发送 FCm



>我必须从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;

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

前任:

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

Insde sendNotification(( put yor FCM code.

相关内容

  • 没有找到相关文章

最新更新