文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一个短信的类

一个短信的类

时间:2006-01-18  来源:wleige


    /* public connection parameters */
    var $SrvHost = "212.95.130.225";  //短信服务器地址
    var $Port = "8010"; //短信服务器端口
     
    /* private parameters */
    var $Id = ""; //连接Id
    var $Password = ""; //连接密码
    var $fp = "";
    var $Fee = 0; //短信收费类型:0-免费;1-按条收费;2-包月封顶收费
    var $errno = 0;
    var $errstr = "";
    var $Loggedin = false;
    /* constructor */
    function SMS($id,$passwd)
    {
$this->Id = $id;
$this->Password = $passwd;
$this->fp = fsockopen($this->SrvHost,$this->Port,$this->errno,$this->errstr);
if(!$this->fp)
     $this->halt("无法建立连接");
    }
     
    /* private Login as sender:should be called before SendMsg()*/
    function SLogin()
    {
  
fputs($this->fp,"SLogin ".$this->Id.",".$this->Password."\r\n");
$tempstr = fgets($this->fp,20);
if(!ereg("OK",$tempstr))
     $this->halt("登陆错误!");   
$this->Loggedin = true;
    }
     
    /* private Login as recipient:should be called before Receive*/
    function RLogin()
    {
  
fputs($this->fp,"RLogin ".$this->Id.",".$this->Password."\r\n");
$tempstr = fgets($this->fp,20);
echo $tempstr;
if(!ereg("OK",$tempstr))
     $this->halt("登陆错误!");     
    }
     
    /* public SendMessage */
    function SendMsg($Mobile,$Msg,$format,$OrderNo = 0)
    {
global $smsfreeid;
if(!$this->Loggedin)
     $this->SLogin(); //Login
$Msg = rawurlencode(trim($Msg));
$command = "Send Id=".$this->Id."&pwd=".$this->Password."&Mobile=$Mobile&Fmt=$format&Msg=$Msg";
if($this->Id != $smsfreeid)
     $command .= "&Fee=1&FeeNo=$Mobile";
else
     $command .= "&Fee=0";
if($OrderNo)
     $command .= "&OrderNo=$OrderNo";
$command .= "\r\n";
  
//echo $command;
fputs($this->fp,$command);
$tempstr = fgets($this->fp,20);
  
if(ereg("OK",$tempstr))
     return true;
      
elseif(ereg("Error 1",$tempstr))
     $this->halt("Id号无法识别");
      
elseif(ereg("Error 1",$tempstr))
     $this->halt("非法IP地址");
      
elseif(ereg("No Msg",$tempstr))
     $this->halt("对不起,信息内容不能为空");
else
     $this->halt("发送失败,可能服务器忙,请稍候重试");
    }
    /* public */
     
    function Receive($SMobile,$DMobile,$Msg)
    {     
/*
Id:连接标识号,每一个Id对应一个服务号码和计费方式,一般情况下每客户端只有一个Id号。如果该客户
     端下接好多种服务,即可使用多Id的情况。
SMobile:呼叫方手机号码,即用户手机号码
DMobile:被叫服务号码.
Msg:短信内容。
*/
$this->RLogin();
  
$command = "Receive Id=".$this->Id."&pwd=".$this->Password;
$command .= "&SMobile=$SMobile&DMobile=$DMobile&Msg=$Msg";
$command .= "\r\n";
echo $command;
fputs($this->fp,$command);
$tempstr = fgets($this->fp,20);
if(ereg("OK",$tempstr))
     return ture;
else     
     $this->halt("注册失败,可能服务器忙,请稍候重试");
    }
     
    /* public: close the connection*/
    function close()
    {
if($this->fp)
     fclose($this->fp);
    }
     
    /* private */
    function halt($msg)
    {
$this->close();
exit($msg);
    }
}
?>


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载