如何解决FCM curl失败错误?

时间:2016-07-29 09:21:15

标签: android

我已经在Android中使用Fire基础云消息实现了推送通知,在今天它正常工作之前。但现在,它不起作用。

它显示如下错误:

  

卷曲失败:无法连接到fcm.googleapis.com端口443:   连接超时

<?php 

function send_notification ($tokens, $message)
{
    $url = 'https://fcm.googleapis.com/fcm/send';
    $fields = array(
         'registration_ids' => $tokens,
         'data' => $message
        );

    $headers = array(
        'Authorization:key = API KEY ',
        'Content-Type: application/json'
        );

   $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, json_encode($fields));
   $result = curl_exec($ch);           
   if ($result === FALSE) {
       die('Curl failed: ' . curl_error($ch));
   }
   curl_close($ch);
   return $result;
}



$tokens = "Token here..";

$message = array("message" => " FCM PUSH NOTIFICATION TEST MESSAGE");
$message_status = send_notification($tokens, $message);
echo $message_status;



?>

现在如何解决?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,即端口没有。由于某种原因,443在服务器上被阻止。现在它的工作正常。 谢谢