Last active
December 23, 2020 23:45
-
-
Save iraycd/819c8c5c456d301aa2531848a758fd11 to your computer and use it in GitHub Desktop.
MSG91 - Django SendSMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sendsms.backends.base import BaseSmsBackend | |
from django.conf import settings | |
import urllib | |
import urllib2 | |
MSG91_AUTHKEY = getattr(settings, 'MSG91_AUTHKEY', '') | |
MSG91_ROUTE = getattr(settings, 'MSG91_ROUTE', '') | |
class Msg91SmsBackend(BaseSmsBackend): | |
def send_messages(self, messages): | |
for message in messages: | |
for to in message.to: | |
values = { | |
'authkey' : MSG91_AUTHKEY, | |
'mobiles' : to, | |
'message' : message.body, | |
'sender' : message.from_phone, | |
'route' : MSG91_ROUTE | |
} | |
print values | |
url = "https://control.msg91.com/api/sendhttp.php" # API URL | |
postdata = urllib.urlencode(values) # URL encoding the data here. | |
req = urllib2.Request(url, postdata) | |
response = urllib2.urlopen(req) | |
output = response.read() # Get Response | |
print response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment