receiver=""; $this->context=""; $this->err=array(); return $this; } /** * setReceiver * * 接收号码 * * @param string $s * * @return this */ function setReceiver($s) { if(substr($s,-1,1)!=';')$s.=';'; if(preg_match("/^1[34578][0-9]{9}$/",$s)||preg_match("/^(1[3458][0-9]{9};){1,}$/",$s)) { $this->receiver.="$s;"; } else { $this->err[]="($s)不是有效的手机号码"; } return $this; } /** * setContent * * 发送的内容 * * @param string $s * * @return this */ function setContent($s) { $this->contextOld=$s; $l=mb_strlen($s,'utf-8'); if($l>$this->contextMax) { $this->err[]="字符数{$l}大于允许的范围($s)"; } else { $c=$this->badWords($s); if($c) { $this->err[]="包含非法字符($c)"; } else { $s=str_replace ( array("&","小姐","%","=","公寓" ,"1259","1989" ,"江罗","奥运","别墅","简装","精装","装修","毛坯","人大","平"), array("&","女士","%","=","公十寓","12五9","19八9","江十罗","奥十运","别野","简::装","精::装","装::修","毛 坯","人 大"," 平"), $s ); $this->context=urlencode($s); } } return $this; } /** * getError * * 错误信息 * * @param null * * @return array */ function getError() { return $this->err; } /** * send * * 发送 * * @param null * * @return int */ function send() { if(!$this->context||!$this->receiver)$this->err[]="缺少接收目标或内容"; if($this->err)return false; /*把非数字换成空*/ $this->receiver=preg_replace("/[^\d]+$/",'',$this->receiver); /*把;号换成,*/ $this->receiver=preg_replace("/[;]+/",',',$this->receiver); /*长度小600直接发*/ if(strlen($this->receiver)<600)/** 少于50个手机号码 **/ { return $this->send2($this->receiver); } $n=0; $p1=0; $step=580; $stopFlag=9999999; $l=strlen($this->receiver)-$step; while(1) { if($p1<$l) { $p2=strpos($this->receiver,',',$p1+$step);if($p2<1)$p2=$stopFlag; } else { $p2=$stopFlag; } $s=substr($this->receiver,$p1,$p2-$p1); $n+=$this->send2($s); $p1=$p2;if($p2==$stopFlag)break; } return $n; } /** * balance * * 查余额 * * @param null * * @return bool */ function balance() { $path="{$this->server}balance.do?username={$this->username}&password={$this->password}"; $s=file_get_contents($path); $re=array_combine(array('productid','type','live'),explode(',',$s)); stop($re); } /** * send2 * * 发送 * * @param null * * @return int */ private function send2($mobiles) { $path="{$this->server}sendXSms.do?username={$this->username}&password={$this->password}&mobile={$mobiles}&content={$this->context}&productid=0000000&dstime=&xh="; $s=file_get_contents($path);error_log($_SERVER['REQUEST_URI']."\t$s\t$path\n",3,"./logs/1680.txt"); $re=$this->parse($s); $n=intval($re); if($n<1) { $this->err[]='error'.iconv("GBK","UTF-8",$re); } else { $this->msg[]=$s; } return $n; } /** * badWords * * 字符过滤 * * @param string $s * * @return bool */ private function badWords($s) { /**** $rs=cacheFile("z1sms");if(!$rs)$rs=$this->getBlackWords(); foreach($rs as $v) { if(strpos($s,$v)!==false)return $v; } ****/ return false; } /** * getBlackWords * * 获取字符过滤 * * @param null * * @return string */ private function getBlackWords() { return ''; } /** * parse * * 解析 * * @param string * * @return array */ private function parse($s) { return intval($s)==1?$s:"0 : $s"; } }