写了一个简单的PHP程序,结合SMS Server Tools 3,可以作为发送短信用的网关。
可以发给一个手机,也可以发给一组手机,只要提供组名,程序会自动展开。
没啥技术含量,主要就是PHP的文件操作和url转换,有需要的朋友可以拿去用,纯GPL
<?php
//创建短信文件
function CreateSMS($smsfile,$phone,$message){
if ($handle = fopen($smsfile, "w")){
$body = stripslashes(urldecode($message)); //解码URL
fputs($handle, "To: $phone\n"); //要发送的手机号
fputs($handle, "Alphabet: UCS\n"); //短信编码
fputs($handle, "\n");
if (strlen($body) > 0)
{
$body = iconv('utf-8','UCS-2BE',$body); //把消息内容转换成中文短信格式
fputs($handle, "$body");
}
else
{
fputs($handle, "\n");
}
fclose($handle);
}
else
return 2;
}
//展开短信用户组
function ExpandGroup($groupfile){
if (is_readable($groupfile)){
$lines = file($groupfile); //将文件的每一行读入数组
foreach ($lines as $tempstring)
{
$tempstring = explode("\t",$tempstring);
$phone[] = $tempstring[0];
}
return $phone; //返回手机号码数组
}
else
die ("Can't open group file!");
}
// Main程序
$ghp = $_GET['ghp'];
$hp = $_GET['hp'];
$rawmsg = $_GET['msg'];
$msg = iconv("gb2312","utf-8",$rawmsg); //把消息中的中文转换成utf-8格式
$smsd_work_dir = "/var/spool/sms/outgoing/";
$group_file_dir = "/home/wwwroot/sms/data/";
if ($ghp == ""){
if ($hp == ""){
die ("Phone number is null!");
}
else{
$sms_file_name = "$smsd_work_dir"."SMS_".rand(10000, 99999);
$phone = "86".$hp;
CreateSMS($sms_file_name,$phone,$msg);
}
}
else{
$groupfile = "$group_file_dir"."$ghp".".txt";
ExpandGroup($groupfile);
foreach (ExpandGroup($groupfile) as $phonenumber)
{
$sms_file_name = "$smsd_work_dir"."SMS_".rand(10000, 99999);
$phone = "86".$phonenumber;
CreateSMS($sms_file_name,$phone,$msg);
}
}
?>[/img]..