我创建了一个面板来发送android的数据消息推送通知。我注意到一种行为,有时对于相同的设备令牌FCM,返回错误消息为无效注册/未注册,但是有时,它发送通知并返回成功。
我正在使用curl发送通知。下面是我的代码:
<?php
// put your code here
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization:key=' . $this->config->item('API_ACCESS_KEY'),
'Content-Type:application/json'
);
$batch_of_1000_user_ids = array(
'tokenXXXXXX1',
'tokenXXX2'
);
$fields = array(
'data' => array(
'id' => $article_id,
'author' => $author,
'title' => $title,
'description' => $desc,
'url' => $url,
'publishedAt' => $publishedAt,
'source' => $source,
'urlToImage' => $urltoImage,
'category' => $categories
),
'registration_ids' => $batch_of_1000_user_ids
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
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_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
?>