我正在使用FCM推送通知进行消息传递所有内容都很好但有时当我想向我得到的人发送推送通知时
Curl failed: Failed to connect to fcm.googleapis.com port 443: Connection timed out
我几乎搜索了所有内容。这里出现类似的问题,但我的端口是开放的 Sending notification message to android device curl error
我的网络也不在代理之下。
问题是否可能是因为经常调用firebase发送通知而导致的?它有一些限制吗?
答案 0 :(得分:0)
可能是这些原因之一。
您的请求发送不正确(以下是供您参考的PHP代码)。
function sendFCMPushNotification(){
$server_key = //"enter your server key here";
$mobile_tokens = array("token 1", "token 2", "token n");
$n_data = array("title"=>"Test Notification", "attribute"=>"3999", "parameter 2"=>"value");
$json_data = [
"to" => implode($mobile_tokens),
"notification" => [
"title" => "FCM PUSH",
"body" => "Text to be shown under the title",
"click_action" => "MAIN_ACTIVITY" // activity to be opened in application, remove this if you dont require one.
],
"data" => $n_data
];
$data = json_encode($json_data);
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$server_key
);
$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_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
//print($result);
if ($result === FALSE) {
print_r('Oops! FCM Send Error: ' . curl_error($ch));
}else{
print_r('WoW! FCM SENT SUCCESSFULLY');
}
curl_close($ch);
}
}