Difference between revisions of "SMS Send Script Example"
Dcunningham (talk | contribs) (Created page with "<code><pre> #!/usr/bin/perl -w use strict; use LWP::UserAgent; use POSIX qw( mktime strftime ); use URI::Escape; use utf8; our $account = 'replaceme'; our $password = 'replac...") |
(No difference)
|
Latest revision as of 00:10, 25 February 2015
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use POSIX qw( mktime strftime );
use URI::Escape;
use utf8;
our $account = 'replaceme';
our $password = 'replaceme';
our $country = '1';
our $longdistance = '0';
our $international = '00';
my $caller = num( env( 'callerid' ) );
my $dest = num( env( 'dnumber' ) );
my $body = env( 'body' );
utf8::decode($body);
#$body =~ s/\s/+/g;
#$body =~ s/[^\w\+\,\:\-\.]//g;
#$body =~ s/\,/%2C/g;
#$body =~ s/\-/%2D/g;
#$body =~ s/\:/%3A/g;
#$body =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
our $url = '';
$url = 'http://provider.com/?action=sendsms&user=' . $account . '&password=' . $password . '&from=' . $caller . '&to=' . $dest . '&clientcharset=UTF-8&text=' . $body;
print $url, "\n";
fork() and exit( 0 );
my $ua = LWP::UserAgent->new();
$ua->agent( 'Enswitch' );
$ua->timeout( 120 );
my $res = $ua->get( $url );
$res->is_success() or die( "$0 error: " . $res->status_line() . "\n" );
$res->content() =~ /^OK/o or die( "$0 returned: " . $res->content() . "\n" );
exit( 0 );
sub env {
my $name = 'ENSWITCH_' . uc( shift );
return $ENV{ $name };
}
sub num {
my $n = shift;
defined $n or return '';
$n =~ /^\+(.*)$/ and return $1;
$n =~ /^$international(.*)$/ and return $1;
$n =~ /^$longdistance(.*)$/ and return ( $country . $1 );
return $n;
}