Esempio n. 1
0
 public function send($mobile, $message = null, $sceneType = 1)
 {
     parent::send($mobile, $message, $sceneType);
     $flag = 0;
     $argv = array('sn' => $this->_sn, 'pwd' => strtoupper(md5($this->_sn . $this->_password)), 'mobile' => "{$mobile}", 'content' => urlencode("{$this->message}[{$this->_appName}]"), 'ext' => $this->_ext, 'rrid' => $this->_rrid, 'stime' => $this->_stime);
     $params = '';
     foreach ($argv as $key => $value) {
         if ($flag != 0) {
             $params .= "&";
             $flag = 1;
         }
         $params .= $key . "=";
         $params .= urlencode($value);
         $flag = 1;
     }
     $length = strlen($params);
     //创建socket连接
     $fp = fsockopen("sdk2.entinfo.cn", 8060, $errno, $errstr, 10);
     if (!$fp) {
         return false;
     }
     //构造post请求的头
     $header = "POST /webservice.asmx/mdSmsSend_u HTTP/1.1\r\n";
     $header .= "Host:sdk2.entinfo.cn\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . $length . "\r\n";
     $header .= "Connection: Close\r\n\r\n";
     //添加post的字符串
     $header .= $params . "\r\n";
     //发送post的数据
     fputs($fp, $header);
     $inheader = 1;
     while (!feof($fp)) {
         $line = fgets($fp, 1024);
         //去除请求包的头只显示页面的返回数据
         if ($inheader && ($line == "\n" || $line == "\r\n")) {
             $inheader = 0;
         }
         if ($inheader == 0) {
             // echo $line;
         }
     }
     $line = str_replace("<string xmlns=\"http://tempuri.org/\">", "", $line);
     $line = str_replace("</string>", "", $line);
     //$result = explode("-",$line);
     $this->response->code = $line > 1 ? 0 : $line;
     $this->response->message = $this->response->code == 0 ? '发送成功' : ErrorCode::$_ERROR_NO_[$this->response->code];
     $this->response->data = null;
     return $this->response;
 }
Esempio n. 2
0
 /**
  * 发送验证码
  * @param string $mobile 手机号
  * @param string $message 验证码
  * @param int $sceneType 场景ID
  * @return string
  */
 public function send($mobile, $message = null, $sceneType = 1)
 {
     parent::send($mobile, $message, $sceneType);
     $content = sprintf($this->content_tpl, $message, $this->suffix);
     $content = urlencode($content);
     //当前格林尼治时间戳
     $time = $this->timestamp - 8 * 3600;
     $authKey = md5($this->username . $time . md5($this->password) . $this->secret_key);
     $options = array('username' => $this->username, 'time' => $time, 'mobile' => $this->mobile, 'content' => $content, 'authkey' => $authKey);
     $code = $this->triggerSms($options);
     $this->response->code = $code == 1 ? 0 : $code;
     $this->response->message = in_array($code, $this->msg_arr) ? $this->msg_arr[$code] : '未知错误';
     $this->response->data = null;
     return $this->response;
 }
 /**
  * 下发验证码
  * @param $mobile
  * @param null $message
  * @param int $sceneType
  * @return string
  */
 public function send($mobile, $message = null, $sceneType = 1)
 {
     parent::send($mobile, $message, $sceneType);
 }