public function setConf($config)
 {
     parent::setConf($config);
     $this->playTimes = isset($config['playTimes']) ? $config['playTimes'] : 3;
     $this->respUrl = isset($config['respUrl']) ? $config['respUrl'] : null;
     $this->lang = isset($config['lang']) ? $config['lang'] : 'zh';
     $this->userData = isset($config['userData']) ? $config['userData'] : null;
     $this->welcomePrompt = isset($config['welcomePrompt']) ? $config['welcomePrompt'] : null;
     $this->playVerifyCode = isset($config['playVerifyCode']) ? $config['playVerifyCode'] : null;
 }
Пример #2
0
 /**
  * 发送模板短信
  * @param string $mobile 单个手机号或者多个手机号以逗号分割
  * @param null $message 数组,一条信息或者多条信息,约束一下格式:[‘验证码’,‘超时时间’]
  * @param int $sceneType 场景ID
  * @return stdClass|mixed|\SimpleXMLElement
  */
 public function send($mobile, $message = null, $sceneType = 1)
 {
     parent::send($mobile, $message, $sceneType);
     //主帐号鉴权信息验证,对必选参数进行判空。
     $response = $this->accAuth();
     if (!empty($response)) {
         return $response;
     }
     // 拼接请求包体
     if ($this->body_type == "json") {
         $data = "";
         for ($i = 0; $i < count($message); $i++) {
             $data = $data . "'" . $message[$i] . "',";
         }
         $body = "{'to':'{$mobile}','templateId':'{$this->template_id}','appId':'{$this->app_id}','datas':[" . $data . "]}";
     } else {
         $data = "";
         for ($i = 0; $i < count($message); $i++) {
             $data = $data . "<data>" . $message[$i] . "</data>";
         }
         $body = "<TemplateSMS>\n                    <to>{$mobile}</to>\n                    <appId>{$this->app_id}</appId>\n                    <templateId>{$this->template_id}</templateId>\n                    <datas>" . $data . "</datas>\n                  </TemplateSMS>";
     }
     //$this->showlog("request body = ".$body);
     // 大写的sig参数
     $sig = strtoupper(md5($this->account_sid . $this->account_token . $this->timestamp_));
     // 生成请求URL
     $url = "https://{$this->server_ip}:{$this->server_port}/{$this->soft_version}/Accounts/{$this->account_sid}/SMS/TemplateSMS?sig={$sig}";
     //$this->showlog("request url = ".$url);
     // 生成授权:主帐户Id + 英文冒号 + 时间戳。
     $authen = base64_encode($this->account_sid . ":" . $this->timestamp_);
     // 生成包头
     $header = array("Accept:application/{$this->body_type}", "Content-Type:application/{$this->body_type};charset=utf-8", "Authorization:{$authen}");
     // 发送请求
     $result = $this->curlPost($url, $body, $header);
     //$this->showlog("response body = ".$result);
     if ($this->body_type == "json") {
         //JSON格式
         $datas = json_decode($result);
     } else {
         //xml格式
         $datas = simplexml_load_string(trim($result, " \t\n\r"));
     }
     //重新装填数据
     if ($datas->statusCode == '000000') {
         $this->response->code = 0;
         $this->response->message = ErrorCode::$_ERROR_NO_[(string) $datas->statusCode];
         $this->response->data = $datas->templateSMS;
     } else {
         $this->response->code = (string) $datas->statusCode;
         $this->response->message = isset(ErrorCode::$_ERROR_NO_[$this->response->code]) ? ErrorCode::$_ERROR_NO_[$this->response->code] : '未知错误';
         $this->response->data = $datas->templateSMS;
     }
     return $this->response;
 }