去年年中的時候架了一個 SmokePing 來監測某公司幾個服務的 Network Latency 問題,用 SmokePing 的原因是他支援數種協定,所以我可以一口氣拿來監測 DNS, SSH Daemon, RADIUS, Web, SMTP 等。而且 SmokePing 的架構頗模組化,只要稍加修改幾個 Perl Script 就可以很快的滿足我的需求。

不過既然已經隨時偵測網路服務,光是使用電子郵件通知也稍嫌不夠即時。於是起意做了簡訊通知功能,隨意找了幾個 SMS 服務供應商,決定拿便宜的 PCHOME 一元簡訊來頂著用。感謝 SnowFLY (飄然似雪) 做了 SMS PCHOMENet-SMS-PChome Perl module,省了不少功夫。也因此半夜時常被簡訊吵醒。

不過 CPAN 上的版本是 2006 年,跟目前的 PCHOME 網頁不太相容,稍加修改後如

diff -ru Net-SMS-PChome-0.11/META.yml Net-SMS-PChome-0.12/META.yml
--- Net-SMS-PChome-0.11/META.yml	2006-08-17 10:46:30.000000000 +0800
+++ Net-SMS-PChome-0.12/META.yml	2007-08-02 23:49:30.000000000 +0800
@@ -1,7 +1,7 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         Net-SMS-PChome
-version:      0.11
+version:      0.12
 version_from: lib/Net/SMS/PChome.pm
 installdirs:  site
 requires:
diff -ru Net-SMS-PChome-0.11/lib/Net/SMS/PChome.pm Net-SMS-PChome-0.12/lib/Net/SMS/PChome.pm
--- Net-SMS-PChome-0.11/lib/Net/SMS/PChome.pm	2006-08-17 10:46:17.000000000 +0800
+++ Net-SMS-PChome-0.12/lib/Net/SMS/PChome.pm	2007-08-02 23:50:31.000000000 +0800
@@ -6,7 +6,7 @@
 use HTML::TagParser;
 use Date::Calc qw(check_date check_time Today_and_Now This_Year);
 
-our $VERSION = '0.11';
+our $VERSION = '0.12';
 our (@ISA) = qw(Exporter);
 our (@EXPORT) = qw(send_sms);
 
@@ -118,11 +118,7 @@
    #### Check for mandatory input
    foreach(qw/username password authcode recipients message sendType encodeType/) {
       $self->_croak("$_ not specified.") unless(defined $self->{"_$_"});
-      if($_ eq 'recipients') {
-         $parms->{$_} = join(";", @{$self->{"_$_"}});
-      } else {
-         $parms->{$_} = $self->{"_$_"};
-      }
+      $parms->{$_} = $self->{"_$_"};
    }
 
    # Type can be now/dlv
@@ -165,16 +161,24 @@
    $self->{"_ua"}->agent_alias('Windows IE 6');
    $self->{"_ua"}->get($self->baseurl);
    $self->{"_ua"}->form_number(1);
-   $self->{"_ua"}->field('smsid', $parms->{username});
+   $self->{"_ua"}->field('fuid', $parms->{username});
    $self->{"_ua"}->field('pwd', $parms->{password});
-   $self->{"_ua"}->submit();   
+   $self->{"_ua"}->submit();
    
    # Input SMS_Message, Recipients
    $self->{"_ua"}->form_number(2);
    $self->{"_ua"}->field('InputMsg', $parms->{message});
-   $self->{"_ua"}->field('mobiles', $parms->{recipients});
+   # $self->{"_ua"}->field('mobiles', $parms->{recipients});
+   $self->{"_ua"}->field('firstClick', '1');
+   foreach (1..scalar(@{$self->{"_recipients"}})) {
+       my $field = sprintf("mobile%.2d", $_);
+       $self->{"_ua"}->field($field, @{$parms->{recipients}}[$_-1]);
+   }
    $self->{"_ua"}->field('sendType', $parms->{sendType});
-   $self->{"_ua"}->field('longCount', scalar(@{$self->{"_recipients"}}));
+ 
+   # $self->{"_ua"}->field('longCount', scalar(@{$self->{"_recipients"}}));
+   $self->{"_ua"}->field('encodeType', $parms->{encodeType});
+   $self->{"_ua"}->field('payType', "PChomeTCC");
 
    if($self->smsType eq '2') {
    	$self->{"_ua"}->select('year', ($parms->{year} - This_Year()));
@@ -184,7 +188,6 @@
    	$self->{"_ua"}->select('minute', $parms->{minute});
    }
    $self->{"_ua"}->submit();
-
    # Input Authcode	
    $self->{"_ua"}->field('auth_code', $parms->{authcode});
    $self->{"_ua"}->current_form()->action('https://ezpay.pchome.com.tw/auth_form_do');
@@ -225,15 +228,15 @@
    # Set/override defaults
    my %options = (
       ua                => $ua,
-      baseurl           => 'http://sms.pchome.com.tw/jsp/smslong.jsp',
-      username          => undef,	#	帳號
-      password          => undef,	#	密碼
+      baseurl           => 'http://sms.pchome.com.tw/front_end/sms', # 'http://sms.pchome.com.tw/jsp/smslong.jsp',
+      username          => undef,	#	帳號
+      password          => undef,	#	密碼
       authcode		=> undef,	#       Auth Code
-      recipients	=> [],		#	收訊者
-      message           => undef,	#	簡訊內容
+      recipients	=> [],		#	收訊者
+      message           => undef,	#	簡訊內容
 
-      dlvdatetime	=> undef,	#	預約時間 delivery date
-      sendType          => '1',		#	1 =>立即發送, 2 => 預約發送
+      dlvdatetime	=> undef,	#	預約時間 delivery date
+      sendType          => '1',		#	1 =>立即發送, 2 => 預約發送
       encodeType	=> 'BIG5',	#	BIG5, ASCII
 
       success           => undef,	#
@@ -253,7 +256,7 @@
    my $html = HTML::TagParser->new($input);
    my $list = [$html->getElementsByTagName( "td" )];
  
-   if ($list->[12]->innerText =~ m/恭喜您扣點消費成功\\/) {
+   if ($list->[12]->innerText =~ m/恭喜您扣點消費成功/) {
  	# success  
    	$item->{"order_sn"} 		= $list->[17];#
    	$item->{"Consume_summary"} 	= $list->[19];#

Patch 可於下載,亦可下載我個人使用的 Debian package. 🙂