Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smsManager
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cristian Mauricio Diaz Canales
smsManager
Commits
504f619e
Commit
504f619e
authored
Jul 17, 2019
by
Cristian Mauricio Diaz Canales
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prueba
parent
866cbbdf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
74 deletions
+68
-74
src/BackendBundle/Controller/EnvioSmsController.php
src/BackendBundle/Controller/EnvioSmsController.php
+68
-74
No files found.
src/BackendBundle/Controller/EnvioSmsController.php
View file @
504f619e
...
...
@@ -6,35 +6,31 @@ use FOS\RestBundle\Controller\FOSRestController;
use
AppBundle\Lib\Utiles
;
use
Symfony\Component\HttpFoundation\Response
;
use
Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
//use Symfony\Component\Routing\Annotation\Route;
use
AppBundle\Model\NotificaQuery
;
use
AppBundle\Model\Notifica
;
use
AppBundle\Model\RespuestasSmsQuery
;
use
AppBundle\Model\RespuestasSms
;
require_once
__DIR__
.
'/../../../vendor/autoload.php'
;
use
FOS\RestBundle\View\View
;
//use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
class
EnvioSmsController
extends
FOSRestController
{
//* @Route("/enviar")
public
function
indexAction
(
$id
)
{
$view
=
View
::
create
();
$view
->
setData
(
array
(
"id"
=>
$id
,
"nombre"
=>
"Usuario no autorizado"
));
return
$this
->
handleView
(
$view
);
}
// * @Route("/enviar")
// * @Method({"POST"})
public
function
enviarSmsAction
()
{
//print_r('Enviando mensaje');
$campana
=
$_POST
[
'campana'
];
...
...
@@ -54,7 +50,7 @@ class EnvioSmsController extends FOSRestController {
$url
=
""
;
if
(
$idmetodo
==
1
)
{
//nrsgateway
// $log->debug('mensajeee: ' . $mensaje);
// $log->debug('mensajeee: ' . $mensaje);
$log
->
debug
(
'Selecciona nrsgateway'
);
$usuario
=
Utiles
::
getParametroConfiguracion
(
'nrsgateway_user'
);
$password
=
Utiles
::
getParametroConfiguracion
(
'nrsgateway_pws'
);
...
...
@@ -63,7 +59,6 @@ class EnvioSmsController extends FOSRestController {
return
$this
->
enviarMensaje
(
$campana
,
$telefono
,
$mensaje
,
$usuario
,
$password
,
$url
,
$from
,
$idmetodo
);
}
else
{
//teltech
if
(
$idmetodo
==
2
)
{
$log
->
debug
(
'Selecciona Teltech'
);
...
...
@@ -72,79 +67,80 @@ class EnvioSmsController extends FOSRestController {
$url
=
Utiles
::
getParametroConfiguracion
(
'teltech_url'
);
return
$this
->
enviarMensaje
(
$campana
,
$telefono
,
$mensaje
,
$usuario
,
$password
,
$url
,
$from
,
$idmetodo
);
}
else
{
//Amazon
$log
->
debug
(
'Selecciona Amazon'
);
$log
->
debug
(
'Selecciona Amazon'
);
return
$this
->
enviarMensajeAmazon
(
$telefono
,
$mensaje
,
$from
,
$idmetodo
);
}
}
}
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
=
""
;
$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'
];
$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
=
""
;
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;
}
// return $resp;
}
$log
->
debug
(
'Grabar en respuestaSms'
);
}
$log
->
debug
(
'Grabar en respuestaSms'
);
try
{
$respuestaSms
=
new
RespuestasSms
();
$respuestaSms
->
setResCampana
(
$campana
);
$respuestaSms
->
setResProveedorSms
(
$proveedor
);
...
...
@@ -156,8 +152,7 @@ class EnvioSmsController extends FOSRestController {
return
$resp
;
}
catch
(
\Exception
$e
)
{
$log
=
Utiles
::
setLog
(
'exception'
);
$log
->
debug
(
'exception: '
.
$e
);
$log
->
debug
(
'exception: '
.
print_r
(
$e
,
true
));
}
}
...
...
@@ -181,10 +176,9 @@ class EnvioSmsController extends FOSRestController {
return
$messageId
;
}
// * @Route("/buscarstatus")
// * @Method({"POST"})
public
function
buscarStatusAction
()
{
// * @Method({"POST"})
public
function
buscarStatusAction
()
{
$time
=
intVal
(
strVal
(
time
()
-
3600
+
6
)
.
"000"
);
$messageId
=
$_POST
[
'messageid'
];
...
...
@@ -218,9 +212,9 @@ class EnvioSmsController extends FOSRestController {
if
(
$result
[
'events'
])
{
$status
=
json_decode
(
$result
[
'events'
][
0
][
'message'
],
true
);
$telefono
=
$status
[
'delivery'
][
'destination'
];
$estado
=
$status
[
'status'
];
$telefono
=
$status
[
'delivery'
][
'destination'
];
$estado
=
$status
[
'status'
];
$notifica
=
new
Notifica
();
$notifica
->
setCampana
(
$messageId
);
...
...
@@ -228,7 +222,7 @@ class EnvioSmsController extends FOSRestController {
$notifica
->
setEstado
(
$estado
);
$notifica
->
setIdMetodo
(
3
);
$notifica
->
save
();
return
$result
;
}
else
{
$result
=
$cloud2
->
filterLogEvents
([
...
...
@@ -241,8 +235,8 @@ class EnvioSmsController extends FOSRestController {
$telefono
=
''
;
if
(
$result
[
'events'
])
{
$status
=
json_decode
(
$result
[
'events'
][
0
][
'message'
],
true
);
$telefono
=
$status
[
'delivery'
][
'destination'
];
$estado
=
$status
[
'status'
];
$telefono
=
$status
[
'delivery'
][
'destination'
];
$estado
=
$status
[
'status'
];
$notifica
=
new
Notifica
();
...
...
@@ -263,9 +257,8 @@ class EnvioSmsController extends FOSRestController {
}
}
// * @Route("/notifica/{idenvio}/{tel}/{estado}")
// * @Route("/notifica/{idenvio}/{tel}/{estado}")
public
function
notificaAction
(
$idenvio
,
$tel
,
$estado
)
{
$notifica
=
new
Notifica
();
$notifica
->
setCampana
(
$idenvio
);
...
...
@@ -274,4 +267,5 @@ class EnvioSmsController extends FOSRestController {
$notifica
->
save
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment