#!/usr/local/bin/python
#-*- coding:utf-8 -*-
# Author: jacky
# Time: 14-2-22 下午11:48
# Desc: 短信http接口的python代码调用示例
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"
#创蓝253密码
pw = "xxxx"
def get_user_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 = "【创蓝253云通讯】您的验证码是1234"
#查账户余额
print(get_user_balance())
#调用智能匹配模版接口发短信
print(send_sms(text, phone))
扫码关注5G通信官方公众号,免费领取以下5G精品资料
1、回复“YD5GAI”免费领取《中国移动:5G网络AI应用典型场景技术解决方案白皮书》
2、回复“5G6G”免费领取《5G_6G毫米波测试技术白皮书-2022_03-21》
3、回复“YD6G”免费领取《中国移动:6G至简无线接入网白皮书》
4、回复“LTBPS”免费领取《《中国联通5G终端白皮书》》
5、回复“ZGDX”免费领取《中国电信5G NTN技术白皮书》
6、回复“TXSB”免费领取《通信设备安装工程施工工艺图解》
7、回复“YDSL”免费领取《中国移动算力并网白皮书》
8、回复“5GX3”免费领取《 R16 23501-g60 5G的系统架构1》