Created
August 4, 2012 13:14
-
-
Save roman-yepishev/3257660 to your computer and use it in GitHub Desktop.
Atompark SMS API v2.0 Example
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# This code is in public domain | |
import httplib2 | |
import urllib | |
import random | |
from xml.etree.ElementTree import Element, SubElement, Comment, tostring | |
from xml.dom import minidom | |
httplib2.debuglevel = 9 | |
USER = '' | |
PASSWORD = '' | |
PHONE_NUMBER = '' | |
GATEWAY_URL = 'https://atompark.com/members/sms/xml.php' | |
sms = Element('SMS') | |
operations = Element('operations') | |
operation = Element('operation') | |
operation.text = 'SEND' | |
operations.append(operation) | |
sms.append(operations) | |
authentification = Element('authentification') | |
username = Element('username') | |
password = Element('password') | |
username.text = USER | |
password.text = PASSWORD | |
authentification.append(username) | |
authentification.append(password) | |
sms.append(authentification) | |
message = Element('message') | |
sender = Element('sender') | |
sender.text='sms-info' | |
text = Element('text') | |
text.text = u'Example Text Message' | |
message.append(sender) | |
message.append(text) | |
sms.append(message) | |
numbers = Element('numbers') | |
number = Element('number') | |
number.text = PHONE_NUMBER | |
numbers.append(number) | |
sms.append(numbers) | |
xml = tostring(sms, encoding='UTF-8') | |
xml = minidom.parseString(xml).toprettyxml(indent=" ") | |
xml = xml.encode('utf-8') | |
boundary = '-' * 21 + str(int(random.random() * 1000)) | |
headers = {'Content-Type': 'multipart/form-data; boundary=%s' % boundary,} | |
body = '--' + boundary + '\r\n' + \ | |
'Content-Disposition: form-data; name="XML"\r\n\r\n' + \ | |
xml + '\r\n--' + boundary + '--\r\n' | |
client = httplib2.Http() | |
resp, content = client.request(GATEWAY_URL, | |
method='POST', | |
headers=headers, | |
body=body) | |
print "Resp: %s" % (resp, ) | |
print "Content: %s" % (content, ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment