Created
January 13, 2016 15:26
-
-
Save layerlre/15873c399db4456e989f to your computer and use it in GitHub Desktop.
Parse Push Notification Api example
This file contains hidden or 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
public function sendNotification($MESSAGE) | |
{ | |
$APPLICATION_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | |
$REST_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | |
$url = 'https://api.parse.com/1/push'; | |
$data = array( | |
'expiry' => 1451606400, | |
'data' => array( | |
'alert' => $MESSAGE, | |
), | |
'is_background' => false, | |
'where' => array( | |
'deviceType' => 'android', | |
) | |
); | |
$_data = json_encode($data); | |
$headers = array( | |
'X-Parse-Application-Id: ' . $APPLICATION_ID, | |
'X-Parse-REST-API-Key: ' . $REST_API_KEY, | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($_data), | |
); | |
$curl = curl_init($url); | |
curl_setopt($curl, CURLOPT_POST, 1); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $_data); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
$response = curl_exec($curl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment