-
Notifications
You must be signed in to change notification settings - Fork 5
/
sms.py
30 lines (27 loc) · 881 Bytes
/
sms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from twilio.rest import TwilioRestClient
from setting import TWILIO_FROM
from setting import TWILIO_ID
from setting import TWILIO_PWD
class SMS(object):
''' SMS object '''
def __init__(self):
self.client = TwilioRestClient(TWILIO_ID, TWILIO_PWD)
def send(self, msg):
data = {'to': msg['to'],
'body': u'[COSCUP]{0}'.format(msg['body'][:152]),
'from_': TWILIO_FROM,
}
try:
m = self.client.sms.messages.create(**data)
return {'status': True,
'msg': m,
'sid': m.sid,
'price': m.price,
}
except Exception as e:
return {'status': False,
'ERROR': str(e),
'data': data,
}