Сбой оповещения PHP Firebase для IOS - PullRequest
0 голосов
/ 27 ноября 2018

У меня есть скрипт push-уведомлений на PHP.Этот сценарий возвращает успешный результат, однако устройство IOS не отображает уведомление.

Я использовал консоль Firebase для тестирования уведомлений.Уведомления успешно отображаются на устройствах IOS.

Мой код PHP:

$msg = array
(
    'body'  => "test",
    'title'     => "test",
    'vibrate'   => 1,
    'sound'     => 1,
);

 sendGoogleCloudMessage( $msg, $ids );

function sendGoogleCloudMessage( $data, $ids )
{
    // Insert real GCM API key from Google APIs Console
    // https://code.google.com/apis/console/        

  define( 'API_ACCESS_KEY', 'my API TOKEN' );

    // Define URL to GCM endpoint

    $url = 'https://fcm.googleapis.com/fcm/send';

    $post = array(
                    'to'  => '/topics/mytopic',  
                    'notification' => $data,               
                    );


    // Set CURL request headers (authentication and type)       
    $headers = array( 
                        'Authorization: key=' . API_ACCESS_KEY,
                        'Content-Type: application/json'
                    );

    // Initialize curl handle       
    $ch = curl_init();

    // Set URL to GCM endpoint      
    curl_setopt( $ch, CURLOPT_URL, $url );

    // Set request method to POST       
    curl_setopt( $ch, CURLOPT_POST, true );

    // Set our custom headers       
    curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );

    // Get the response back as string instead of printing it       
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

    // Set JSON post data
    curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );

    // Actually send the push   
    $result = curl_exec( $ch );

    // Error handling
    if ( curl_errno( $ch ) )
    {
        echo 'GCM error: ' . curl_error( $ch );
    }

    // Close curl handle
    curl_close( $ch );

    // Debug GCM response       
    echo $result;
}

Результат: {"message_id":9138025304879801378}

Я не уверен, чтопроблема в том, что я пробовал разные сценарии, но даже если он показывает успешный результат, он не отображается на устройстве IOS.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...