Ошибка облачных сообщений Google 500 (внутренняя ошибка сервера)

Google Cloud Messaging Call из PHP. Я много искал с кодом ошибки, многие говорят, что в случае удаления приложения вы можете получить эту ошибку. Но в моем случае приложение не было удалено.

Я пытаюсь отправить push-уведомление от php.

Мой PHP-код выглядит как -

include "../db_con.php";
// Replace with the real server API key from Google APIs
$apiKey = "xxx";

// Message to be sent
$message = "GET DEVICE INFO NOW";

// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';


if(isset($_REQUEST['imei_no']) && $_REQUEST['imei_no']!='')
{
$sql = "SELECT gcmId FROM device_tracker_device_master_tbl WHERE deviceId = ". $_REQUEST["imei_no"] ."";
$result = mysql_query($sql);

if (mysql_num_rows($result)>0) 
{
    while($row = mysql_fetch_assoc($result))  
    {
        // Replace with the real client registration IDs
        $registrationIDs = array( $row["gcmId"] );

        $fields = array(
            'registration_ids' => $registrationIDs,
            'data' => array( "message" => $message ),
        );
        $headers = array(
            'Authorization: key=' . $apiKey,
            'Content-Type: application/json'
        );

        // 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_POSTFIELDS, json_encode( $fields));

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // curl_setopt($ch, CURLOPT_POST, true);
        // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));

        // Execute post
        $result = curl_exec($ch);

        // Close connection
        curl_close($ch);
        // print the result if you really need to print else neglate thi
        echo $result;
        //print_r($result);
        //var_dump($result);
    }
} 
else 
{
    echo "Sorry no device found with this IMEI !!";
}
}

Ошибка выглядит как -

введите описание изображения здесь

1 ответ

Я нашел решение большое спасибо @e4c5

На моем сервере не был установлен CURL, я установил, что с помощью

sudo apt-get install php5-curl

Затем пересчитал apache2, теперь все работает.

sudo /etc/init.d/apache2 restart
Другие вопросы по тегам