12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace tools;
- /**
- * 企信短息发送类
- */
- class Qxsms{
- private $CorpID; //账号
- private $Pwd; //密码
- private $host = 'http://www.lxqixin.com:8082'; //接口域名
- private $error;
- public function __construct($config=array())
- {
- $this->CorpID = isset($config['qx_corpid'])?$config['qx_corpid']:'';
- $this->Pwd = isset($config['qx_pwd'])?$config['qx_pwd']:'';
- }
- /**
- * 发送短信
- * @param $mobiles 手机号多个以逗号隔开,最多1000个
- * @param $content 短信内容
- * @return bool true=发送成功 false=发送失败
- */
- public function send($mobiles,$content){
- if(!$this->CorpID){
- $this->error = '未填写账号';
- return false;
- }
- if(!$this->Pwd){
- $this->error = '未填写密码';
- return false;
- }
- $url = $this->host.'/SendMT/SendMessage?CorpID='.$this->CorpID.'&Pwd='.$this->Pwd.'&Mobile='.$mobiles.'&Content='.urlencode($content);
- try{
- $ch = curl_init ();
- curl_setopt ( $ch, CURLOPT_URL, $url );
- curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "GET" );
- curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
- curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
- curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 );
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
- $result = curl_exec ( $ch );
- curl_close ( $ch );
- if(empty($result)){
- $this->error = '发送失败';
- return false;
- }
- $result = explode(',',$result);
- if(in_array($result[0],array('00','03'))){
- return true;
- }else{
- $this->error = $result;
- return false;
- }
- }catch (\Exception $e){
- $this->error = "短信发送失败";
- return false;
- }
- }
- public function getError(){
- return $this->error;
- }
- }
|