Commit 018b960c authored by Ana's avatar Ana

cambios

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