-
-
Save mlshvdv/7097672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param apiKey - ключ для GCM, получить можно в https://code.google.com/apis/console/ | |
* @param registrationIdsArray - массив токенов устройств | |
* @param messageData - массив данных уведомления, например: array('message' => "Hey!") | |
*/ | |
function sendGCMNotification( $apiKey, $registrationIdsArray, $messageData ) | |
{ | |
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey); | |
$data = array( | |
'data' => $messageData, | |
'registration_ids' => $registrationIdsArray | |
); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
curl_setopt($ch, CURLOPT_VERBOSE, false); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers ); | |
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send" ); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0 ); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0 ); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data) ); | |
$response = curl_exec($ch); | |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
$header_size = curl_getinfo($ch,CURLINFO_HEADER_SIZE); | |
curl_close($ch); | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment