Evitando problemas, mostrare todo, solo omitire la parte de las calves..
Archivo Base
Código PHP:
<?php
$mysql_username="************";
$mysql_password="*************";
$mysql_database="**************";
$mysql_host="localhost";
$mysql_table="boxcar";
mysql_connect($mysql_host,$mysql_username,$mysql_password);
@mysql_select_db($mysql_database) or die( "Unable to select database");
$query="SELECT * FROM $mysql_table";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
include_once("boxApi.php");
$i=0;
while ($i < $num) {
$secret=mysql_result($result,$i,"secret");
$key=mysql_result($result,$i,"key");
$push = new BoxAPI('$secret','$key');
$push->notify('email@address','boxAPI','Hello Kshitij!','rand');
$i++;
}
?>
boxApi.php
Código PHP:
<?php
/*
Initial class by Kshitij Parajuli (kshitij at jagaparajuli dot com dot np)
+ initialize
- new BoxAPI(secret,private_key)
+ function invite(email)
- email = email address of the user you want to send the invitation to subscribe to
+ function broadcast(sender, message, unique, redirect_payload)
- sender = from_screen_name
- message = message
+ unique = from_remote_service_id
- If you pass "random" in unique, the class will send the current UNIX timestamp as this value
- redirect_payload = redirect_payload
+ function notify(email, sender, message, unique, redirect_payload)
- email = email address of the user you want to notify (send a push notification)
- sender = from_screen_name
- message = message
+ unique = from_remote_service_id
- If you pass "random" in unique, the class will send the current UNIX timestamp as this value
- redirect_payload = redirect_payload
+ function notify_service(token, secret, sender, message,unique,redirect_payload)
- token = token of the service you want to notify
- secret = secret of the service you want to notify
- sender = from_screen_name
- message = message
+ unique = from_remote_service_id
- If you pass "random" in unique, the class will send the current UNIX timestamp as this value
- redirect_payload = redirect_payload
More information: http://boxcar.io/help/api/providers
Examples:
<?php
include("boxApi.php");
$test = new BoxAPI("--secret--","--key--");
$test->notify("email@address","boxAPI","Hello Kshitij!","rand");
?>
<?php
include("boxApi.php");
$test = new BoxAPI("--secret--","--key--");
$test->broadcast("Sender_Name","Sed ut perspiciatis unde omnis iste natus error sit voluptatem","","http://www.google.com?#q=::user::");
?>
*/
class BoxAPI {
private $secret;
private $key;
function __construct($secret,$key){
$this->secret = $secret;
$this->key = $key;
}
function invite($email){
$secret = $this->secret;
$key = $this->key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://boxcar.io/devices/providers/$key/notifications/subscribe");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
'email='.md5($email));
$return = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array($httpcode,$return);
}
public function broadcast($sender="", $message="",$unique="",$redirect_payload="") {
$key = $this->key;
$secret = $this->secret;
if ($unique="rand"){
$unique=time();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://boxcar.io/devices/providers/$key/notifications/broadcast");
curl_setopt($ch, CURLOPT_POST, 5);
curl_setopt($ch, CURLOPT_POSTFIELDS,
'secret='.$secret.
'¬ification[from_screen_name]='.urlencode(stripslashes($sender)).
'¬ification[message]='.urlencode(stripslashes($message)).
'¬ification[from_remote_service_id]='.urlencode(stripslashes($unique)).
'¬ification[redirect_payload]='.urlencode(stripslashes($redirect_payload))
);
$return = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array($httpcode,$return);
}
public function notify($email, $sender="", $message,$unique="",$redirect_payload="") {
$key = $this->key;
if ($unique="rand"){
$unique=time();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://boxcar.io/devices/providers/$key/notifications");
curl_setopt($ch, CURLOPT_POST, 5);
curl_setopt($ch, CURLOPT_POSTFIELDS,
'email='.md5($email).
'¬ification[from_screen_name]='.urlencode(stripslashes($sender)).
'¬ification[message]='.urlencode(stripslashes($message)).
'¬ification[from_remote_service_id]='.urlencode(stripslashes($unique)).
'¬ification[redirect_payload]='.urlencode(stripslashes($redirect_payload))
);
$return = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array($httpcode,$return);
}
public function notify_service($token, $secret, $sender="", $message,$unique="",$redirect_payload="") {
$key = $this->key;
if ($unique="rand"){
$unique=time();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://boxcar.io/devices/providers/$key/notifications/");
curl_setopt($ch, CURLOPT_POST, 6);
curl_setopt($ch, CURLOPT_POSTFIELDS,
'token='.$token.
'&secret='.$secret.
'¬ification[from_screen_name]='.urlencode(stripslashes($sender)).
'¬ification[message]='.urlencode(stripslashes($message)).
'¬ification[from_remote_service_id]='.urlencode(stripslashes($unique)).
'¬ification[redirect_payload]='.urlencode(stripslashes($redirect_payload))
);
$return = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array($httpcode,$return);
}
}
?>