[SMS verification code Python interface demo based on Chuanglan 253 cloud communication platform]
#!/usr/local/bin/python
#-*- coding:utf-8 -*-
# Author: jacky
# Time: 14-2-22 11:48 pm
# Desc: Example of python code call for SMS http interface
import httplib
import urllib #Service
address
host = "sms.253.com" #Port
number
port = 80 #Version
number
version = "v1.1" #Check
account URI of information
balance_get_uri = "/msg/balance" #URI
of smart matching template SMS interface
sms_send_uri = "/msg/send" #Chuanglan
253 account
un = "xxxx" #Chuanglan
password
pw = "xxxx"
def get_user_balance() :
"""
Withdraw account balance
"""
conn = httplib.HTTPConnection(host, port=port)
conn.request('GET', balance_get_uri + "?un=" + un + "&pw=" + pw)
response = conn.getresponse()
response_str = response.read()
conn.close()
return response_str
def send_sms(text, phone):
"""
能用接口发短信
"""
params = urllib.urlencode({'un': un, 'pw' : pw, 'msg': text, 'phone':phone, 'rd' : '1'})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = httplib.HTTPConnection(host, port=port, timeout=30)
conn.request("POST", sms_send_uri, params,headers)
response = conn.getresponse()
response_str = response.read()
conn.close()
return response_str
if __name__ == '__main__':
phone = "188xxxxxxxx"
text = "[Chuanglan 253 Cloud Communication] Your verification code is 1234" #Check
account balance
print(get_user_balance()) #Call the
smart matching template interface to send text messages
print(send_sms(text, phone))
SMS verification code Python interface demo
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326237530&siteId=291194637
Recommended
Ranking