| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: SMS::Send driver for Bulkgate - Czech Republic |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use warnings; |
|
7
|
2
|
|
|
2
|
|
78823
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
51
|
|
|
8
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
29
|
|
|
9
|
2
|
|
|
2
|
|
6
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
108
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "2.004"; |
|
11
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use LWP::UserAgent; |
|
14
|
2
|
|
|
2
|
|
1023
|
use LWP::Protocol::https; |
|
|
2
|
|
|
|
|
69626
|
|
|
|
2
|
|
|
|
|
58
|
|
|
15
|
2
|
|
|
2
|
|
687
|
use DateTime qw(); |
|
|
2
|
|
|
|
|
136687
|
|
|
|
2
|
|
|
|
|
67
|
|
|
16
|
2
|
|
|
2
|
|
1324
|
use base 'SMS::Send::Driver'; |
|
|
2
|
|
|
|
|
780645
|
|
|
|
2
|
|
|
|
|
81
|
|
|
17
|
2
|
|
|
2
|
|
16
|
use Log::LogLite; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
643
|
|
|
18
|
2
|
|
|
2
|
|
1055
|
use Text::Unidecode; |
|
|
2
|
|
|
|
|
9889
|
|
|
|
2
|
|
|
|
|
63
|
|
|
19
|
2
|
|
|
2
|
|
863
|
use JSON; |
|
|
2
|
|
|
|
|
2151
|
|
|
|
2
|
|
|
|
|
244
|
|
|
20
|
2
|
|
|
2
|
|
1158
|
|
|
|
2
|
|
|
|
|
14537
|
|
|
|
2
|
|
|
|
|
12
|
|
|
21
|
|
|
|
|
|
|
my $class = shift; |
|
22
|
|
|
|
|
|
|
my %params = @_; |
|
23
|
1
|
|
|
1
|
1
|
51
|
|
|
24
|
1
|
|
|
|
|
3
|
my $LOG_FILE = "/var/log/bulkgate.log"; |
|
25
|
|
|
|
|
|
|
my $ERROR_LOG_LEVEL = 6; |
|
26
|
1
|
|
|
|
|
1
|
|
|
27
|
1
|
|
|
|
|
2
|
open HANDLE, ">>$LOG_FILE"; |
|
28
|
|
|
|
|
|
|
close HANDLE; |
|
29
|
1
|
|
|
|
|
224
|
|
|
30
|
1
|
|
|
|
|
11
|
# Create our LWP::UserAgent object |
|
31
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
9
|
# Create the object, saving any private params for later |
|
34
|
|
|
|
|
|
|
my $self = bless { |
|
35
|
|
|
|
|
|
|
ua => $ua, |
|
36
|
|
|
|
|
|
|
login => $params{_login}, |
|
37
|
|
|
|
|
|
|
password => $params{_password}, |
|
38
|
|
|
|
|
|
|
private => \%params, |
|
39
|
|
|
|
|
|
|
log => (-w $LOG_FILE) ? new Log::LogLite($LOG_FILE, $ERROR_LOG_LEVEL) : 0 |
|
40
|
1
|
50
|
|
|
|
1871
|
}, $class; |
|
41
|
|
|
|
|
|
|
$self->log("Driver Bulkgate created", 4); |
|
42
|
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
185
|
$self; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
1
|
|
|
|
|
270
|
|
|
46
|
|
|
|
|
|
|
my ($self, $msg, $level) = @_; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if ($self->{'log'}) { |
|
49
|
4
|
|
|
4
|
1
|
8
|
$self->{'log'}->write($msg, $level); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
4
|
50
|
|
|
|
16
|
} |
|
52
|
4
|
|
|
|
|
12
|
|
|
53
|
|
|
|
|
|
|
my ($self, %args) = @_; |
|
54
|
|
|
|
|
|
|
my $url = 'https://portal.bulkgate.com/api/1.0/simple/transactional'; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$args{'text'} = unidecode($args{'text'}); |
|
57
|
1
|
|
|
1
|
1
|
800
|
$self->log("TEXT: " . $args{'text'} . ", TO: " . $args{'to'}, 4); |
|
58
|
1
|
|
|
|
|
1
|
|
|
59
|
|
|
|
|
|
|
# example: 1111:gOwn:420111222333 |
|
60
|
1
|
|
|
|
|
4
|
my @id = split(':', $self->{'login'}); |
|
61
|
1
|
|
|
|
|
17
|
my $app_id = $id[0]; |
|
62
|
|
|
|
|
|
|
my $sender_id = defined $id[1] ? $id[1] : 'gSystem'; |
|
63
|
|
|
|
|
|
|
my $sender_id_value = defined $id[2] ? $id[2] : undef; |
|
64
|
1
|
|
|
|
|
181
|
|
|
65
|
1
|
|
|
|
|
2
|
my %params = ( |
|
66
|
1
|
50
|
|
|
|
3
|
'application_id' => $id[0], |
|
67
|
1
|
50
|
|
|
|
2
|
'application_token' => $self->{'password'}, |
|
68
|
|
|
|
|
|
|
'number' => $args{'to'} || '', |
|
69
|
|
|
|
|
|
|
'text' => $args{'text'} || '', |
|
70
|
|
|
|
|
|
|
'unicode' => 0, |
|
71
|
|
|
|
|
|
|
'sender_id' => $sender_id, |
|
72
|
|
|
|
|
|
|
'sender_id_value' => $sender_id_value |
|
73
|
1
|
|
50
|
|
|
8
|
); |
|
|
|
|
50
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# cleanup |
|
76
|
|
|
|
|
|
|
$params{'number'} =~ s{\D}{}g; # remove non-digits |
|
77
|
|
|
|
|
|
|
if (length($params{'number'}) == 9) { |
|
78
|
|
|
|
|
|
|
$params{'number'} = '420' . $params{'number'}; |
|
79
|
|
|
|
|
|
|
$self->log("Auto-prefix: " . $args{'to'} . " => " . $params{'number'}, 4); |
|
80
|
1
|
|
|
|
|
2
|
} |
|
81
|
1
|
50
|
|
|
|
3
|
|
|
82
|
1
|
|
|
|
|
2
|
# send away |
|
83
|
1
|
|
|
|
|
3
|
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 }); |
|
84
|
|
|
|
|
|
|
$ua->protocols_allowed( ['https'] ); |
|
85
|
|
|
|
|
|
|
my $res = $ua->post($url, \%params ); |
|
86
|
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
181
|
if( $res->{'_rc'} == 200 ) { |
|
88
|
1
|
|
|
|
|
153
|
my $json = decode_json($res->{'_content'}); |
|
89
|
1
|
|
|
|
|
15
|
if (defined $json->{data}->{status} && $json->{data}->{status} eq 'accepted') { |
|
90
|
|
|
|
|
|
|
$self->log("SMS sent to : " . $args{'to'} . ", text: " . $args{'text'}, 4); |
|
91
|
1
|
50
|
|
|
|
31835681
|
return 1; |
|
92
|
0
|
|
|
|
|
0
|
} |
|
93
|
0
|
0
|
0
|
|
|
0
|
else { |
|
94
|
0
|
|
|
|
|
0
|
$self->log("Unexpected response from SMS provider: " . $res->{'_content'}, 4); |
|
95
|
0
|
|
|
|
|
0
|
return 0; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
0
|
|
|
|
|
0
|
else { |
|
99
|
0
|
|
|
|
|
0
|
my $json = eval { decode_json($res->{'_content'}) }; |
|
100
|
|
|
|
|
|
|
$self->log("Error " . $res->{'_rc'} . ": " . (defined $json ? $json->{error} : 'unexpected error'), 4); |
|
101
|
|
|
|
|
|
|
return 0; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
1
|
|
|
|
|
2
|
} |
|
|
1
|
|
|
|
|
13
|
|
|
104
|
1
|
50
|
|
|
|
8
|
|
|
105
|
1
|
|
|
|
|
301
|
|
|
106
|
|
|
|
|
|
|
=pod |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=encoding UTF-8 |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
SMS::Send::CZ::Bulkgate - SMS::Send driver for Bulkgate - Czech Republic |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
version 2.004 |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
use SMS::Send; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# see https://help.bulkgate.com/docs/cs/http-simple-transactional.html |
|
123
|
|
|
|
|
|
|
my $sender = SMS::Send->new('CZ::Bulkgate', |
|
124
|
|
|
|
|
|
|
_login => '1111:gOwn:420111222333', |
|
125
|
|
|
|
|
|
|
_password => 'secret', |
|
126
|
|
|
|
|
|
|
); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $sent = $sender->send_sms( |
|
129
|
|
|
|
|
|
|
text => 'Test SMS', |
|
130
|
|
|
|
|
|
|
to => '604111111', |
|
131
|
|
|
|
|
|
|
); |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# Did it send? |
|
134
|
|
|
|
|
|
|
if ( $sent ) { |
|
135
|
|
|
|
|
|
|
print "Sent test message\n"; |
|
136
|
|
|
|
|
|
|
} else { |
|
137
|
|
|
|
|
|
|
print "Test message failed\n"; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 METHODS |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 log |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Logs message to /var/log/bulkgate.log if this file is accessible and writable |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 send_sms |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Sends the message using BulkGate Simple API at https://portal.bulkgate.com/api/1.0/simple/transactional and takes additional arguments: |
|
149
|
|
|
|
|
|
|
'text' containing the message itself and 'to' providing recipient's number. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Processing information is automatically logged to /var/log/bulkgate.log to allow tracking of possible problems. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Returns true if the msssage was successfully sent |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns false if an error occured |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 AUTHOR |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Radek Šiman <rbit@rbit.cz> |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This software is copyright (c) 2022 by R-Bit Technology, s.r.o. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
168
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |