Ver Mensaje Individual
  #18 (permalink)  
Antiguo 07/10/2010, 15:46
JPZamora
 
Fecha de Ingreso: mayo-2009
Ubicación: Mérida, Yucatán
Mensajes: 68
Antigüedad: 15 años
Puntos: 3
Respuesta: Variable dinámica

Asi me quedo...


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;
$resp=array();//array para almacenar los resultados
$push = new BoxAPI();//creamos una sola instancia
while ($i $num) {
    
$secret=mysql_result($result,$i,"secret");
    
$key=mysql_result($result,$i,"key");
    
$push->asignar('$secret','$key');//asignamos valores
    //ejecutamos la notificacion y asignamos el resultado en un array
    
$res[$i]=$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(){}//anulamos el constructor
 
function asignar($secret,$key){//nuevo metodo para asignar valores
    
$this->secret $secret;
    
$this->key $key;
}

        
        function 
invite($email){
            
$secret $this->secret;
            
$key $this->key;
            
$ch curl_init();
            
curl_setopt($chCURLOPT_URL"http://boxcar.io/devices/providers/$key/notifications/subscribe");
            
curl_setopt($chCURLOPT_POST1);
            
curl_setopt($chCURLOPT_POSTFIELDS,
                    
'email='.md5($email));
                        
$return curl_exec($ch);
            
$httpcode curl_getinfo($chCURLINFO_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($chCURLOPT_URL"http://boxcar.io/devices/providers/$key/notifications/broadcast");
            
curl_setopt($chCURLOPT_POST5);
            
curl_setopt($chCURLOPT_POSTFIELDS,
                    
'secret='.$secret.
                    
'&notification[from_screen_name]='.urlencode(stripslashes($sender)).
                    
'&notification[message]='.urlencode(stripslashes($message)).
                    
'&notification[from_remote_service_id]='.urlencode(stripslashes($unique)).
                    
'&notification[redirect_payload]='.urlencode(stripslashes($redirect_payload))
                );
                        
$return curl_exec($ch);
            
$httpcode curl_getinfo($chCURLINFO_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($chCURLOPT_URL"http://boxcar.io/devices/providers/$key/notifications");
            
curl_setopt($chCURLOPT_POST5);
            
curl_setopt($chCURLOPT_POSTFIELDS,
                    
'email='.md5($email).
                    
'&notification[from_screen_name]='.urlencode(stripslashes($sender)).
                    
'&notification[message]='.urlencode(stripslashes($message)).
                    
'&notification[from_remote_service_id]='.urlencode(stripslashes($unique)).
                    
'&notification[redirect_payload]='.urlencode(stripslashes($redirect_payload))
                );
                        
$return curl_exec($ch);
            
$httpcode curl_getinfo($chCURLINFO_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($chCURLOPT_URL"http://boxcar.io/devices/providers/$key/notifications/");
            
curl_setopt($chCURLOPT_POST6);
            
curl_setopt($chCURLOPT_POSTFIELDS,
                    
'token='.$token.
                    
'&secret='.$secret.
                    
'&notification[from_screen_name]='.urlencode(stripslashes($sender)).
                    
'&notification[message]='.urlencode(stripslashes($message)).
                    
'&notification[from_remote_service_id]='.urlencode(stripslashes($unique)).
                    
'&notification[redirect_payload]='.urlencode(stripslashes($redirect_payload))
                );
                        
$return curl_exec($ch);
            
$httpcode curl_getinfo($chCURLINFO_HTTP_CODE);
            
curl_close($ch);
            return array(
$httpcode,$return);
        }
        

    }

?>