一些 SMS 的 function

這邊提供 PHS (大眾)、emome (中華電信)、HiNet ADSL (中華電信)、PChome (電腦家庭) 所提供的簡訊介面的 Perl code 讓大家用,其中我自己平常有在跑的是 emomePChome 兩個,其他的我就不清楚了…

這是 HiNet ADSL 的 code:

#!/usr/bin/perl

use WWW::Mechanize;
use strict;

&sendsms("HN 號碼", "密碼", "0911341234", "簡訊測試");

sub sendsms
{
  my ($username, $password, $receiver, $msg) = @_;

  my $number = 0;

  my $agent = WWW::Mechanize->new();
  $agent->get("http://hiair.hinet.net/hweb/hiairpost_new.jsp");
  $agent->form("form1");

  foreach (split(/[ ,]+/, $receiver))
  {
    $agent->field("tel", $_, ++$number);
  }

  $agent->field("add_name", "0");
  $agent->field("message", $msg);
  $agent->submit();

  $agent->form("loginform");
  $agent->submit();

  $agent->form("AuthScreen");
  $agent->field("aa-uid", $username);
  $agent->field("aa-passwd", $password);
  $agent->submit();

  foreach (split(/\r|\n/, $agent->content()))
  {
    next unless (/window.location.href='/i);

    $_ =~ /window.location.href='(.+)'/i;
    my $newurl = $1;

    $agent->get($newurl);
    last;
  }

  print($agent->content());
}

這是 PChome 的 code:

#!/usr/bin/perl

use HTML::Form;
use WWW::Mechanize;
use strict;

&sendsms('username', 'password', 'confirm code', '0911341234', '測試簡訊');

sub sendsms
{
  my ($username, $password1, $password2, $receiver, $msg) = @_;

  my $agent = WWW::Mechanize->new();
  $agent->agent_alias('Windows IE 6');
  $agent->get('http://sms.pchome.com.tw/front_end/sms');

  $agent->form_number(1);
  $agent->field('fuid', $username);
  $agent->field('pwd', $password1);
  $agent->submit();

  $agent->form_number(2);
  $agent->field('InputMsg', $msg);

  my $num = 0;
  foreach my $phone_number (split(/,+/, $receiver))
  {
    $agent->field(sprintf('mobile%02d', ++$num), $phone_number);
  }

  $agent->submit();

  $agent->field('auth_code', $password2);
  $agent->current_form()->action('https://ezpay.pchome.com.tw/auth_form_do');
  $agent->submit();
}

再來是 PHS 的 code:

#!/usr/bin/perl

use WWW::Mechanize;
use strict;

&sendsms("0968123123", "A123456789", "0968123123", "PHS SMS test");

sub sendsms
{
  my (%h);

  my ($username, $password, $receiver, $msg) = @_;

  my $agent = WWW::Mechanize->new();
  $agent->agent_alias('Windows IE 6');

  $agent->get('http://www.phs.com.tw/myphs/Login.asp?URL=Send-SMS.asp');
  $agent->form('form1');
  $agent->field('PhoneNo', $username);
  $agent->field('PWD', $password);

  my $con = $agent->submit();

  $agent->get('Send-SMS.asp');

  $agent->form('frmSS');
  $agent->field("txtSMS", $msg);
  $agent->field("RcvPhoneNo1", $receiver);
  $agent->field("rdSendTime", "R");

  $con = $agent->submit();
}

最後是 emome

#!/usr/bin/perl

use HTML::Form;
use WWW::Mechanize;
use strict;

&sendsms('0911341234', '123456', '0911341234', '我是 dk,來打 settler 或 war3 吧');

sub sendsms
{
  my ($username, $password, $receiver, $msg) = @_;

  my $agent = WWW::Mechanize->new();
  $agent->agent_alias('Windows IE 6');
  $agent->get('http://www.emome.net/cgi-bin/MASP/jsp/membersvc/AuthServlet?serviceId=5235');

  $agent->form('myform');
  $agent->field('MSISDN', $username);
  $agent->field('PASSWD', $password);
  $agent->submit();

  $agent->form('form1');
  $agent->field('phonelist', $receiver);
  $agent->field('data', $msg);
  $agent->field('language', 2);         # 1 == 中,2 == 英
  $agent->current_form()->action('http://websms1.emome.net/sms/sendsms/send.jsp');
  $agent->submit();
}