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

来源:互联网 发布:seo文章内链 编辑:程序博客网 时间:2024/06/06 00:02

有关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!";    }}?>