Python SMS Interface Demo: Gen Blue 253 SMS Authentication Code interface, SMS Marketing interface

Source: Internet
Author: User

#!/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))

Python SMS Interface Demo: Gen Blue 253 SMS Verification Code interface, SMS Marketing interface

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.