SMS::Send::TW::emome - SMS::Send driver for www.emome.net


SMS-Send-TW-emome documentation Contained in the SMS-Send-TW-emome distribution.

Index


Code Index:

NAME

Top

SMS::Send::TW::emome - SMS::Send driver for www.emome.net

SYNOPSIS

Top

  use SMS::send;

  my $sender = SMS::Send->new('TW::emome',
                  _username   => 'UserName',
                  _password   => 'Password',
                  _language   => '1',		# 1:Chinese  2:English
                );

  my $sent = $sender->send_sms(
                  text => 'My very urgent message',
                  to   => '0912345678',
             );

DESCRIPTION

Top

SMS::Send::TW::emome is a SMS::Send driver which allows you to send messages through http://www.emome.net/.

METHODS

Top

new

The new method takes a few parameters. _username , _password , and _language > are mandatory.

send_sms

Takes to as recipient phonenumber, and text as the text that's supposed to be delivered.

SEE ALSO

Top

* Send::SMS
* WWW::Mechanize

AUTHOR

Top

Tsung-Han Yeh, <snowfly@yuntech.edu.tw>

COPYRIGHT AND LICENSE

Top


SMS-Send-TW-emome documentation Contained in the SMS-Send-TW-emome distribution.

package SMS::Send::TW::emome;

use strict;
use Carp;
use WWW::Mechanize;
use Text::Iconv;
use base 'SMS::Send::Driver';


use vars qw{$VERSION};
BEGIN {
   $VERSION = '0.04';
}

# Preloaded methods go here.

sub new {
   my ($class, %params) = @_;

   foreach(qw/username password language/) {
      Carp::croak("No $_ specified") unless(defined $params{"_$_"});
   }

   my $self = bless { %params }, $class;

   return $self;
}

sub send_sms {
   my $self   = shift;
   my %params = @_;
   my $baseurl = 'http://websms1.emome.net/sms/sendsms/new.jsp?msg=';
   my $posturl = 'http://websms1.emome.net/sms/sendsms/send.jsp';

   # Get the message and destination
   my $message   = $self->_MESSAGE( $params{text} );
   my $recipient = $self->_TO( delete $params{to} );

   my $ua = WWW::Mechanize->new(
      agent => __PACKAGE__." v. $VERSION",
   );

   $ua->agent_alias('Windows IE 6');
   $ua->get($baseurl);
   $ua->submit();
   $ua->submit();
   $ua->submit_form(
        form_name => 'form1',
        fields    => {
                        uid  => $self->{"_username"},
                        pw   => $self->{"_password"},
                     },
   );

   $ua->content() =~ /window.location.href='(.+)'/i;
   $ua->get($1);
   $ua->post($posturl,
		[
		  'nextURL' 	  => '0',
		  'resend'	  => '1',			# 0:¤£­«°e¡@1:­«°e
		  'language'	  => $self->{"_language"},	# 1:¤¤¤å¡@  2:­^¤å
		  'phonelist'	  => $recipient,
		  'data'	  => $message,
		  'rad'		  => '0', 			# 0:¥ß§Y¶Ç°e  1:¹w¬ù¶Ç°e
		]);

   return $ua->content;
}

sub _MESSAGE {

  my $class = ref $_[0] ? ref shift : shift;
  my $message = shift;
  my $converter = Text::Iconv->new("big5", "utf-8");
  unless ( length($message) <= 160 ) {
    Carp::croak("Message length limit is 160 characters");
  }
  
  
  return $converter->convert($message);
}

sub _TO {
  my $class = ref $_[0] ? ref shift : shift;
  my $to = shift;

  # International numbers need their + removed
  $to =~ y/0123456789//cd;

  return $to;
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!