Commit 018b960c authored by Ana's avatar Ana

cambios

parent 9970e4c2
...@@ -159,12 +159,14 @@ class EnvioSmsController extends FOSRestController { ...@@ -159,12 +159,14 @@ class EnvioSmsController extends FOSRestController {
} }
private function enviarMensajeAmazon($telefono, $mensaje, $from, $proveedor) { private function enviarMensajeAmazon($telefono, $mensaje, $from, $proveedor) {
$log = Utiles::setLog('BackendBundle', 'backend/backend');
$sdk = new \Aws\Sns\SnsClient([ $sdk = new \Aws\Sns\SnsClient([
'region' => Utiles::getParametroConfiguracion('region'), 'region' => Utiles::getParametroConfiguracion('region'),
'version' => Utiles::getParametroConfiguracion('version'), 'version' => Utiles::getParametroConfiguracion('version'),
'credentials' => ['key' => Utiles::getParametroConfiguracion('amazonkey'), 'secret' => Utiles::getParametroConfiguracion('amazonsecret') 'credentials' => ['key' => Utiles::getParametroConfiguracion('amazonkey'), 'secret' => Utiles::getParametroConfiguracion('amazonsecret')
]]); ]]);
try {
$result = $sdk->publish([ $result = $sdk->publish([
'Message' => $mensaje, 'Message' => $mensaje,
'PhoneNumber' => $telefono, 'PhoneNumber' => $telefono,
...@@ -173,17 +175,32 @@ class EnvioSmsController extends FOSRestController { ...@@ -173,17 +175,32 @@ class EnvioSmsController extends FOSRestController {
'StringValue' => $from 'StringValue' => $from
] ]
]]); ]]);
} catch (Exception $e) {
$log->debug('Amazon Exception: ' . $e->getMessage());
}
$messageId = $result['MessageId']; $messageId = $result['MessageId'];
return $messageId;
$resp = array(
'success' => true,
'statusCode' => $messageId
);
return $resp;
} }
// * @Route("/buscarstatus") // * @Route("/buscarstatus")
// * @Method({"POST"}) // * @Method({"POST"})
public function buscarStatusAction() { public function buscarStatusAction() {
$time = intVal(strVal(time() - 3600 + 6) . "000"); $fecha=getdate();
$time = $fecha[0] - 20600;
$time = strVal($time) . "000";
$messageId = $_POST['messageid']; $messageId = $_POST['messageid'];
$log = Utiles::setLog('BackendBundle', 'backend/backend');
$log->debug("messageID:" . $messageId);
$cloud = new \Aws\CloudWatchLogs\CloudWatchLogsClient([ $cloud = new \Aws\CloudWatchLogs\CloudWatchLogsClient([
'region' => Utiles::getParametroConfiguracion('region'), 'region' => Utiles::getParametroConfiguracion('region'),
'version' => Utiles::getParametroConfiguracion('version'), 'version' => Utiles::getParametroConfiguracion('version'),
...@@ -206,7 +223,7 @@ class EnvioSmsController extends FOSRestController { ...@@ -206,7 +223,7 @@ class EnvioSmsController extends FOSRestController {
$result = $cloud2->filterLogEvents([ $result = $cloud2->filterLogEvents([
'filterPattern' => '{ $.notification.messageId = ' . $val . ' }', 'filterPattern' => '{ $.notification.messageId = ' . $val . ' }',
'logGroupName' => $g[0]['logGroupName'], // REQUIRED 'logGroupName' => $g[0]['logGroupName'], // REQUIRED
'startTime' => $time, 'startTime' => doubleVal($time),
]); ]);
$estado = ''; $estado = '';
...@@ -216,8 +233,7 @@ class EnvioSmsController extends FOSRestController { ...@@ -216,8 +233,7 @@ class EnvioSmsController extends FOSRestController {
$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);
$notifica->setTelefono($telefono); $notifica->setTelefono($telefono);
...@@ -225,32 +241,42 @@ class EnvioSmsController extends FOSRestController { ...@@ -225,32 +241,42 @@ class EnvioSmsController extends FOSRestController {
$notifica->setIdMetodo(3); $notifica->setIdMetodo(3);
$notifica->save(); $notifica->save();
return $result; $resp = array(
'success' => true,
'statusCode' => $estado
);
return $resp;
} else { } else {
$result = $cloud2->filterLogEvents([ $result = $cloud2->filterLogEvents([
'filterPattern' => '{ $.notification.messageId = ' . $val . ' }', 'filterPattern' => '{ $.notification.messageId = ' . $val . ' }',
'logGroupName' => $g[1]['logGroupName'], // REQUIRED 'logGroupName' => $g[1]['logGroupName'], // REQUIRED
'startTime' => $time, 'startTime' => doubleVal($time),
]); ]);
$estado = ''; $estado = '';
$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();
$notifica->setCampana($messageId); $notifica->setCampana($messageId);
$notifica->setTelefono($telefono); $notifica->setTelefono($telefono);
$notifica->setEstado($estado); $notifica->setEstado($estado);
$notifica->setIdMetodo(3); $notifica->setIdMetodo(3);
$notifica->save(); $notifica->save();
return $result;
} else {
$resp = array( $resp = array(
'success' => true, 'success' => true,
'statusCode' => $estado
);
return $resp;
} else {
$resp = array(
'success' => false,
'statusCode' => '-1' 'statusCode' => '-1'
); );
return $resp; return $resp;
......
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