1package SMS::Send::TW::emome; 2 3use strict; 4use Carp; 5use WWW::Mechanize; 6use Text::Iconv; 7use base 'SMS::Send::Driver'; 8 9 10use vars qw{$VERSION}; 11BEGIN { 12 $VERSION = '0.04'; 13} 14 15# Preloaded methods go here. 16 17sub new { 18 my ($class, %params) = @_; 19 20 foreach(qw/username password language/) { 21 Carp::croak("No $_ specified") unless(defined $params{"_$_"}); 22 } 23 24 my $self = bless { %params }, $class; 25 26 return $self; 27} 28 29sub send_sms { 30 my $self = shift; 31 my %params = @_; 32 my $baseurl = 'http://websms1.emome.net/sms/sendsms/new.jsp?msg='; 33 my $posturl = 'http://websms1.emome.net/sms/sendsms/send.jsp'; 34 35 # Get the message and destination 36 my $message = $self->_MESSAGE( $params{text} ); 37 my $recipient = $self->_TO( delete $params{to} ); 38 39 my $ua = WWW::Mechanize->new( 40 agent => __PACKAGE__." v. $VERSION", 41 ); 42 43 $ua->agent_alias('Windows IE 6'); 44 $ua->get($baseurl); 45 $ua->submit(); 46 $ua->submit(); 47 $ua->submit_form( 48 form_name => 'form1', 49 fields => { 50 uid => $self->{"_username"}, 51 pw => $self->{"_password"}, 52 }, 53 ); 54 55 $ua->content() =~ /window.location.href='(.+)'/i; 56 $ua->get($1); 57 $ua->post($posturl, 58 [ 59 'nextURL' => '0', 60 'resend' => '1', # 0:�����e�@1:���e 61 'language' => $self->{"_language"}, # 1:����@ 2:�^�� 62 'phonelist' => $recipient, 63 'data' => $message, 64 'rad' => '0', # 0:�ߧY�ǰe 1:�w���ǰe 65 ]); 66 67 return $ua->content; 68} 69 70sub _MESSAGE { 71 72 my $class = ref $_[0] ? ref shift : shift; 73 my $message = shift; 74 my $converter = Text::Iconv->new("big5", "utf-8"); 75 unless ( length($message) <= 160 ) { 76 Carp::croak("Message length limit is 160 characters"); 77 } 78 79 80 return $converter->convert($message); 81} 82 83sub _TO { 84 my $class = ref $_[0] ? ref shift : shift; 85 my $to = shift; 86 87 # International numbers need their + removed 88 $to =~ y/0123456789//cd; 89 90 return $to; 91} 921; 93__END__ 94# Below is stub documentation for your module. You'd better edit it! 95 96=head1 NAME 97 98SMS::Send::TW::emome - SMS::Send driver for www.emome.net 99 100=head1 SYNOPSIS 101 102 use SMS::send; 103 104 my $sender = SMS::Send->new('TW::emome', 105 _username => 'UserName', 106 _password => 'Password', 107 _language => '1', # 1:Chinese 2:English 108 ); 109 110 my $sent = $sender->send_sms( 111 text => 'My very urgent message', 112 to => '0912345678', 113 ); 114 115=head1 DESCRIPTION 116 117SMS::Send::TW::emome is a SMS::Send driver which allows you to send messages through L<http://www.emome.net/>. 118 119=head1 METHODS 120 121=head2 new 122 123The C<new> method takes a few parameters. C<_username> , C<_password> , and C<_language> > 124are mandatory. 125 126=head2 send_sms 127 128Takes C<to> as recipient phonenumber, and C<text> as the text that's 129supposed to be delivered. 130 131=head1 SEE ALSO 132 133=over 5 134 135=item * L<Send::SMS> 136 137=item * L<WWW::Mechanize> 138 139=head1 AUTHOR 140 141Tsung-Han Yeh, E<lt>snowfly@yuntech.edu.twE<gt> 142 143=head1 COPYRIGHT AND LICENSE 144 145Copyright (C) 2007 by Tsung-Han Yeh 146 147This library is free software; you can redistribute it and/or modify 148it under the same terms as Perl itself, either Perl version 5.8.8 or, 149at your option, any later version of Perl 5 you may have available. 150 151 152=cut 153