line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Send::TW::emome; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
50918
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
5
|
1
|
|
|
1
|
|
1262
|
use WWW::Mechanize; |
|
1
|
|
|
|
|
220205
|
|
|
1
|
|
|
|
|
47
|
|
6
|
1
|
|
|
1
|
|
1039
|
use Text::Iconv; |
|
1
|
|
|
|
|
3550
|
|
|
1
|
|
|
|
|
70
|
|
7
|
1
|
|
|
1
|
|
11
|
use base 'SMS::Send::Driver'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
860
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
324
|
use vars qw{$VERSION}; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
430
|
$VERSION = '0.04'; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Preloaded methods go here. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
1
|
|
my ($class, %params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
foreach(qw/username password language/) { |
21
|
0
|
0
|
|
|
|
|
Carp::croak("No $_ specified") unless(defined $params{"_$_"}); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $self = bless { %params }, $class; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub send_sms { |
30
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
31
|
0
|
|
|
|
|
|
my %params = @_; |
32
|
0
|
|
|
|
|
|
my $baseurl = 'http://websms1.emome.net/sms/sendsms/new.jsp?msg='; |
33
|
0
|
|
|
|
|
|
my $posturl = 'http://websms1.emome.net/sms/sendsms/send.jsp'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Get the message and destination |
36
|
0
|
|
|
|
|
|
my $message = $self->_MESSAGE( $params{text} ); |
37
|
0
|
|
|
|
|
|
my $recipient = $self->_TO( delete $params{to} ); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $ua = WWW::Mechanize->new( |
40
|
|
|
|
|
|
|
agent => __PACKAGE__." v. $VERSION", |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$ua->agent_alias('Windows IE 6'); |
44
|
0
|
|
|
|
|
|
$ua->get($baseurl); |
45
|
0
|
|
|
|
|
|
$ua->submit(); |
46
|
0
|
|
|
|
|
|
$ua->submit(); |
47
|
0
|
|
|
|
|
|
$ua->submit_form( |
48
|
|
|
|
|
|
|
form_name => 'form1', |
49
|
|
|
|
|
|
|
fields => { |
50
|
|
|
|
|
|
|
uid => $self->{"_username"}, |
51
|
|
|
|
|
|
|
pw => $self->{"_password"}, |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$ua->content() =~ /window.location.href='(.+)'/i; |
56
|
0
|
|
|
|
|
|
$ua->get($1); |
57
|
0
|
|
|
|
|
|
$ua->post($posturl, |
58
|
|
|
|
|
|
|
[ |
59
|
|
|
|
|
|
|
'nextURL' => '0', |
60
|
|
|
|
|
|
|
'resend' => '1', # 0:不重送 1:重送 |
61
|
|
|
|
|
|
|
'language' => $self->{"_language"}, # 1:中文 2:英文 |
62
|
|
|
|
|
|
|
'phonelist' => $recipient, |
63
|
|
|
|
|
|
|
'data' => $message, |
64
|
|
|
|
|
|
|
'rad' => '0', # 0:立即傳送 1:預約傳送 |
65
|
|
|
|
|
|
|
]); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $ua->content; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _MESSAGE { |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
0
|
|
|
my $class = ref $_[0] ? ref shift : shift; |
73
|
0
|
|
|
|
|
|
my $message = shift; |
74
|
0
|
|
|
|
|
|
my $converter = Text::Iconv->new("big5", "utf-8"); |
75
|
0
|
0
|
|
|
|
|
unless ( length($message) <= 160 ) { |
76
|
0
|
|
|
|
|
|
Carp::croak("Message length limit is 160 characters"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return $converter->convert($message); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _TO { |
84
|
0
|
0
|
|
0
|
|
|
my $class = ref $_[0] ? ref shift : shift; |
85
|
0
|
|
|
|
|
|
my $to = shift; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# International numbers need their + removed |
88
|
0
|
|
|
|
|
|
$to =~ y/0123456789//cd; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $to; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |