コード例 #1
0
 public function send($username, $recipient, $message, array $passwordLocations)
 {
     $rcptDir = $this->messageDir . '/' . $recipient;
     if (file_exists($rcptDir) && (!is_writable($rcptDir) || !is_dir($rcptDir))) {
         throw new \RuntimeException('Message directory is not writable!');
     }
     if (!file_exists($rcptDir)) {
         mkdir($rcptDir);
     }
     $messageFileName = date('YmdHis') . '-' . uniqid() . '.sms';
     $fd = fopen($rcptDir . '/' . $messageFileName, 'w');
     fwrite($fd, $message);
     fclose($fd);
     $this->logger->messageLog($username, $recipient, $message, $passwordLocations);
     return true;
 }
コード例 #2
0
 public function send($username, $recipient, $message, array $passwordLocations)
 {
     if ($this->logger === null) {
         throw new \LogicException('Logger is not defined!');
     }
     $descriptors = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
     $cmd = escapeshellcmd($this->gnokiiPath . ' --sendsms ' . escapeshellarg($recipient));
     $pipes = array();
     $process = proc_open($cmd, $descriptors, $pipes, null, array('LANG' => 'en_US.UTF-8'));
     if (is_resource($process)) {
         fwrite($pipes[0], $message);
         fclose($pipes[0]);
         $stdout = stream_get_contents($pipes[1]);
         $stderr = stream_get_contents($pipes[2]);
         $returnValue = proc_close($process);
         if ($returnValue != 0) {
             throw new \RuntimeException('Unable to send SMS: ' . $stderr . '; ' . $stdout);
         }
         $this->logger->messageLog($username, $recipient, $message, $passwordLocations);
     } else {
         throw new \RuntimeException('Unable to start Gnokii.');
     }
     return true;
 }