python短信发送
'''以云之讯平台为例:'''
url = 'https://open.ucpaas.com/ol/sms/sendsms'
# 账户sid
sid = 'f0ad70b276a8b63eb44f415a425da21b'
# 认证令牌
token = 'c23b34c9a467689c2ba562b10a7de7d4'
# 应用ID
appid = '6c37655fbb894848a71f8004e105e313'
# 模板ID
templateid = '403815'
# 接收手机号
mobile = '17549204420'
# 参数字典
data = {
"sid": sid,
"token": token,
"appid": appid,
"templateid": templateid,
"mobile": mobile,
}
# 将字典转换为JSON字符串
import json
json_data = json.dumps(data)
# print(json_data)
# 创建'浏览器'对象
import http.client
connect = http.client.HTTPConnection('open.ucpaas.com')
# 接口地址
url = 'https://open.ucpaas.com/ol/sms/sendsms'
# 请求头
header = {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=utf-8',
}
# 发送请求
connect.request(method='POST', url=url, body=json_data, headers=header)
# 获取响应
resp = connect.getresponse()
# 打印响应内容
print(resp.read().decode('utf-8'))