Commit 1c5414f9 authored by Ana's avatar Ana

cambgios

parents ba88a816 22830ccf
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<type>org.netbeans.modules.php.project</type> <type>org.netbeans.modules.php.project</type>
<configuration> <configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1"> <data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>intelsecuritymovistar</name> <name>smsmanager</name>
</data> </data>
</configuration> </configuration>
</project> </project>
...@@ -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,50 +67,75 @@ class EnvioSmsController extends FOSRestController { ...@@ -72,50 +67,75 @@ 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";
$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); $log = Utiles::setLog('BackendBundle', 'backend/backend');
$array = json_decode($result, true); $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)
));
$result = curl_exec($ch);
// $log->debug(print_r($result,true));
$array = json_decode($result, true);
$resp = "";
$estado = "";
if (isset($array['error']['code'])) {
$log->debug('Api Devuelve error');
$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']
); );
<<<<<<< HEAD
//return $resp; //return $resp;
} else { } else {
$log->debug('Api envio exitoso'); $log->debug('Api envio exitoso');
...@@ -141,26 +161,27 @@ class EnvioSmsController extends FOSRestController { ...@@ -141,26 +161,27 @@ class EnvioSmsController extends FOSRestController {
); );
// return $resp; // return $resp;
} }
=======
// return $resp;
>>>>>>> 22830ccf3f37fe0ceed3609fae2da773696ebb89
} }
try {
$log->debug('Grabar en respuestaSms');
$respuestaSms = new RespuestasSms();
$respuestaSms->setResCampana($campana);
$respuestaSms->setResProveedorSms($proveedor);
$respuestaSms->setResEmisor($from);
$respuestaSms->setResMovil($movil);
$respuestaSms->setResMensaje($mensaje);
$respuestaSms->setResHttpCodeRespuestaPeticion($estado);
$respuestaSms->save();
} catch (PropelException $pe) {
$log = Utiles::setLog('exception');
$log->debug('Propelexception: ' . $pe->getMessage());
}
return $resp;
} catch (\Exception $e) {
$log = Utiles::setLog('exception');
$log->debug('exception: ' . $e);
} }
try {
$log->debug('Grabar en respuestaSms');
$respuestaSms = new RespuestasSms();
$respuestaSms->setResCampana($campana);
$respuestaSms->setResProveedorSms($proveedor);
$respuestaSms->setResEmisor($from);
$respuestaSms->setResMovil($movil);
$respuestaSms->setResMensaje($mensaje);
$respuestaSms->setResHttpCodeRespuestaPeticion($estado);
$respuestaSms->save();
} catch (PropelException $pe) {
//$log = Utiles::setLog('exception');
$log->debug('Propelexception: ' . $pe->getMessage());
}
return $resp;
} }
private function enviarMensajeAmazon($telefono, $mensaje, $from, $proveedor) { private function enviarMensajeAmazon($telefono, $mensaje, $from, $proveedor) {
...@@ -183,10 +204,9 @@ class EnvioSmsController extends FOSRestController { ...@@ -183,10 +204,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'];
...@@ -220,9 +240,9 @@ class EnvioSmsController extends FOSRestController { ...@@ -220,9 +240,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);
...@@ -230,7 +250,7 @@ class EnvioSmsController extends FOSRestController { ...@@ -230,7 +250,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([
...@@ -243,8 +263,8 @@ class EnvioSmsController extends FOSRestController { ...@@ -243,8 +263,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();
...@@ -264,9 +284,8 @@ class EnvioSmsController extends FOSRestController { ...@@ -264,9 +284,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);
...@@ -275,4 +294,5 @@ class EnvioSmsController extends FOSRestController { ...@@ -275,4 +294,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