我希望通过带有Firebase的FCM发送推播通知到iOS和Android,但出现InvalidRegistration错误。
已经尝试了不同的方法,并且我总是遇到相同的错误,所以我不知道问题出在代码还是某些firebase配置。 这是我所拥有的:
$url = "https://fcm.googleapis.com/fcm/send";
$notification = array('title' =>$message_title , 'body' => $message_body, 'message_type' => $message_type, 'content_id' => $content_id, 'data' => $content_url);
$arrayToSend = array('registration_ids' => $users_token_list,
'priority' => 'high', 'notification' => array('title' => 'Test', 'body' => $message ,'sound'=>'Default','image'=>'Notification Image' ),);
$headers = array('Authorization:key='.$allpush_google_api_key, Content-Type:application/json );
$json = json_encode($arrayToSend);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
echo "RESULT : ". $result;
echo $ch;
if ($result === FALSE || $result === 'JSON_PARSING_ERROR') {
die('Oops! FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
报酬
echo "RESULT : ". $result;
是这样:
{"multicast_id":7490342661176350728,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}
和
echo $ch;
返回:
Resource id #1695
知道我在做什么错吗?