S
sibob
There's been a few requests for sending SMS via Perl. Here is some
sample code that uses a Web service to send SMS in Perl with coverage
to 160 countries. All that is needed is a phone number to send with
country code and the text of the message.
#!/usr/bin/perl
# This is an example of using Perl to invoke
# A Web service from StrikeIron's Web Services Marketplace
# This particular example is the Global SMS Web Service
# http://ws.strikeiron.com/SMSTextMessaging?WSDL
# To get a UserID and Password for this Web service, please register at
www.strikeiron.com
# Alternatively, you can use a validated email address as an
unregistered user for a limited number of hits. YOU MUST
# ENTER YOUR EMAIL ADDRESS IN THE LINE OF CODE BELOW
# Download the free Web Services Analyzer to interactively invoke this
(or any) Web service and see its structure:
# http://www.strikeiron.com/tools/tools_analyzer_windows.aspx
# makes use of the SOAP::Lite module with mapping disabled for
compatibility
use SOAP::Lite maptype => {};
# select the Web service
my $service = SOAP::Lite
-> uri($callNs)
-> on_action( sub { join '/', 'http://www.strikeiron.com', $_[1] }
)
-> proxy('http://ws.strikeiron.com/smstextmessaging');
# select the operation of this Web service to invoke
my $method = SOAP:ata->name('SendMessage')->attr({xmlns =>
'http://www.strikeiron.com'});
# Provide authentication credentials here
# If you are unregistered with StrikeIron, use your email address
# If you are registered, use your UserID (your email address) and
Password
# The registered user code is currently commented out
# Unregistered Users:
# The first time you invoke the Web service you will need to validate
your email address
my $header = SOAP::Header->name(LicenseInfo =>
\SOAP::Header->name(UnregisteredUser => {
EmailAddress =>
'[email protected]'}))->uri('http://ws.strikeiron.com')->prefix('');
# Registered Users: Use your UserID and Password with this code instead
# You can also use your license key obtained from "My StrikeIron" with
the password blank
# Uncomment the code below for StrikeIron registered users and comment
out the Unregistered code above
#my $header = SOAP::Header->name(LicenseInfo =>
\SOAP::Header->name(RegisteredUser => {
# UserID => '(e-mail address removed)', Password =>
'YOURPASSWORD'}))->uri('http://ws.strikeiron.com')->prefix('');
# set input parameters to the Web service
my @params = ($header, SOAP:ata->name("ToNumber"=>"+19195551212"), #
country code followed by area code and number
SOAP:ata->name("FromName"=>"A Friend"),
SOAP:ata->name("MessageText"=>"Test SMS sent
via Perl"));
# invoke the Web service
my $result = $service->call($method => @params);
# display any error message
if ($result->fault)
{
print "Soap fault generated: " . $result->faultstring;
}
# display result from a successful invocation
else
{
print "Status: " .
$result->valueof('//SendMessageResponse/SendMessageResult/MessageStatus/StatusText')
.. "\n";
print "Hits Remaining: " .
$result->valueof('//SubscriptionInfo/RemainingHits');
}
# Have questions or want to see additional examples? www.strikeiron.com
sample code that uses a Web service to send SMS in Perl with coverage
to 160 countries. All that is needed is a phone number to send with
country code and the text of the message.
#!/usr/bin/perl
# This is an example of using Perl to invoke
# A Web service from StrikeIron's Web Services Marketplace
# This particular example is the Global SMS Web Service
# http://ws.strikeiron.com/SMSTextMessaging?WSDL
# To get a UserID and Password for this Web service, please register at
www.strikeiron.com
# Alternatively, you can use a validated email address as an
unregistered user for a limited number of hits. YOU MUST
# ENTER YOUR EMAIL ADDRESS IN THE LINE OF CODE BELOW
# Download the free Web Services Analyzer to interactively invoke this
(or any) Web service and see its structure:
# http://www.strikeiron.com/tools/tools_analyzer_windows.aspx
# makes use of the SOAP::Lite module with mapping disabled for
compatibility
use SOAP::Lite maptype => {};
# select the Web service
my $service = SOAP::Lite
-> uri($callNs)
-> on_action( sub { join '/', 'http://www.strikeiron.com', $_[1] }
)
-> proxy('http://ws.strikeiron.com/smstextmessaging');
# select the operation of this Web service to invoke
my $method = SOAP:ata->name('SendMessage')->attr({xmlns =>
'http://www.strikeiron.com'});
# Provide authentication credentials here
# If you are unregistered with StrikeIron, use your email address
# If you are registered, use your UserID (your email address) and
Password
# The registered user code is currently commented out
# Unregistered Users:
# The first time you invoke the Web service you will need to validate
your email address
my $header = SOAP::Header->name(LicenseInfo =>
\SOAP::Header->name(UnregisteredUser => {
EmailAddress =>
'[email protected]'}))->uri('http://ws.strikeiron.com')->prefix('');
# Registered Users: Use your UserID and Password with this code instead
# You can also use your license key obtained from "My StrikeIron" with
the password blank
# Uncomment the code below for StrikeIron registered users and comment
out the Unregistered code above
#my $header = SOAP::Header->name(LicenseInfo =>
\SOAP::Header->name(RegisteredUser => {
# UserID => '(e-mail address removed)', Password =>
'YOURPASSWORD'}))->uri('http://ws.strikeiron.com')->prefix('');
# set input parameters to the Web service
my @params = ($header, SOAP:ata->name("ToNumber"=>"+19195551212"), #
country code followed by area code and number
SOAP:ata->name("FromName"=>"A Friend"),
SOAP:ata->name("MessageText"=>"Test SMS sent
via Perl"));
# invoke the Web service
my $result = $service->call($method => @params);
# display any error message
if ($result->fault)
{
print "Soap fault generated: " . $result->faultstring;
}
# display result from a successful invocation
else
{
print "Status: " .
$result->valueof('//SendMessageResponse/SendMessageResult/MessageStatus/StatusText')
.. "\n";
print "Hits Remaining: " .
$result->valueof('//SubscriptionInfo/RemainingHits');
}
# Have questions or want to see additional examples? www.strikeiron.com