Skip to content

Instantly share code, notes, and snippets.

@jatovar
Last active February 19, 2018 19:24
Show Gist options
  • Save jatovar/113631e806a1c300ce48419e3a58e33b to your computer and use it in GitHub Desktop.
Save jatovar/113631e806a1c300ce48419e3a58e33b to your computer and use it in GitHub Desktop.
PUSH_NOTIFICATION.sql
create or replace PACKAGE BODY PR_NOTIFICACIONES_PUSH AS
procedure PUSH_NOTIFICATION
(
sDeviceId varchar2,
sDevicePlatform varchar2,
sName varchar2,
sTitle varchar2,
sBody varchar2
) is
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := CASE WHEN (sDevicePlatform = 'iOS') THEN 'http://192.0.1.53/API/PushNotifications/SendAppMoviliOS' ELSE 'http://192.0.1.53/API/PushNotifications/SendAppMovilAndroid' END;
name varchar2(4000);
buffer varchar2(4000);
--content varchar2(4000) := '{"Title":"'||sTitle||'","Body":"'||sBody||'","devices":["'||sDeviceId||'"]}';
content varchar2(4000) := '{"Campaign":"'|| sName ||'","Title":"'||sTitle||'","Body":"'||sBody||'","Target":{"type":"devices_target","devices":["'||sDeviceId||'"]}}';
begin
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'content-type', 'application/json');
utl_http.set_header(req, 'Content-Length', length(content));
-- UTL_HTTP.SET_BODY_CHARSET(request,'UTF-8');
utl_http.write_text(req, content);
DBMS_OUTPUT.PUT_LINE(content);
res := utl_http.get_response(req);
-- process the response from the HTTP c
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffer);
end loop;
utl_http.end_response(res);
exception
when utl_http.end_of_body
then
utl_http.end_response(res);
end;
end PUSH_NOTIFICATION;
/*
PROCEDURE ENVIA_NOTIFICACIONES_PAGO IS
BEGIN
FOR c IN (SELECT field1, field2 FROM mytable) LOOP
my_proc(c.field1, c.field2);
END LOOP;
SELECT PR_NOTIFICACIONES_PUSH.PUSH_NOTIFICATION('hola', 'hola', 'hola','HOLA')
FROM MOVIL_FACTURAS_PENDIENTES mfp
inner join MOVIL_USUARIO mu on mfp.IDUSMOVIL = mu.IDUSMOVIL
inner join MOVIL_PUSHCONFIG mpc ON mfp.DIAS = mpc.DIAS
where mu.DEVICEID is not null
and mu.DEVICEPLATFORM is not null;
END ENVIA_NOTIFICACIONES_PAGO;
*/
PROCEDURE ENVIA_NOTIFICACIONES_PAGO IS
guid varchar2(300) := 'Notificaciones de pago. Fecha: '|| sysdate;
BEGIN
FOR c IN (
SELECT mu.IDUSMOVIL idusumovil, mu.deviceid deviceid,mu.deviceplatform deviceplatform,'Notificacion de pago' title, 'Estimado cliente le recordamos que su poliza ' || mfp.POLIZA || ' tiene un pago por vencer, la fecha limite de pago es el dia ' || mfp.fecvenc mensaje
FROM MOVIL_FACTURAS_PENDIENTES mfp
inner join MOVIL_USUARIO mu on mfp.IDUSMOVIL = mu.IDUSMOVIL
inner join MOVIL_PUSHCONFIG mpc ON mfp.DIAS = mpc.DIAS
where mu.DEVICEID is not null
and mu.DEVICEPLATFORM is not null
) LOOP
PUSH_NOTIFICATION(c.deviceid, c.deviceplatform, guid, c.title,c.mensaje);
insert into acselsep.movil_notificacion (id_usuario, mensaje)
values (c.idusumovil, c.mensaje);
END LOOP;
END ENVIA_NOTIFICACIONES_PAGO;
END;
create or replace PACKAGE BODY PR_NOTIFICACIONES_PUSH AS
procedure PUSH_NOTIFICATION
(
sDeviceId varchar2,
sDevicePlatform varchar2,
sName varchar2,
sTitle varchar2,
sBody varchar2
) is
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := CASE WHEN (sDevicePlatform = 'iOS') THEN 'http://192.0.1.53/API/PushNotifications/SendAppMoviliOS' ELSE 'http://192.0.1.53/API/PushNotifications/SendAppMovilAndroid' END;
name varchar2(4000);
buffer varchar2(4000);
--content varchar2(4000) := '{"Title":"'||sTitle||'","Body":"'||sBody||'","devices":["'||sDeviceId||'"]}';
content varchar2(4000) := '{"Campaign":"'|| sName ||'","Title":"'||sTitle||'","Body":"'||sBody||'","Target":{"type":"devices_target","devices":["'||sDeviceId||'"]}}';
begin
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'content-type', 'application/json');
utl_http.set_header(req, 'Content-Length', length(content));
-- UTL_HTTP.SET_BODY_CHARSET(request,'UTF-8');
utl_http.write_text(req, content);
DBMS_OUTPUT.PUT_LINE(content);
res := utl_http.get_response(req);
-- process the response from the HTTP c
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffer);
end loop;
utl_http.end_response(res);
exception
when utl_http.end_of_body
then
utl_http.end_response(res);
end;
end PUSH_NOTIFICATION;
/*
PROCEDURE ENVIA_NOTIFICACIONES_PAGO IS
BEGIN
FOR c IN (SELECT field1, field2 FROM mytable) LOOP
my_proc(c.field1, c.field2);
END LOOP;
SELECT PR_NOTIFICACIONES_PUSH.PUSH_NOTIFICATION('hola', 'hola', 'hola','HOLA')
FROM MOVIL_FACTURAS_PENDIENTES mfp
inner join MOVIL_USUARIO mu on mfp.IDUSMOVIL = mu.IDUSMOVIL
inner join MOVIL_PUSHCONFIG mpc ON mfp.DIAS = mpc.DIAS
where mu.DEVICEID is not null
and mu.DEVICEPLATFORM is not null;
END ENVIA_NOTIFICACIONES_PAGO;
*/
PROCEDURE ENVIA_NOTIFICACIONES_PAGO IS
guid varchar2(300) := 'Notificaciones de pago. Fecha: '|| sysdate;
BEGIN
FOR c IN (
SELECT mu.IDUSMOVIL idusumovil, mu.deviceid deviceid,mu.deviceplatform deviceplatform,'Notificacion de pago' title, 'Estimado cliente le recordamos que su poliza ' || mfp.POLIZA || ' tiene un pago por vencer, la fecha limite de pago es el dia ' || mfp.fecvenc mensaje
FROM MOVIL_FACTURAS_PENDIENTES mfp
inner join MOVIL_USUARIO mu on mfp.IDUSMOVIL = mu.IDUSMOVIL
inner join MOVIL_PUSHCONFIG mpc ON mfp.DIAS = mpc.DIAS
where mu.DEVICEID is not null
and mu.DEVICEPLATFORM is not null
) LOOP
PUSH_NOTIFICATION(c.deviceid, c.deviceplatform, guid, c.title,c.mensaje);
insert into acselsep.movil_notificacion (id_usuario, mensaje)
values (c.idusumovil, c.mensaje);
END LOOP;
END ENVIA_NOTIFICACIONES_PAGO;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment