SMS in Perl using a Web service

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::Data->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::Data->name("ToNumber"=>"+19195551212"), #
country code followed by area code and number
SOAP::Data->name("FromName"=>"A Friend"),
SOAP::Data->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
 
S

sibob

anonymous said:
How much we have to pay for their service. Tks

You can get 10 free SMS messages sent with an email address (the first
time you run the perl code it will send an email address to your
account to click validate), and then 10 cents on down to 4.5 cents
depending on volume sent. The nice thing is that it figures out based
on the phone number where to send it, and it's the same price in Japan,
Russia, India, Europe, South America, etc.. that it is to send one to a
cell phone in the U.S.

http://ws.strikeiron.com/globalsmspro2_5?WSDL
 
D

Dr.Ruud

sibob:


[news:[email protected]]

I tried your code, after inserting
use strict; use warnings;
my $callNs;
and it worked for me.

I had first sent 2 test-SMS-s through the web-interface
<http://www.strikeiron.com/sample/smstextmessaging/
GlobalSMSPro_2_5/sendonemessage.aspx>
so I expected my quotum to go from 8 to 7 when trying your code, but it
went from 10 to 9.

The message arrived with no delay. Tracking options are also available
(Queued -> Sent -> Delivered).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top