Created
September 1, 2015 10:59
-
-
Save deivisonmoraes/973255eb55946f9d7f4d to your computer and use it in GitHub Desktop.
Script para envio de SMS GoIP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Envia sms passando parametros por linha de comando | |
* | |
* Deivison Moraes | |
*/ | |
$pid = pcntl_fork(); | |
posix_setsid(); | |
if ($pid == -1) { | |
die('could not fork'); | |
} else if ($pid) { | |
// we are the parent | |
pcntl_wait($status); //Protect against Zombie children | |
} else { | |
$SMS_HOST = "ip_servidor_sms_server"; | |
$SMS_USER = "user_smsserver"; | |
$SMS_PASS = "senhasms_server"; | |
if ($argc != 3) { | |
fprintf(STDERR, "Usage: %s \"TELEFONE[,TELEFONE]*\" \"MENSAGEM\"\n", $argv[0]); | |
exit(1); | |
} | |
$tel = $argv[1]; | |
$msg = $argv[2]; | |
$db = mysql_connect($SMS_HOST, 'user_mysql', 'password_mysql') or die('Erro ao conectar no mysql'); | |
/* cria mensagem */ | |
$sql = sprintf("INSERT INTO goip.message (userid, msg, type, tel, prov) VALUES (1, \"%s\", 4, \"%s\", 1)", addslashes($msg), addslashes($tel)); | |
mysql_query($sql, $db); | |
$id = mysql_insert_id($db); | |
if (!$id || $id == 0) { | |
mysql_close($db); | |
fprintf(STDERR, "Nao foi possivel gerar mensagem\nSQL: %s\n", $sql); | |
exit(1); | |
} | |
/* insere mensagem no queue de envio | |
OBS: para cada telefone, um registro */ | |
$numeros = explode(",", $tel); | |
for ($i = 0; $i < count($numeros); $i++) { | |
$sql = sprintf("INSERT INTO goip.sends (time, userid, messageid, goipid, provider, telnum) VALUES(NOW(), 1, %d, 1, \"2\", \"%s\")", $id, $numeros[$i]); | |
mysql_query($sql, $db); | |
} | |
mysql_close($db); | |
/* executa script de envio via wget */ | |
$cmd = sprintf("wget -q -O /dev/null \"http://%s/goip/en/resend.php?messageid=%d&USERNAME=%s&PASSWORD=%s\"", $SMS_HOST, $id, $SMS_USER, $SMS_PASS); | |
$ret = 0; | |
system($cmd, $ret); | |
if ($ret != 0) { | |
fprintf(STDERR, "Nao foi possivel enviar o sms via comando\nCMD: %s\n", $cmd); | |
exit(1); | |
} | |
exit(0); | |
}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hola, en envios masivos hay que setear algo con el text?