Tema: envio de sms
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/11/2004, 11:50
Motki
 
Fecha de Ingreso: septiembre-2003
Mensajes: 341
Antigüedad: 20 años, 7 meses
Puntos: 0
envio de sms

hola a to2.
Este cgi me lo ha proporcionado un proveedor de sms para poder enviar a través de mi pagina web mensajes sms.
El problema que tengo es que este ejemplo es válido para enviar a un sólo num de telefono,
en cambio me gustaría modificarlo y que la variable dst que contiene el num de telf, pase a ser un array,
es decir pasarle yo los numeros de telf separados por comas: ej:221234568,644444444
y luego que el cgi me los convierta en array y realize un bucle para enviar a los diferentes num.
Mi problema es que no tengo NI IDEA DE CGI y PERL y por cada prueba que realizo me descuentan créditos .
Si alguien me pudiese echar una mano se lo agradecedia.


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

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

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

$texto=$in{'msg'};
$texto=~s/\n//g;
$texto=~s/\r//g;
$DEST_NUM[0]="+34".$in{'dst'};

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

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

#====================================#
# Socket
#====================================#
if ($SOCK=IO::Socket::INET->new(PeerAddr=>$HOST, Proto=>'protocoloautilizar'))
{
	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