【问题标题】:Sending notification message to android device curl error向 android 设备 curl 错误发送通知消息
【发布时间】:2014-07-23 23:33:36
【问题描述】:

我正在尝试使用输出表单下方的代码向 android 设备发送通知消息,结果是

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

我的服务器是亚马逊 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"}]}

所以我认为亚马逊 ec2 设置有问题

【问题讨论】:

标签: php android curl amazon-ec2 google-cloud-messaging


【解决方案1】:

我发现问题是我的代码是正确的,服务器上没有打开端口 443

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 2021-06-17
    • 2019-05-09
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多