예제 #1
0
 /**
  *
  */
 public function sendSMS($msgId, $toNumber, $msg)
 {
     $message = new \HumanSimpleMessage();
     $message->setBody($msg);
     $message->setTo($toNumber);
     $message->setMsgId(sprintf('%04d', $msgId));
     #$message->setSchedule($schedule);
     $this->lastResponse = $this->zenvia->sendMessage($message, \HumanSimpleSend::CALLBACK_INACTIVE);
     return $this;
 }
예제 #2
0
 /**
  * @param string $body Texto da mensagem
  * @param string $to Destinatário da mensagem
  * @param string $msgId ID da mensagem
  * @param string $from Remetente da mensagem
  * @param string $schedule Agendamento da mensagem
  * @param string $callbackOption Callback da mensagem
  *
  * @return \HumanResponse
  */
 public function send($body, $to, $msgId = null, $from = null, $schedule = null, $callbackOption = null)
 {
     $message = new \HumanSimpleMessage();
     $message->setBody($body);
     $message->setTo($to);
     $message->setFrom($from ?: $this->_module->from);
     $message->setMsgId($msgId);
     $message->setSchedule($schedule);
     if ($this->_module->simulate === true) {
         $response = new \HumanResponse();
         $response->setCode('000');
         $response->setMessage('Simulado');
         Yii::trace(VarDumper::dumpAsString($message));
     } else {
         $response = $this->humanSimpleSend->sendMessage($message, $callbackOption ?: $this->_module->callBack);
     }
     return $response;
 }
 /**
  * Faz o envio da mensagem para o gateway através do método HTTP/POST .
  *
  * @param HumanSimpleMessage $message
  * @param integer $callbackOption (0, 1, 2)
  * @return HumanResponse
  */
 public function sendMessage($message, $callbackOption = self::CALLBACK_INACTIVE)
 {
     $params = array("dispatch" => "send", "account" => $this->getAccount(), "code" => $this->getPassword(), "callbackOption" => $callbackOption, "to" => $message->getTo(), "msg" => $message->getBody());
     if ($message->getFrom() != null && trim($message->getFrom()) != "") {
         $params["from"] = $message->getFrom();
     }
     if ($message->getMsgId() != null && trim($message->getMsgId()) != "") {
         $params["id"] = $message->getMsgId();
     }
     if ($message->getSchedule() != null && trim($message->getSchedule()) != "") {
         $params["schedule"] = $message->getSchedule();
     }
     $responses = $this->send($params);
     return $responses[0];
 }
<?php

ini_set('display_errors', "on");
//ini_set('error_reporting', E_ALL & ~E_NOTICE);
ini_set('error_reporting', E_ALL);
include_once 'human_gateway_client_api/HumanClientMain.php';
$account = "account";
$password = "******";
$body = "Este e um teste de envio de mensagem simples utilizando a plataforma Zenvia. " . date('d/m/Y H:i:s');
$to = "5500112233445";
$msgId = "0001";
$schedule = date("d/m/Y H:i:s", strtotime("+2 minutes"));
$callbackOption = HumanSimpleSend::CALLBACK_INACTIVE;
$sender = new HumanSimpleSend($account, $password);
$message = new HumanSimpleMessage();
$message->setBody($body);
$message->setTo($to);
$message->setMsgId($msgId);
#$message->setSchedule($schedule);
$response = $sender->sendMessage($message, $callbackOption);
echo $response->getCode() . " - " . $response->getMessage() . "<br />";