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
Wpp1State.py
View file @
3a4472f
...
...
@@ -175,3 +175,71 @@ class StateMail():
dg
.
starttls
()
dg
.
login
(
User
,
Pass
)
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
config.py
View file @
3a4472f
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_uid
=
"5493412641022"
FILE_server
=
"https://archivos.hgtsa.com.ar/"
...
...
deploy.py
View file @
3a4472f
...
...
@@ -4,13 +4,14 @@ from werkzeug.datastructures import FileStorage
from
process
import
Process
from
python_arptable
import
get_arp_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
app
=
Flask
(
__name__
)
TelState
=
StatePhoneWs
()
MailState
=
StateMail
()
SmsStatus
=
AndroidStatus
()
# carpeta de los mensajes
msgfolder
=
config
.
folder
#"msg/"
# id mínimo para una tabla
...
...
@@ -26,7 +27,7 @@ prefix_lenght = 16
# tiempo límite que debe pasar para eliminar cosas
operation_timer
=
86400
# conección a base de datos
process
=
Process
(
config
.
db
,
TelState
,
MailState
)
process
=
Process
(
config
.
db
,
TelState
,
MailState
,
SmsStatus
)
#Cache de estado de telefonos
...
...
@@ -42,21 +43,31 @@ def key():
f
.
close
()
return
key
@app.route
(
"/state/<tel>"
,
methods
=
[
'GET'
])
@app.route
(
"/state/<tel>"
,
methods
=
[
'GET'
,
'POST'
])
def
estadoWabox
(
tel
):
print
(
tel
)
if
tel
==
"default"
:
xi
=
TelState
.
ChequearTelefono
(
config
.
WS_uid
)
else
:
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
():
datos
=
request
.
json
#
print(datos)
print
(
datos
)
test
=
MailState
.
ChequearMailServer
(
datos
[
"user"
],
datos
[
"pass"
],
int
(
datos
[
"port"
]),
datos
[
"host"
])
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)
# Pide guardar en base de datos una preinstancia del mensaje
@app.route
(
'/data'
,
methods
=
[
'POST'
])
...
...
@@ -133,13 +144,13 @@ def cons():
# Intenta enviar mensajes
def
attempt
():
p
=
Process
(
config
.
db
,
TelState
,
MailState
)
p
=
Process
(
config
.
db
,
TelState
,
MailState
,
SmsStatus
)
p
.
send
()
threading
.
Timer
(
retry_timer
,
attempt
)
.
start
()
# Limpia basura
def
clean
():
p
=
Process
(
config
.
db
,
TelState
,
MailState
)
p
=
Process
(
config
.
db
,
TelState
,
MailState
,
SmsStatus
)
paths
=
p
.
paths
()
now
=
datetime
.
datetime
.
now
()
...
...
process.py
View file @
3a4472f
...
...
@@ -3,13 +3,15 @@ from database import DBconnection
from
enums
import
Services
,
States
,
Datatypes
,
Table
import
ipdb
,
os
,
json
,
datetime
,
config
class
Process
:
def
__init__
(
self
,
db
,
estadoTelefono
,
estadoMail
):
def
__init__
(
self
,
db
,
estadoTelefono
,
estadoMail
,
estadoSms
):
self
.
db
=
db
self
.
conn
=
DBconnection
(
db
)
self
.
statePhone
=
estadoTelefono
self
.
stateMail
=
estadoMail
self
.
stateSms
=
estadoSms
# Guarda la data
def
datastore
(
self
,
id
,
path
):
...
...
@@ -40,8 +42,8 @@ class Process:
if
not
serv
.
validatetype
(
types
[
file
]):
return
"El servicio '"
+
query
[
Table
.
serv
]
+
"' no puede enviar el tipo '"
+
types
[
file
]
+
"' destinado al archivo '"
+
file
+
"'"
# el parametro no es valido
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
)
#
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)
entities
=
{
Table
.
dest
:
query
[
Table
.
dest
],
...
...
@@ -59,6 +61,7 @@ class Process:
def
send
(
self
):
self
.
_send
(
States
.
queued
,
"wpp1"
)
self
.
_send
(
States
.
queued
,
"mail"
)
self
.
_send
(
States
.
queued
,
"sms"
)
self
.
_send
(
"partially delivered"
,
"wpp1"
)
self
.
_send
(
"partially delivered"
,
"mail"
)
self
.
stateMail
.
MailRompedor
=
[]
...
...
@@ -75,7 +78,7 @@ class Process:
continue
try
:
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
:
success
=
{
'texto'
:
False
}
print
(
"Rompio el proseso de envio procces linea 82"
)
...
...
services.py
View file @
3a4472f
...
...
@@ -7,6 +7,7 @@ from email.mime.audio import MIMEAudio
from
email.mime.application
import
MIMEApplication
from
ValidacionTelefonos
import
ValidacionTelefonosArgentinos
,
ValidacionCorreo
import
requests
,
json
,
os
,
smtplib
,
config
,
base64
import
SmsGateway24
as
Sms
class
ServiceBase
(
ABC
):
...
...
@@ -41,7 +42,7 @@ class Wpp1(ServiceBase):
uid
=
config
.
WS_uid
server
=
config
.
FILE_server
def
send
(
self
,
data
,
stadotel
,
stadomail
):
def
send
(
self
,
data
,
stadotel
,
stadomail
,
stadoSms
):
tel
=
data
[
"dest"
]
v
=
ValidacionTelefonosArgentinos
()
tel
=
v
.
ValidarTelefono
(
tel
)
...
...
@@ -121,7 +122,7 @@ class Mail(ServiceBase):
self
.
s
.
starttls
()
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
])
try
:
host
=
info
[
"smtp"
][
"host"
]
...
...
@@ -298,9 +299,11 @@ class Mail(ServiceBase):
class
SMS
(
ServiceBase
):
Allowed
=
[
Datatypes
.
text
]
URL
=
config
.
SMS_URL
def
send
(
self
,
data
):
Parameters
=
[
"smtp"
,]
def
send
(
self
,
data
,
stadotel
,
stadomail
,
stadoSms
):
types
=
json
.
loads
(
data
[
Table
.
type
])
info
=
json
.
loads
(
data
[
Table
.
info
])
success
=
{}
for
file
in
types
:
with
open
(
data
[
Table
.
path
]
+
file
)
as
m
:
...
...
@@ -308,16 +311,21 @@ class SMS(ServiceBase):
if
type
(
text
)
==
bytes
:
text
=
text
.
decode
(
"utf-8"
)
try
:
response
=
requests
.
get
(
url
=
SMS
.
URL
,
params
=
{
"phone"
:
data
[
Table
.
dest
],
"message"
:
text
})
success
[
file
]
=
True
if
response
.
text
==
"OK"
else
False
#response = requests.get(url = SMS.URL, params = {
# "phone" : data[Table.dest],
# "message" : text
#})
#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
:
success
[
file
]
=
False
return
success
def
validatetype
(
self
,
type
):
return
type
in
SMS
.
Allowed
def
validateinfo
(
self
,
info
):
if
info
==
None
:
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