我是一名网络开发人员,并聘请ios开发人员为我的客户创建本机应用。客户想要推送通知。我们正在使用firebase,但问题是由于 InvalidRegistration 错误,我无法从我的php脚本发送推送通知。我已经阅读了有关此错误的所有stackoverflow,仍然没有线索如何解决它。
我将device_token保存在mysql表CHAR(64)中。
这是我的剧本:
if (isset($_POST['submit'])) {
// API access key from Google API's Console
define('API_ACCESS_KEY', 'API');
$users = $db->getResults("device_id", "users", "device_id != '' AND travel_stay = '" . $_POST['group'] . "'");
foreach ($users as $user) {
$registrationIds = (string)$user['device_id'];
// prep the bundle
$msg = array(
'message' => $_POST['description'],
'title' => $_POST['title'],
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon');
$fields = array('to' => $registrationIds, 'data' => $msg);
$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;
}
} ?>
我不知道它有什么问题,device_token发错了吗?我该如何解决呢?