2016-07-29 105 views
0

在今天之前,我已经在Android中使用Fire base Cloud Messaging实现了推送通知。但现在,它不工作。如何解决FCM curl失败的错误?

它显示了这样的错误:

卷曲失败:无法连接到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; 



?> 

现在如何解决它?

回答

0

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

相关问题