Skip to content

Instantly share code, notes, and snippets.

@ricardoalcocer
Last active January 9, 2016 11:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ricardoalcocer/51b63b6ddba293c83c3e to your computer and use it in GitHub Desktop.
Save ricardoalcocer/51b63b6ddba293c83c3e to your computer and use it in GitHub Desktop.
Send ACS Push Notification from PHP
<?php
/*
Original code by @patrickjongmans
Edited and tested by @ricardoalcocer
Description:
Originally posted at http://developer.appcelerator.com/question/140589/how-to-send-push-notifiaction-to-android-using-php-controled-acs-#254798
@ricardoalcocer:
My only change was to add the ti_ids to the POST_FIELDS
*/
/*** SETUP ***************************************************/
$key = "<your_acs_app_key>";
$username = "<your_acs_admin_user>";
$password = "<your_acs_admin_password>";
$to_ids = "everyone";
$channel = "Allusers";
$message = "YOUR_MESSAGE";
$title = "YOUR_ANDROID_TITLE";
$tmp_fname = 'cookie.txt';
$json = '{"alert":"'. $message .'","title":"'. $title .'","vibrate":true,"sound":"default"}';
/*** PUSH NOTIFICATION ***********************************/
$post_array = array('login' => $username, 'password' => $password);
/*** INIT CURL *******************************************/
$curlObj = curl_init();
$c_opt = array(CURLOPT_URL => 'https://api.cloud.appcelerator.com/v1/users/login.json?key='.$key,
CURLOPT_COOKIEJAR => $tmp_fname,
CURLOPT_COOKIEFILE => $tmp_fname,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => "login=".$username."&password=".$password,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_TIMEOUT => 60);
// show debug message
//var_dump($c_opt);
/*** LOGIN **********************************************/
curl_setopt_array($curlObj, $c_opt);
$session = curl_exec($curlObj);
// show debug message
//var_dump($session);
/*** SEND PUSH ******************************************/
$c_opt[CURLOPT_URL] = "https://api.cloud.appcelerator.com/v1/push_notification/notify.json?key=".$key;
$c_opt[CURLOPT_POSTFIELDS] = "channel=".$channel."&payload=".$json."&to_ids=".$to_ids;
curl_setopt_array($curlObj, $c_opt);
$session = curl_exec($curlObj);
// show debug message
//var_dump($session);
/*** THE END ********************************************/
curl_close($curlObj);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment