#!/usr/local/bin/python
#-
-Coding:utf-8--
author:jackytime:14-2-22 pm 11:48desc: Python code invocation example for SMS HTTP interface
Import Httplib
Import Urllib
#服务地址
Host = "Sms.253.com"
#端口号
Port = 80
#版本号
Version = "v1.1"
#查账户信息的URI
Balance_get_uri = "/msg/balance"
#智能匹配模版短信接口的URI
Sms_send_uri = "/msg/send"
#创蓝253账号
UN = "xxxx"
#创蓝密码
PW = "XXXX"
Def get_user_balance ():
"""
Take 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):
"""
can send text messages with the interface
"""
params = Urllib.urlencode ({' UN ': un, ' pw ': PW, ' msg ': text, ' phone ':p hone, ' 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 = "【创蓝253云通讯】您的验证码是1234"#查账户余额print(get_user_balance())#调用智能匹配模版接口发短信print(send_sms(text, phone))
Gen Blue 253 Cloud communication PAAs platform Python SMS interface demo