Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function send($mobile, $content, $extend = '', $uid = '', $callback_url = '')
 {
     if (parent::send($mobile, $content)) {
         return true;
     }
     $data = ['apikey' => $this->apikey, 'mobile' => $mobile, 'text' => $content];
     if ($extend) {
         $data['extend'] = $extend;
     }
     if ($uid) {
         $data['uid'] = $uid;
     }
     if ($callback_url) {
         $data['callback_url'] = $callback_url;
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->url);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
     $result = curl_exec($ch);
     curl_close($ch);
     $json = json_decode($result);
     if ($json && is_object($json)) {
         $this->state = isset($json->code) ? (string) $json->code : null;
         $this->message = isset($json->msg) ? (string) $json->msg : null;
     }
     return $this->state === '0';
 }
    /**
     * @inheritdoc
     */
    public function sendByTemplate($mobile, $data, $id)
    {
        if (parent::sendByTemplate($mobile, $data, $id)) {
            return true;
        }
        if ($this->dataType === 'json') {
            $body = json_encode(['to' => $mobile, 'templateId' => $id, 'appId' => $this->appId, 'datas' => array_values($data)]);
        } elseif ($this->dataType === 'xml') {
            $dataStr = '';
            foreach ($data as $val) {
                $dataStr .= "<data>{$val}</data>";
            }
            $body = <<<XML
<TemplateSMS>
    <to>{$mobile}</to>
    <appId>{$this->appId}</appId>
    <templateId>{$id}</templateId>
    <datas>{$dataStr}</datas>
</TemplateSMS>
XML;
        } else {
            throw new InvalidConfigException('“dataType” 配置不正确。');
        }
        $sig = strtoupper(md5($this->accountSid . $this->accountToken . $this->getBatch()));
        $this->url = "https://{$this->serverIp}:{$this->serverPort}/{$this->softVersion}/Accounts/{$this->accountSid}/SMS/TemplateSMS?sig={$sig}";
        $authen = base64_encode($this->accountSid . ':' . $this->getBatch());
        $header = ["Accept:application/{$this->dataType}", "Content-Type:application/{$this->dataType};charset=utf-8", "Authorization:{$authen}"];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        $result = curl_exec($ch);
        curl_close($ch);
        if (empty($result)) {
            $this->state = '172001';
            $this->message = '网络错误';
        } else {
            if ($this->dataType === 'json') {
                $json = json_decode($result);
                if ($json && is_object($json)) {
                    $this->state = isset($json->statusCode) ? (string) $json->statusCode : null;
                    $this->message = isset($json->statusMsg) ? (string) $json->statusMsg : null;
                }
            } else {
                $xml = simplexml_load_string(trim($result, " \t\n\r"));
                if ($xml && is_object($xml)) {
                    $this->state = isset($xml->statusCode) ? (string) $xml->statusCode : null;
                    $this->message = isset($xml->statusMsg) ? (string) $xml->statusMsg : null;
                }
            }
        }
        return $this->state === '000000';
    }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 public function send($mobile, $content)
 {
     if (parent::send($mobile, $content)) {
         return true;
     }
     $data = ['action' => 'sendsms', 'username' => $this->username, 'userpwd' => $this->password, 'mobiles' => $mobile, 'content' => $content];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
     $this->state = (string) curl_exec($ch);
     curl_close($ch);
     $success = false;
     switch ($this->state) {
         case '':
         case '-1':
             $this->message = '用户名或密码错误';
             break;
         case '-2':
             $this->message = '余额不足';
             break;
         case '-3':
             $this->message = '号码太长,不能超过1000条一次提交';
             break;
         case '-4':
             $this->message = '无合法号码';
             break;
         case '-5':
             $this->message = '内容包含关键字';
             break;
         case '-6':
             $this->message = '内容太长,超过9条';
             break;
         case '-7':
             $this->message = '内容为空';
             break;
         case '-8':
             $this->message = '定时时间格式不对';
             break;
         case '-9':
             $this->message = '修改密码失败';
             break;
         case '-10':
             $this->message = '用户当前不能发送短信';
             break;
         case '-11':
             $this->message = 'Action参数不正确';
             break;
         case '-100':
             $this->message = '系统错误';
             break;
         default:
             $this->message = '短信发送成功';
             $success = true;
             break;
     }
     return $success;
 }
 /**
  * @inheritdoc
  */
 public function send($mobile, $content)
 {
     if (parent::send($mobile, $content)) {
         return true;
     }
     $data = ['uid' => $this->username, 'key' => $this->password, 'smsMob' => $mobile, 'smsText' => $content];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
     $this->state = (string) curl_exec($ch);
     curl_close($ch);
     $success = false;
     switch ($this->state) {
         case '':
         case '-1':
             $this->message = '没有该用户账户';
             break;
         case '-2':
             $this->message = '接口密钥不正确';
             break;
         case '-21':
             $this->message = 'MD5接口密钥加密不正确';
             break;
         case '-3':
             $this->message = '短信数量不足';
             break;
         case '-11':
             $this->message = '该用户被禁用';
             break;
         case '-14':
             $this->message = '短信内容出现非法字符';
             break;
         case '-4':
             $this->message = '手机号格式不正确';
             break;
         case '-41':
             $this->message = '手机号码为空';
             break;
         case '-42':
             $this->message = '短信内容为空';
             break;
         case '-51':
             $this->message = '短信签名格式不正确';
             break;
         case '-6':
             $this->message = 'IP限制';
             break;
         default:
             $this->message = '短信发送成功';
             $success = true;
             break;
     }
     return $success;
 }
Beispiel #5
0
 /**
  * @inheritdoc
  */
 public function send($mobile, $content)
 {
     if (parent::send($mobile, $content)) {
         return true;
     }
     $data = ['uid' => $this->username, 'pwd' => $this->password, 'mobile' => $mobile, 'content' => $content];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->url);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
     $result = curl_exec($ch);
     curl_close($ch);
     $resultArr = [];
     parse_str($result, $resultArr);
     $this->state = isset($resultArr['stat']) ? (string) $resultArr['stat'] : null;
     $this->message = isset($resultArr['message']) ? (string) $resultArr['message'] : null;
     return $this->state === '100';
 }