コード例 #1
0
ファイル: ToEmail.php プロジェクト: pinepain/sms-krank
 /**
  * @param PhoneNumber $number
  * @param Message     $message
  * @param \DateTime   $schedule
  *
  * @throws \SMSKrank\Exceptions\GatewayException
  *
  * @return float | null Message fee, if available. Null otherwise
  */
 public function send(PhoneNumber $number, Message $message, \DateTime $schedule = null)
 {
     $mailer = new PHPMailer();
     $mailer->IsSMTP();
     $mailer->Port = $this->port;
     $mailer->Host = $this->host;
     if ($this->user || $this->password) {
         $mailer->SMTPAuth = true;
         $mailer->Username = $this->user;
         $mailer->Password = $this->password;
     }
     $mailer->CharSet = "UTF-8";
     $mailer->From = $this->from;
     $mailer->Subject = "SMS-Krank Debug Gateway";
     if (empty($this->to)) {
         throw new GatewayException('No recipients');
     }
     foreach ($this->to as $to) {
         if (!$mailer->AddAddress($to)) {
             throw new GatewayException("Invalid recipient: '{$to}'");
         }
     }
     $nl = "\r\n";
     $mailer->Body .= "Phone: " . $number->getNumber() . $nl;
     $mailer->Body .= "Message: " . $message->getText() . $nl;
     $mailer->Body .= "Scheduled: " . ($schedule ? $schedule->format(\DateTime::ISO8601) : 'immediately');
     if (!$mailer->Send()) {
         throw new GatewayException("Failed to send");
     }
     return null;
 }
コード例 #2
0
ファイル: AtomparkCom.php プロジェクト: pinepain/sms-krank
 public function send(PhoneNumber $number, Message $message, \DateTime $schedule = null)
 {
     $args = array('key' => $this->public_key, 'text' => $message->getText(), 'phone' => $number->getNumber(), 'sender' => $this->sender);
     if ($schedule) {
         // NOTE: this gate traits date timezone as your location provided in cabinet
         $args['datetime'] = $schedule->format("Y-m-d H:i:s");
     }
     $json = $this->call('sendSMS', $args);
     if (!isset($json['price'])) {
         throw new GatewayException('Bad response');
     }
     return (double) $json['price'];
     // price amount is set in user prefs
 }
コード例 #3
0
ファイル: EchoDude.php プロジェクト: pinepain/sms-krank
 public function send(PhoneNumber $number, Message $message, \DateTime $schedule = null)
 {
     if ($this->balance - $this->price < 0) {
         throw new GatewayException("You don't have enough money on your balance");
     }
     $template = $this->format;
     $template = str_replace('{name}', $this->name, $template);
     $template = str_replace('{phone}', $number->getNumber(), $template);
     $template = str_replace('{schedule}', $schedule ? 'at ' . $schedule->format(\DateTime::ISO8601) : 'immediately', $template);
     // message may contain any data, even template placeholders, so process it aat last
     $template = str_replace('{message}', $message->getText(), $template);
     echo $template;
     $this->balance -= $this->price;
     return $this->price;
 }
コード例 #4
0
ファイル: A1SystemsRu.php プロジェクト: pinepain/sms-krank
 /**
  * @param PhoneNumber $number
  * @param Message     $message
  * @param \DateTime   $schedule
  *
  * @throws \SMSKrank\Exceptions\GatewayException
  *
  * @return float | null Message fee, if available. Null otherwise
  */
 public function send(PhoneNumber $number, Message $message, \DateTime $schedule = null)
 {
     $args = array('operation' => 'send', 'login' => $this->login, 'password' => $this->password, 'msisdn' => $number->getNumber(), 'shortcode' => $this->sender, 'text' => $message->getText());
     $url = 'http://http.a1smsmarket.ru:8000/send?' . http_build_query($args);
     $res = file_get_contents($url);
     if (strpos($res, ':')) {
         list(, $error) = explode(':', $res);
         throw new GatewayException(trim($error));
     }
     $id = (int) $res;
     // retrieve message id
     if ($id < 1) {
         throw new GatewayException('Bad response');
     }
     return null;
 }
コード例 #5
0
ファイル: SmsUslugiRu.php プロジェクト: pinepain/sms-krank
 public function send(PhoneNumber $number, Message $message, \DateTime $schedule = null)
 {
     $args = array('login' => $this->login, 'password' => $this->password, 'txt' => $message->getText(), 'to' => $number->getNumber(), 'onlydelivery' => 1);
     if ($schedule) {
         // NOTE: this gate traits date timezone as your location provided in cabinet
         $args['dateTimeSend'] = $schedule->format("Y-m-d H:i:s");
     }
     // response as JSON (no respect to HTTP status code, btw, very nice. curl is useless here)
     // https://lcab.sms-uslugi.ru/lcabApi/sendSms.php
     $res = file_get_contents("https://lcab.sms-uslugi.ru/lcabApi/sendSms.php?" . http_build_query($args));
     $json = json_decode($res, true);
     if (!is_array($json) || !isset($json['code'])) {
         throw new GatewayException('Bad response');
     }
     // TODO: return message(s) cost
     return $json['code'] == 1;
 }
コード例 #6
0
ファイル: ToFile.php プロジェクト: pinepain/sms-krank
 public function send(PhoneNumber $number, Message $message, \DateTime $schedule = null)
 {
     if ($this->file_name == '/dev/null') {
         // add null device support for non-*NIX users
         return null;
     }
     $template = $this->format;
     $schedule = $schedule ? 'at ' . $schedule->format(\DateTime::ISO8601) : 'immediately';
     $now = new \DateTime();
     $template = str_replace('{datetime}', $now->format(\DateTime::ISO8601), $template);
     $template = str_replace('{phone}', $number->getNumber(), $template);
     $template = str_replace('{schedule}', $schedule, $template);
     // message may contain any data, even template placeholders, so process it aat last
     $template = str_replace('{message}', $message->getText(), $template);
     $fh = fopen($this->file_name, 'w+');
     if (!$fh) {
         throw new GatewayException("Failed to open file '{$this->file_name}'");
     }
     fwrite($fh, $template . PHP_EOL);
     fclose($fh);
     return null;
 }
コード例 #7
0
ファイル: MessageTest.php プロジェクト: pinepain/sms-krank
 /**
  * @covers \SMSKrank\Message::options
  */
 public function testOptions()
 {
     $obj = new Message('');
     $this->assertInstanceOf('SMSKrank\\Utils\\Options', $obj->options());
 }