Tema: envio de sms
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/11/2004, 11:09
Motki
 
Fecha de Ingreso: septiembre-2003
Mensajes: 341
Antigüedad: 20 años, 7 meses
Puntos: 0
hola de nuevo,
bueno he intentado crear el array y el bucle,
agradeceria que alguien me dijese si es o no correcto, nunca he programado con PERL,no puedo hacer muchas pruebas con el código pq los creditos que tengo de prueba estan limitados..

bueno lo dejo:





#!/usr/bin/perl
#================================================= ============
$DEBUG=0;
use IO::Socket;



#====================================#
# Read numbers and text
#====================================#
&ReadParse;

$HOST="hostdeenvio";
$SMS_USER="$in{'login'}";
$SMS_PASS="$in{'password'}";

$texto=$in{'msg'};
$texto=~s/\n//g;
$texto=~s/\r//g;


print "Content-type: text/html\n";
print "Cache-Control: no-cache, must-revalidate\n";
print "Pragma: no-cache\n";
print "Expires: 0\n\n";

#esto es mio
@numeros = split(/;/, $in{'dst'});
foreach $elemento (@numeros) {

$DEST_NUM[0]="+34".$elemento;

if (length ($texto) > 160) {
$texto=substr ($texto,0,160);
}

#====================================#
# Socket
#====================================#
if ($SOCK=IO::Socket::INET->new(PeerAddr=>$HOST, Proto=>'protocolo'))
{
select (STDOUT); $| = 1;
select ($SOCK); $| = 1;
select (STDOUT);

#===================================#
# Parsea respuesta
#===================================#
&login;
&dst;
&texto;
&envia;

while( $linia = <$SOCK> ) {

print "->>> $linia" if $DEBUG;
($instr, $code, $reply) = split(" ",$linia,3);

if( $code =~ m/OK/ && $instr==1 ) {
$CREDITO_INI=$reply;
print STDOUT "\nCréditos disponibles: $reply\n" if $DEBUG;
}

if( $code =~ m/REJDST/ ) {
print STDOUT "Rechazado $reply" if $DEBUG;
}

if ( $code =~ m/OK/ && $instr==$FLAG ) {
($CREDITO_FIN,$CREDITO_INT)=split(" ",$reply,2);
print STDOUT "Enviado OK, saldo disponible: $CREDITO_FIN\n" if $DEBUG;
$errtxt="OK $CREDITO_FIN\n";
&quit;
}

}

chomp($CREDITO_FIN);
$CREDITO_FIN=$CREDITO_FIN+0;
if ( $CREDITO_FIN < 1 ) {
print "ERROR Parametros\n\n";
exit 0;
} else {
print "$errtxt\n";
exit 0;
}

} else {
print "ERROR Socket\n";
exit 0;
}


$CREDITO_INI=~ s/\n\r//g;
$CREDITO_FIN=~ s/\n\r//g;
$SMS_SENT=$CREDITO_INI - $CREDITO_FIN;

exit 0;
}


#==================================#
# Login
#==================================#
sub login {
$INSTR=1;
print $SOCK "$INSTR login $SMS_USER $SMS_PASS\n";
print STDOUT "$INSTR login $SMS_USER $SMS_PASS\n" if $DEBUG;
$LOGIN=1;
}

#==================================#
# Bucle de envio
#==================================#
sub dst {
for ($i=0;$i<@DEST_NUM;$i++) {
$INSTR++;
print $SOCK "$INSTR dst $DEST_NUM[$i]\n";
print STDOUT "$INSTR dst $DEST_NUM[$i]\n" if $DEBUG;
}
}

#==================================#
# Finalizar conexión
#==================================#
sub quit {
$INSTR++;
print $SOCK "$INSTR quit\n";
print STDOUT "$INSTR quit\n" if $DEBUG;
}

#==================================#
# Lee texto
#==================================#
sub texto {

$INSTR++;
print $SOCK "$INSTR msg $texto\n";
print STDOUT "$INSTR msg $texto\n" if $DEBUG;
}

#==================================#
# Envia
#==================================#
sub envia {
$INSTR++;
print $SOCK "$INSTR envia\n";
print STDOUT "$INSTR envia\n" if $DEBUG;
$FLAG=$INSTR;
$END=1;
}

#==================================#
# Lee la entrada del formulario
#==================================#
sub ReadParse {

local (*in) = @_ if @_;
local ($i, $key, $val);

if ( $ENV{'REQUEST_METHOD'} eq "GET" ) {
$in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
} else {
# Added for command line debugging
# Supply name/value form data as a command line argument
# Format: name1=value1\&name2=value2\&...
# (need to escape & for shell)
# Find the first argument that's not a switch (-)
$in = ( grep( !/^-/, @ARGV )) [0];
$in =~ s/\\&/&/g;
}

@in = split(/&/,$in);

foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;

# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.

# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;

# Associate key and value. \0 is the multiple separator
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $val;
}
return length($in);
}
__________________
---Nuestra recompensa se encuentra en el esfuerzo y no en el resultado. Un esfuerzo total es una victoria completa.-- GHANDI

Última edición por Motki; 24/11/2004 a las 11:12