Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Luciano Barletta
/
message-service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 3a4472ff
authored
2020-08-09 13:05:14 -0300
by
Tu Nombre
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
prueba de sms
1 parent
1bcc9624
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
161 additions
and
22 deletions
SmsGateway24.py
SmsMasivoArgentina.py
Wpp1State.py
config.py
deploy.py
process.py
services.py
SmsGateway24.py
0 → 100644
View file @
3a4472f
import
requests
,
json
,
config
,
datetime
from
Wpp1State
import
AndroidStatus
device
=
"2183"
sim
=
"1"
def
enviarSMS
(
texto
,
destino
,
device
,
sim
,
token
):
ModeloURL
=
"""https://smsgateway24.com/getdata/addsms?token={}&device_id={}&sim={}&sendto={}&body={}"""
url
=
ModeloURL
.
format
(
token
,
device
,
sim
,
destino
,
texto
)
res
=
requests
.
get
(
url
,
timeout
=
3
)
return
(
res
.
json
())
def
EnviarSMS
(
status
,
texto
,
destino
,
device
,
sim
,
usuario
,
contrase
ñ
a
):
#print(status, texto, destino, device, sim, usuario, contraseña)
try
:
token
=
status
.
ObtenerToken
(
usuario
,
contrase
ñ
a
)
except
:
token
=
False
if
token
==
False
:
raise
NameError
(
"Login_not_sussesfull"
)
try
:
resultado
=
enviarSMS
(
texto
,
destino
,
device
,
sim
,
token
)
except
:
raise
NameError
(
"SMS_Server_Down"
)
if
not
resultado
[
"error"
]
==
0
:
print
(
resultado
)
raise
NameError
(
"SMS_No_ENVIADO"
)
#for tel in ["3412516354", "3416118184", "3416532428", "3415814145"]:
# print(EnviarSMS("Prueba de envio", tel, device, sim, Token))
SmsMasivoArgentina.py
0 → 100644
View file @
3a4472f
import
requests
,
json
,
config
ejemplo
=
"""http://servicio.smsmasivos.com.ar/enviar_sms.asp?api=1&usuario=DEMO500&clave=DEMO500&tos=1144445555&texto=Mensaje"""
ModeloURL
=
"""http://servicio.smsmasivos.com.ar/enviar_sms.asp?api=1&usuario={}&clave={}&tos={}&texto={}"""
def
EnviarSMS
(
usuario
,
clave
,
destinatario
,
texto
):
url
=
ModeloURL
.
format
(
usuario
,
clave
,
destinatario
,
texto
)
res
=
requests
.
get
(
url
,
timeout
=
3
)
#if res.text == "OK":
# return(True)
#else:
return
(
res
.
text
)
print
(
EnviarSMS
(
"SMSDEMOC98966"
,
"SMSDEMOC98966605"
,
"3412516354"
,
"Prueba de envio de mensaje"
))
\ No newline at end of file
\ No newline at end of file
Wpp1State.py
View file @
3a4472f
...
@@ -175,3 +175,71 @@ class StateMail():
...
@@ -175,3 +175,71 @@ class StateMail():
dg
.
starttls
()
dg
.
starttls
()
dg
.
login
(
User
,
Pass
)
dg
.
login
(
User
,
Pass
)
dg
.
quit
()
dg
.
quit
()
class
AndroidStatus
():
"""Esta clase manejara estados de la mensajeria de sms via android
con cache"""
def
__init__
(
self
):
self
.
ESTADOS
=
{}
self
.
TOKENs
=
{}
def
obtenerToken
(
self
,
email
,
clave
):
try
:
ModeloURL
=
"""https://smsgateway24.com/getdata/gettoken?email={}&pass={}"""
url
=
ModeloURL
.
format
(
email
,
clave
)
resp
=
requests
.
get
(
url
,
timeout
=
10
)
respuesta
=
resp
.
json
()
except
:
respuesta
=
{
"error"
:
1
}
return
(
respuesta
)
def
ObtenerToken
(
self
,
email
,
clave
):
np
=
"""{}-{}"""
.
format
(
email
,
clave
)
token
=
False
if
np
in
self
.
TOKENs
.
keys
():
if
self
.
TOKENs
[
np
][
"hora"
]
>
datetime
.
datetime
.
now
():
return
(
self
.
TOKENs
[
np
][
"token"
])
else
:
self
.
TOKENs
.
pop
(
np
,
None
)
Token
=
self
.
obtenerToken
(
email
,
clave
)
print
(
Token
)
if
not
Token
[
"error"
]
==
1
:
hora
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
seconds
=
3600
)
self
.
TOKENs
[
np
]
=
{
"hora"
:
hora
,
"token"
:
Token
[
"token"
]}
token
=
Token
[
"token"
]
return
(
token
)
def
EstadoDispositivo
(
self
,
email
,
clave
,
dispositivo
):
"""{'online': True, 'error': 0, 'message': 'OK', 'device_id': 2183,
'lastseen': {'date': '2020-08-04 23:15:29.000000', 'timezone_type': 3,
'timezone': 'UTC'}, 'diffseconds': 34, 'title': 'Redmi_Note_7'}"""
token
=
self
.
ObtenerToken
(
email
,
clave
)
Id
=
token
+
dispositivo
try
:
if
self
.
ESTADOS
[
Id
][
"hora"
]
>
datetime
.
datetime
.
now
():
return
(
self
.
ESTADOS
[
Id
][
"estado"
])
except
:
pass
estado
=
self
.
estadoDispositivo
(
token
,
dispositivo
)
if
estado
[
"online"
]
==
True
:
hora
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
seconds
=
60
)
self
.
ESTADOS
[
Id
]
=
{
"estado"
:
estado
,
"hora"
:
hora
}
return
(
estado
)
def
estadoDispositivo
(
self
,
token
,
dispositivo
):
respuesta
=
{
'online'
:
False
,
"error"
:
True
}
if
token
==
False
:
return
(
respuesta
)
URL
=
"""https://smsgateway24.com/getdata/getdevicestatus?token={}&device_id={}"""
url
=
URL
.
format
(
token
,
dispositivo
)
try
:
resp
=
requests
.
get
(
url
,
timeout
=
10
)
respuesta
=
resp
.
json
()
except
:
pass
return
(
respuesta
)
\ No newline at end of file
\ No newline at end of file
config.py
View file @
3a4472f
WS_URL
=
"https://www.waboxapp.com/api/send/"
WS_URL
=
"https://www.waboxapp.com/api/send/"
WS_Status
=
"
https://www.waboxapp.com/api/status/"
WS_Status
=
"https://www.waboxapp.com/api/status/"
WS_token
=
"fd378337aebead91c2eb25209aa51a7d5ce9754ea1718"
WS_token
=
"fd378337aebead91c2eb25209aa51a7d5ce9754ea1718"
WS_uid
=
"5493412641022"
WS_uid
=
"5493412641022"
FILE_server
=
"https://archivos.hgtsa.com.ar/"
FILE_server
=
"https://archivos.hgtsa.com.ar/"
...
...
deploy.py
View file @
3a4472f
...
@@ -4,13 +4,14 @@ from werkzeug.datastructures import FileStorage
...
@@ -4,13 +4,14 @@ from werkzeug.datastructures import FileStorage
from
process
import
Process
from
process
import
Process
from
python_arptable
import
get_arp_table
from
python_arptable
import
get_arp_table
from
enums
import
States
,
Table
from
enums
import
States
,
Table
from
Wpp1State
import
StatePhoneWs
,
StateMail
from
Wpp1State
import
StatePhoneWs
,
StateMail
,
AndroidStatus
import
os
,
ipdb
,
time
,
threading
,
random
,
datetime
,
config
import
os
,
ipdb
,
time
,
threading
,
random
,
datetime
,
config
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
TelState
=
StatePhoneWs
()
TelState
=
StatePhoneWs
()
MailState
=
StateMail
()
MailState
=
StateMail
()
SmsStatus
=
AndroidStatus
()
# carpeta de los mensajes
# carpeta de los mensajes
msgfolder
=
config
.
folder
#"msg/"
msgfolder
=
config
.
folder
#"msg/"
# id mínimo para una tabla
# id mínimo para una tabla
...
@@ -26,7 +27,7 @@ prefix_lenght = 16
...
@@ -26,7 +27,7 @@ prefix_lenght = 16
# tiempo límite que debe pasar para eliminar cosas
# tiempo límite que debe pasar para eliminar cosas
operation_timer
=
86400
operation_timer
=
86400
# conección a base de datos
# conección a base de datos
process
=
Process
(
config
.
db
,
TelState
,
MailState
)
process
=
Process
(
config
.
db
,
TelState
,
MailState
,
SmsStatus
)
#Cache de estado de telefonos
#Cache de estado de telefonos
...
@@ -42,21 +43,31 @@ def key():
...
@@ -42,21 +43,31 @@ def key():
f
.
close
()
f
.
close
()
return
key
return
key
@app.route
(
"/state/<tel>"
,
methods
=
[
'GET'
])
@app.route
(
"/state/<tel>"
,
methods
=
[
'GET'
,
'POST'
])
def
estadoWabox
(
tel
):
def
estadoWabox
(
tel
):
print
(
tel
)
if
tel
==
"default"
:
if
tel
==
"default"
:
xi
=
TelState
.
ChequearTelefono
(
config
.
WS_uid
)
xi
=
TelState
.
ChequearTelefono
(
config
.
WS_uid
)
else
:
else
:
xi
=
TelState
.
ChequearTelefono
(
tel
)
xi
=
TelState
.
ChequearTelefono
(
tel
)
return
(
xi
)
print
(
xi
)
return
(
jsonify
(
xi
))
@app.route
(
"/state/mail"
,
methods
=
[
'POST'
])
@app.route
(
"/state/mail"
,
methods
=
[
'
GET'
,
'
POST'
])
def
estadoMail
():
def
estadoMail
():
datos
=
request
.
json
datos
=
request
.
json
#
print(datos)
print
(
datos
)
test
=
MailState
.
ChequearMailServer
(
datos
[
"user"
],
datos
[
"pass"
],
int
(
datos
[
"port"
]),
datos
[
"host"
])
test
=
MailState
.
ChequearMailServer
(
datos
[
"user"
],
datos
[
"pass"
],
int
(
datos
[
"port"
]),
datos
[
"host"
])
return
(
str
(
test
))
return
(
str
(
test
))
@app.route
(
"/state/sms"
,
methods
=
[
'GET'
,
'POST'
])
def
estadoSMS
():
datos
=
request
.
json
#print(type(datos), datos)
test
=
SmsStatus
.
EstadoDispositivo
(
datos
[
"email"
],
datos
[
"pass"
],
str
(
datos
[
"device"
]))
print
(
test
)
return
(
jsonify
(
test
))
# Guarda archivos del emisor en una nueva carpeta (desencriptados)
# Guarda archivos del emisor en una nueva carpeta (desencriptados)
# Pide guardar en base de datos una preinstancia del mensaje
# Pide guardar en base de datos una preinstancia del mensaje
@app.route
(
'/data'
,
methods
=
[
'POST'
])
@app.route
(
'/data'
,
methods
=
[
'POST'
])
...
@@ -133,13 +144,13 @@ def cons():
...
@@ -133,13 +144,13 @@ def cons():
# Intenta enviar mensajes
# Intenta enviar mensajes
def
attempt
():
def
attempt
():
p
=
Process
(
config
.
db
,
TelState
,
MailState
)
p
=
Process
(
config
.
db
,
TelState
,
MailState
,
SmsStatus
)
p
.
send
()
p
.
send
()
threading
.
Timer
(
retry_timer
,
attempt
)
.
start
()
threading
.
Timer
(
retry_timer
,
attempt
)
.
start
()
# Limpia basura
# Limpia basura
def
clean
():
def
clean
():
p
=
Process
(
config
.
db
,
TelState
,
MailState
)
p
=
Process
(
config
.
db
,
TelState
,
MailState
,
SmsStatus
)
paths
=
p
.
paths
()
paths
=
p
.
paths
()
now
=
datetime
.
datetime
.
now
()
now
=
datetime
.
datetime
.
now
()
...
...
process.py
View file @
3a4472f
...
@@ -3,13 +3,15 @@ from database import DBconnection
...
@@ -3,13 +3,15 @@ from database import DBconnection
from
enums
import
Services
,
States
,
Datatypes
,
Table
from
enums
import
Services
,
States
,
Datatypes
,
Table
import
ipdb
,
os
,
json
,
datetime
,
config
import
ipdb
,
os
,
json
,
datetime
,
config
class
Process
:
class
Process
:
def
__init__
(
self
,
db
,
estadoTelefono
,
estadoMail
):
def
__init__
(
self
,
db
,
estadoTelefono
,
estadoMail
,
estadoSms
):
self
.
db
=
db
self
.
db
=
db
self
.
conn
=
DBconnection
(
db
)
self
.
conn
=
DBconnection
(
db
)
self
.
statePhone
=
estadoTelefono
self
.
statePhone
=
estadoTelefono
self
.
stateMail
=
estadoMail
self
.
stateMail
=
estadoMail
self
.
stateSms
=
estadoSms
# Guarda la data
# Guarda la data
def
datastore
(
self
,
id
,
path
):
def
datastore
(
self
,
id
,
path
):
...
@@ -40,8 +42,8 @@ class Process:
...
@@ -40,8 +42,8 @@ class Process:
if
not
serv
.
validatetype
(
types
[
file
]):
if
not
serv
.
validatetype
(
types
[
file
]):
return
"El servicio '"
+
query
[
Table
.
serv
]
+
"' no puede enviar el tipo '"
+
types
[
file
]
+
"' destinado al archivo '"
+
file
+
"'"
return
"El servicio '"
+
query
[
Table
.
serv
]
+
"' no puede enviar el tipo '"
+
types
[
file
]
+
"' destinado al archivo '"
+
file
+
"'"
# el parametro no es valido
# el parametro no es valido
if
not
serv
.
validateinfo
(
query
[
Table
.
info
]):
#
if not serv.validateinfo(query[Table.info]):
return
"El servicio '"
+
query
[
Table
.
serv
]
+
"' no cuenta con algún parámetro, sus parámetros son "
+
str
(
serv
.
Parameters
)
#
return "El servicio '" + query[Table.serv] + "' no cuenta con algún parámetro, sus parámetros son " + str(serv.Parameters)
entities
=
{
entities
=
{
Table
.
dest
:
query
[
Table
.
dest
],
Table
.
dest
:
query
[
Table
.
dest
],
...
@@ -59,6 +61,7 @@ class Process:
...
@@ -59,6 +61,7 @@ class Process:
def
send
(
self
):
def
send
(
self
):
self
.
_send
(
States
.
queued
,
"wpp1"
)
self
.
_send
(
States
.
queued
,
"wpp1"
)
self
.
_send
(
States
.
queued
,
"mail"
)
self
.
_send
(
States
.
queued
,
"mail"
)
self
.
_send
(
States
.
queued
,
"sms"
)
self
.
_send
(
"partially delivered"
,
"wpp1"
)
self
.
_send
(
"partially delivered"
,
"wpp1"
)
self
.
_send
(
"partially delivered"
,
"mail"
)
self
.
_send
(
"partially delivered"
,
"mail"
)
self
.
stateMail
.
MailRompedor
=
[]
self
.
stateMail
.
MailRompedor
=
[]
...
@@ -75,7 +78,7 @@ class Process:
...
@@ -75,7 +78,7 @@ class Process:
continue
continue
try
:
try
:
serv
=
serviceFactory
(
query
[
Table
.
serv
])
serv
=
serviceFactory
(
query
[
Table
.
serv
])
success
=
serv
.
send
(
query
,
self
.
statePhone
,
self
.
stateMail
)
#envia al servicio se salida
success
=
serv
.
send
(
query
,
self
.
statePhone
,
self
.
stateMail
,
self
.
stateSms
)
#envia al servicio se salida
except
:
except
:
success
=
{
'texto'
:
False
}
success
=
{
'texto'
:
False
}
print
(
"Rompio el proseso de envio procces linea 82"
)
print
(
"Rompio el proseso de envio procces linea 82"
)
...
...
services.py
View file @
3a4472f
...
@@ -7,6 +7,7 @@ from email.mime.audio import MIMEAudio
...
@@ -7,6 +7,7 @@ from email.mime.audio import MIMEAudio
from
email.mime.application
import
MIMEApplication
from
email.mime.application
import
MIMEApplication
from
ValidacionTelefonos
import
ValidacionTelefonosArgentinos
,
ValidacionCorreo
from
ValidacionTelefonos
import
ValidacionTelefonosArgentinos
,
ValidacionCorreo
import
requests
,
json
,
os
,
smtplib
,
config
,
base64
import
requests
,
json
,
os
,
smtplib
,
config
,
base64
import
SmsGateway24
as
Sms
class
ServiceBase
(
ABC
):
class
ServiceBase
(
ABC
):
...
@@ -41,7 +42,7 @@ class Wpp1(ServiceBase):
...
@@ -41,7 +42,7 @@ class Wpp1(ServiceBase):
uid
=
config
.
WS_uid
uid
=
config
.
WS_uid
server
=
config
.
FILE_server
server
=
config
.
FILE_server
def
send
(
self
,
data
,
stadotel
,
stadomail
):
def
send
(
self
,
data
,
stadotel
,
stadomail
,
stadoSms
):
tel
=
data
[
"dest"
]
tel
=
data
[
"dest"
]
v
=
ValidacionTelefonosArgentinos
()
v
=
ValidacionTelefonosArgentinos
()
tel
=
v
.
ValidarTelefono
(
tel
)
tel
=
v
.
ValidarTelefono
(
tel
)
...
@@ -121,7 +122,7 @@ class Mail(ServiceBase):
...
@@ -121,7 +122,7 @@ class Mail(ServiceBase):
self
.
s
.
starttls
()
self
.
s
.
starttls
()
self
.
s
.
login
(
self
.
__username
,
self
.
__password
)
self
.
s
.
login
(
self
.
__username
,
self
.
__password
)
def
send
(
self
,
data
,
stadotel
,
stadomail
):
#separo si es smtp o si es sendgrid api
def
send
(
self
,
data
,
stadotel
,
stadomail
,
stadoSms
):
#separo si es smtp o si es sendgrid api
info
=
json
.
loads
(
data
[
Table
.
info
])
info
=
json
.
loads
(
data
[
Table
.
info
])
try
:
try
:
host
=
info
[
"smtp"
][
"host"
]
host
=
info
[
"smtp"
][
"host"
]
...
@@ -298,9 +299,11 @@ class Mail(ServiceBase):
...
@@ -298,9 +299,11 @@ class Mail(ServiceBase):
class
SMS
(
ServiceBase
):
class
SMS
(
ServiceBase
):
Allowed
=
[
Datatypes
.
text
]
Allowed
=
[
Datatypes
.
text
]
URL
=
config
.
SMS_URL
URL
=
config
.
SMS_URL
Parameters
=
[
"smtp"
,]
def
send
(
self
,
data
):
def
send
(
self
,
data
,
stadotel
,
stadomail
,
stadoSms
):
types
=
json
.
loads
(
data
[
Table
.
type
])
types
=
json
.
loads
(
data
[
Table
.
type
])
info
=
json
.
loads
(
data
[
Table
.
info
])
success
=
{}
success
=
{}
for
file
in
types
:
for
file
in
types
:
with
open
(
data
[
Table
.
path
]
+
file
)
as
m
:
with
open
(
data
[
Table
.
path
]
+
file
)
as
m
:
...
@@ -308,16 +311,21 @@ class SMS(ServiceBase):
...
@@ -308,16 +311,21 @@ class SMS(ServiceBase):
if
type
(
text
)
==
bytes
:
if
type
(
text
)
==
bytes
:
text
=
text
.
decode
(
"utf-8"
)
text
=
text
.
decode
(
"utf-8"
)
try
:
try
:
response
=
requests
.
get
(
url
=
SMS
.
URL
,
params
=
{
#response = requests.get(url = SMS.URL, params = {
"phone"
:
data
[
Table
.
dest
],
# "phone" : data[Table.dest],
"message"
:
text
# "message" : text
})
#})
success
[
file
]
=
True
if
response
.
text
==
"OK"
else
False
#print(data[Table.dest], text, info)
#print(stadoSms,text, Table.dest, info["smtp"]["device"], info["smtp"]["sim"],info["smtp"]["email"], info["smtp"]["pass"])
Sms
.
EnviarSMS
(
stadoSms
,
text
,
data
[
Table
.
dest
],
info
[
"smtp"
][
"device"
],
info
[
"smtp"
][
"sim"
],
info
[
"smtp"
][
"email"
],
info
[
"smtp"
][
"pass"
])
success
[
file
]
=
True
if
"OK"
==
"OK"
else
False
except
:
except
:
success
[
file
]
=
False
success
[
file
]
=
False
return
success
return
success
def
validatetype
(
self
,
type
):
def
validatetype
(
self
,
type
):
return
type
in
SMS
.
Allowed
return
type
in
SMS
.
Allowed
def
validateinfo
(
self
,
info
):
def
validateinfo
(
self
,
info
):
if
info
==
None
:
if
info
==
None
:
return
True
return
True
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment