PHP的SMS Server Tools 3驱动网管程序

有关SMS Server Tools 3的配置和使用见上一偏文章,这篇来分享我的PHP驱动程序(转载请注明出处):

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: zzly jiangyeziwh@gmail.com
 * Date: 12-7-23
 * Time: 下午6:21
 * To change this template use File | Settings | File Templates.
 */
// header('Content-Type:text/html; charset = GBK');
// 创建短信文件
function createSms ($smsfile, $phone, $message)
{
    if($handle = fopen($smsfile, "w"))
    {
        $body = stripcslashes(urldecode($message));
        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 externGroup ($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 unreadable file!");
    }
}
?>


<?php
// 发送主程序
// 接口
// $ghp = $_GET['ghp'];
// $hp = $_GET['hp'];
// $rawmsg = $_GET['msg'];

//示例
$ghp = "";
$hp = "186****2580";
$rawmsg = "这是PHP程序发送的";

// $msg = iconv("UTF-8", "GBK//IGNORE", $rawmsg);

$smsd_work_dir = "/var/spool/sms/outgoing/";
$group_file_dir = "/var/spool/sms/data/";

if($ghp == "")
{
    if($hp == "")
    {
        die("Phone number is null");
    }
    else
    {
        $sms_file_name = $smsd_work_dir . "GSM1." . rand(10000, 99999);
        $phone = "86" . $hp;
        createSms($sms_file_name, $phone, $rawmsg);
        echo "Send succuse!";
    }
}
else
{
    $groupfile = $group_file_dir . $ghp . "txt";
    externGroup($groupfile);
    foreach(externGroup($groupfile) as $phonenumber)
    {
        $sms_file_name = $smsd_work_dir . "GSM1." . rand(10000, 99999);
        $phone = "86" . $phonenumber;
        createSms($sms_file_name, $phone, $msg);
        echo "Send succuse!";
    }
}
?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值