Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/02/2012, 11:07
marcoobedjim
 
Fecha de Ingreso: febrero-2012
Ubicación: Jalisco Mexico
Mensajes: 5
Antigüedad: 14 años, 9 meses
Puntos: 0
Pregunta scrip para enviar sms

Hola esta es la primera ves que escribo un post en la pagina estoy algo perdido puesto que estoy tratando de incluir un form para enviar sms via web usando http://gateway160.com


tengo 2 opciones viables para mi usando script en php o java sim embargo estoy un poco perdido por que no he logrado conectar el script al formulario

en el link se encuentran los parametros del script les agradeceria mucho su ayuda si alguien puede brindarmela. gracias de antemano

[URL="http://gateway160.com/doc/sendmessage"]http://gateway160.com/doc/sendmessage[/URL]


el script que no logro hacer funcionar con el formulario es el siguiente :

Código PHP:
<!--?php
 
function post_request($url, $data, $optional_headers = null)
{
    
// data needs to be in the form of foo=bar&bar=foo
    
$data = http_build_query($data);
    
$params = array(
            
'http' =--> array(
                
'method' => 'POST',
                
'content' => $data,
                
// you need to specify the content length header
                
'header' => "Content-type: application/x-www-form-urlencoded\r\n"
                    
. 'Content-Length: ' . strlen($data) . "\r\n"
                
));
    if (
$optional_headers !== null) {
        
// append optional_headers if it is not null
        
$params['http']['header'] .= $optional_headers;
    }
    
$ctx = stream_context_create($params);
    
$fp = fopen($url, 'r', false, $ctx);
    if (!
$fp) {
        throw new 
Exception("Problem with $url, $php_errormsg");
    }
    
$response = stream_get_contents($fp);
    if (
$response === false) {
        throw new 
Exception("Problem reading data from $url, $php_errormsg");
    }
    
fclose($fp);
    return 
$response;
}
 
$post_data = array(
        
'accountName' => 'MyAccount',
        
'key' => 'xxxxffxx-xxxx-xxxx-xxxx-xxxxd2d3xxxx',
        
'phoneNumber' => '9998887777',
        
'message' => 'Hello World', //please perform URLEncode on this field
        
'countryCode' => 'US'
        
);
 
 
try
{
    
$result = post_request('http://api.gateway160.com/client/sendmessage/', $post_data);
    if(
$result == "1")
    {
        echo 
"Sent Successfully";
    }
    else
    {
        
//error  (check the response code from the chart above)
        
echo "Error";
    }
}
catch (
Exception $e)
{
    echo 
"Exception: " . $e->getMessage();
}
 
?>