[工具开发] 一信通 Web 短信发送客户端
一、简介
为了协助公司运营部对几家短信平台进行测试,我根据各自的接口文档编写了几个简单的短信发送客户端;
下面是一信通 Web 短信发送客户端,使用 HTTP GET 方法。
二、效果图
1. 首页
2. 返回页
三、源代码
1. index.pl
#!/usr/bin/perl -w #Hu Peng #penghu.zh@gmail.com use strict; use 5.10.1; use CGI; use Encode; my $form_action = '/yxt/send.pl'; my $q = CGI->new; my $smsMsg = '您的验证码为1232'; print $q->header(-type=>'text/html',-charset=>'UTF-8'), $q->start_html(-title=>'一信通短信平台测试'), $q->start_form(-action=>$form_action, -method=>'post'), $q->p({-align=>'center'},'一信通短信平台测试'), $q->start_table({-align=>'center',-border=>'0',-cellpadding=>'4',-cellspacing=>'0'}), $q->start_Tr, $q->start_td({-align=>'left'}),'短信内容: '.$q->input({-id=>'smsMsg',-type=>'text',-name=>'smsMsg',-value=>$smsMsg}),$q->end_td, $q->end_Tr, $q->start_Tr, $q->start_td({-align=>'left'}),'接收号码: '.$q->input({-id=>'smsPhone',-type=>'text',-name=>'smsPhone',-title=>'多个号码用,隔开'}),$q->end_td, $q->end_Tr, $q->end_table, $q->p({-align=>'center'},$q->submit(-value=>'发 送')), $q->end_form, $q->br, $q->end_html;
2. send.pl
#!/usr/bin/perl -w #Hu Peng #penghu.zh@gmail.com use strict; use 5.10.1; use CGI; use Encode; use LWP::UserAgent; my $form_action = '/yxt/index.pl'; my $q = CGI->new; sub sendSMS { my ($opt_u,$opt_p,$opt_r,$opt_m) = @_; my $msg = encode('gbk',decode('utf8',$opt_m)); my $ua = LWP::UserAgent->new; my $url = 'http://js.ums86.com:8899/sms/Api/Send.do?SpCode=201971&LoginName='.$opt_u.'&Password='.$opt_p.'&MessageContent='.$msg.'&UserNumber='.$opt_r.'&SerialNumber=&ScheduleTime=&f=1'; my $resp = $ua->get($url); if ($resp->is_success) { my $message = encode('utf8',decode('gbk',$resp->decoded_content)); return "$message\n"; }else{ return "HTTP GET error code: ".$resp->code.':'.$resp->message."\n"; } } my $smsMsg = defined($q->param('smsMsg'))?$q->param('smsMsg'):''; my $smsPhone = defined($q->param('smsPhone'))?$q->param('smsPhone'):''; my $return = &sendSMS('YOUR_ACCOUNT','YOUR_PASSWORD',$smsPhone,$smsMsg); print $q->header(-type=>'text/html',-charset=>'UTF-8'), $q->start_html(-title=>'一信通短信平台测试'), $q->start_form(-action=>$form_action, -method=>'post'), $q->p({-align=>'center'},'一信通短信平台测试'), $q->start_table({-align=>'center',-border=>'0',-cellpadding=>'4',-cellspacing=>'0'}), $q->start_Tr, $q->start_td({-align=>'left'}),'返回信息: '.$return,$q->end_td, $q->end_Tr, $q->end_table, $q->p({-align=>'center'},$q->submit(-value=>'返 回')), $q->end_form, $q->br, $q->end_html;