prueba

parent 866cbbdf
...@@ -6,35 +6,31 @@ use FOS\RestBundle\Controller\FOSRestController; ...@@ -6,35 +6,31 @@ use FOS\RestBundle\Controller\FOSRestController;
use AppBundle\Lib\Utiles; use AppBundle\Lib\Utiles;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
//use Symfony\Component\Routing\Annotation\Route; //use Symfony\Component\Routing\Annotation\Route;
use AppBundle\Model\NotificaQuery; use AppBundle\Model\NotificaQuery;
use AppBundle\Model\Notifica; use AppBundle\Model\Notifica;
use AppBundle\Model\RespuestasSmsQuery; use AppBundle\Model\RespuestasSmsQuery;
use AppBundle\Model\RespuestasSms; use AppBundle\Model\RespuestasSms;
require_once __DIR__ . '/../../../vendor/autoload.php'; require_once __DIR__ . '/../../../vendor/autoload.php';
use FOS\RestBundle\View\View; use FOS\RestBundle\View\View;
//use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; //use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
class EnvioSmsController extends FOSRestController { class EnvioSmsController extends FOSRestController {
//* @Route("/enviar") //* @Route("/enviar")
public function indexAction($id) { public function indexAction($id) {
$view = View::create(); $view = View::create();
$view->setData(array("id" => $id, "nombre" => "Usuario no autorizado")); $view->setData(array("id" => $id, "nombre" => "Usuario no autorizado"));
return $this->handleView($view); return $this->handleView($view);
} }
// * @Route("/enviar") // * @Route("/enviar")
// * @Method({"POST"}) // * @Method({"POST"})
public function enviarSmsAction() { public function enviarSmsAction() {
//print_r('Enviando mensaje'); //print_r('Enviando mensaje');
$campana = $_POST['campana']; $campana = $_POST['campana'];
...@@ -54,7 +50,7 @@ class EnvioSmsController extends FOSRestController { ...@@ -54,7 +50,7 @@ class EnvioSmsController extends FOSRestController {
$url = ""; $url = "";
if ($idmetodo == 1) { //nrsgateway if ($idmetodo == 1) { //nrsgateway
// $log->debug('mensajeee: ' . $mensaje); // $log->debug('mensajeee: ' . $mensaje);
$log->debug('Selecciona nrsgateway'); $log->debug('Selecciona nrsgateway');
$usuario = Utiles::getParametroConfiguracion('nrsgateway_user'); $usuario = Utiles::getParametroConfiguracion('nrsgateway_user');
$password = Utiles::getParametroConfiguracion('nrsgateway_pws'); $password = Utiles::getParametroConfiguracion('nrsgateway_pws');
...@@ -63,7 +59,6 @@ class EnvioSmsController extends FOSRestController { ...@@ -63,7 +59,6 @@ class EnvioSmsController extends FOSRestController {
return $this->enviarMensaje($campana, $telefono, $mensaje, $usuario, $password, $url, $from, $idmetodo); return $this->enviarMensaje($campana, $telefono, $mensaje, $usuario, $password, $url, $from, $idmetodo);
} else { //teltech } else { //teltech
if ($idmetodo == 2) { if ($idmetodo == 2) {
$log->debug('Selecciona Teltech'); $log->debug('Selecciona Teltech');
...@@ -72,79 +67,80 @@ class EnvioSmsController extends FOSRestController { ...@@ -72,79 +67,80 @@ class EnvioSmsController extends FOSRestController {
$url = Utiles::getParametroConfiguracion('teltech_url'); $url = Utiles::getParametroConfiguracion('teltech_url');
return $this->enviarMensaje($campana, $telefono, $mensaje, $usuario, $password, $url, $from, $idmetodo); return $this->enviarMensaje($campana, $telefono, $mensaje, $usuario, $password, $url, $from, $idmetodo);
} else { //Amazon } else { //Amazon
$log->debug('Selecciona Amazon'); $log->debug('Selecciona Amazon');
return $this->enviarMensajeAmazon($telefono, $mensaje, $from, $idmetodo); return $this->enviarMensajeAmazon($telefono, $mensaje, $from, $idmetodo);
} }
} }
} }
private function enviarMensaje($campana, $movil, $mensaje, $usuario, $password, $url, $from, $proveedor) { private function enviarMensaje($campana, $movil, $mensaje, $usuario, $password, $url, $from, $proveedor) {
try {
$log = Utiles::setLog('BackendBundle', 'backend/backend');
$post['to'] = array($movil);
$post['text'] = $mensaje;
$post['from'] = $from;
$post['dlr-url'] = Utiles::getParametroConfiguracion("url_sms") . "/api/notifica/" . $campana . "/%P/%d"; $log = Utiles::setLog('BackendBundle', 'backend/backend');
$post['to'] = array($movil);
$post['text'] = $mensaje;
$post['from'] = $from;
$post['dlr-url'] = Utiles::getParametroConfiguracion("url_sms") . "/api/notifica/" . $campana . "/%P/%d";
$user = $usuario;
$password = $password;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Basic " . base64_encode($user . ":" . $password)
));
$user = $usuario;
$password = $password;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Basic " . base64_encode($user . ":" . $password)
));
$result = curl_exec($ch);
$array = json_decode($result, true);
$result = curl_exec($ch); $resp = "";
$estado = "";
if (isset($array['error']['code'])) {
$log->debug('Api Devuelve error');
$array = json_decode($result, true); $estado = $array['error']['code'];
$resp = array(
'success' => false,
'statusCode' => $array['error']['code']
);
//return $resp;
} else {
$log->debug('Api envio exitoso');
$notifica = NotificaQuery::create()->filterByCampana($campana)->filterByTelefono($movil)->find();
$resp = ""; $resp = "";
$estado = "";
if (isset($array['error']['code'])) {
$log->debug('Api Devuelve error');
if (count($notifica) > 0) {
foreach ($notifica as $noti) {
$estado = $noti->getEstado();
}
$resp = array(
'success' => true,
'statusCode' => $estado
);
// return $resp;
} else {
$estado = $array['error']['code']; $estado = $array['error']['code'];
$resp = array( $resp = array(
'success' => false, 'success' => false,
'statusCode' => $array['error']['code'] 'statusCode' => $array['error']['code']
); );
//return $resp; // return $resp;
} else {
$log->debug('Api envio exitoso');
$notifica = NotificaQuery::create()->filterByCampana($campana)->filterByTelefono($movil)->find();
$resp = "";
if (count($notifica) > 0) {
foreach ($notifica as $noti) {
$estado = $noti->getEstado();
}
$resp = array(
'success' => true,
'statusCode' => $estado
);
// return $resp;
} else {
$estado = $array['error']['code'];
$resp = array(
'success' => false,
'statusCode' => $array['error']['code']
);
// return $resp;
}
} }
$log->debug('Grabar en respuestaSms'); }
$log->debug('Grabar en respuestaSms');
try {
$respuestaSms = new RespuestasSms(); $respuestaSms = new RespuestasSms();
$respuestaSms->setResCampana($campana); $respuestaSms->setResCampana($campana);
$respuestaSms->setResProveedorSms($proveedor); $respuestaSms->setResProveedorSms($proveedor);
...@@ -156,8 +152,7 @@ class EnvioSmsController extends FOSRestController { ...@@ -156,8 +152,7 @@ class EnvioSmsController extends FOSRestController {
return $resp; return $resp;
} catch (\Exception $e) { } catch (\Exception $e) {
$log = Utiles::setLog('exception'); $log->debug('exception: ' . print_r($e, true));
$log->debug('exception: ' . $e);
} }
} }
...@@ -181,10 +176,9 @@ class EnvioSmsController extends FOSRestController { ...@@ -181,10 +176,9 @@ class EnvioSmsController extends FOSRestController {
return $messageId; return $messageId;
} }
// * @Route("/buscarstatus") // * @Route("/buscarstatus")
// * @Method({"POST"}) // * @Method({"POST"})
public function buscarStatusAction() { public function buscarStatusAction() {
$time = intVal(strVal(time() - 3600 + 6) . "000"); $time = intVal(strVal(time() - 3600 + 6) . "000");
$messageId = $_POST['messageid']; $messageId = $_POST['messageid'];
...@@ -218,9 +212,9 @@ class EnvioSmsController extends FOSRestController { ...@@ -218,9 +212,9 @@ class EnvioSmsController extends FOSRestController {
if ($result['events']) { if ($result['events']) {
$status = json_decode($result['events'][0]['message'], true); $status = json_decode($result['events'][0]['message'], true);
$telefono= $status['delivery']['destination']; $telefono = $status['delivery']['destination'];
$estado= $status['status']; $estado = $status['status'];
$notifica = new Notifica(); $notifica = new Notifica();
$notifica->setCampana($messageId); $notifica->setCampana($messageId);
...@@ -228,7 +222,7 @@ class EnvioSmsController extends FOSRestController { ...@@ -228,7 +222,7 @@ class EnvioSmsController extends FOSRestController {
$notifica->setEstado($estado); $notifica->setEstado($estado);
$notifica->setIdMetodo(3); $notifica->setIdMetodo(3);
$notifica->save(); $notifica->save();
return $result; return $result;
} else { } else {
$result = $cloud2->filterLogEvents([ $result = $cloud2->filterLogEvents([
...@@ -241,8 +235,8 @@ class EnvioSmsController extends FOSRestController { ...@@ -241,8 +235,8 @@ class EnvioSmsController extends FOSRestController {
$telefono = ''; $telefono = '';
if ($result['events']) { if ($result['events']) {
$status = json_decode($result['events'][0]['message'], true); $status = json_decode($result['events'][0]['message'], true);
$telefono= $status['delivery']['destination']; $telefono = $status['delivery']['destination'];
$estado= $status['status']; $estado = $status['status'];
$notifica = new Notifica(); $notifica = new Notifica();
...@@ -263,9 +257,8 @@ class EnvioSmsController extends FOSRestController { ...@@ -263,9 +257,8 @@ class EnvioSmsController extends FOSRestController {
} }
} }
// * @Route("/notifica/{idenvio}/{tel}/{estado}")
// * @Route("/notifica/{idenvio}/{tel}/{estado}")
public function notificaAction($idenvio, $tel, $estado) { public function notificaAction($idenvio, $tel, $estado) {
$notifica = new Notifica(); $notifica = new Notifica();
$notifica->setCampana($idenvio); $notifica->setCampana($idenvio);
...@@ -274,4 +267,5 @@ class EnvioSmsController extends FOSRestController { ...@@ -274,4 +267,5 @@ class EnvioSmsController extends FOSRestController {
$notifica->save(); $notifica->save();
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment