簡體   English   中英

發送通知消息到android設備curl錯誤

[英]Sending notification message to android device curl error

我正在嘗試使用輸出表單下面的代碼向Android設備發送通知消息,結果是

Curl failed: Failed to connect to android.googleapis.com port 443: 
Connection timed out

我的服務器是Amazon EC2。

我的代碼:

public function send_notification($registatoin_ids, $message) {
    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';
    $fields = array(
        'registration_ids' => $registatoin_ids,
        'data' => $message,
    );
    $headers[] = 'Content-Type:application/json';
    $headers[] = 'Authorization:key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    // Open connection
    $ch = curl_init();
    // Set the url, number of POST vars, POST data
    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_FOLLOWLOCATION, false);
    curl_setopt($ch, CURLOPT_HEADER, true);
    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    // Execute post
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }
    // Close connection
    curl_close($ch);
    echo $result;
}

我只是在另一台正在工作的服務器上嘗試了代碼

{"multicast_id":5322863685330856855,"success":1,"failure":0,"canonical_ids":0,
"results":[{"message_id":"0:1401820119301203%a5dcde78f9fd7ecd"}]}

所以我認為Amazon EC2設置有問題

我發現我的代碼正確的問題,服務器上的端口443未打開

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM