这篇文章主要为大家分享Python短信接口代码,Python短信发送、Python批量发送、Python短信验证码发送,感兴趣的小伙伴们可以参考一下。
功能:PYTHON短信接口、PYTHON发送短信
用途:短信验证码、会员营销短信、各类通知短信
注意事项:该代码仅供接入秒赛科技短信接口参考使用,用户可根据实际需要自行修改
#!/usr/local/bin/python
#-*-coding:utf-8-*-
# Desc: 短信http接口的python代码调用示例
# https访问,需要安装 openssl-devel库。apt-get install openssl-devel
import httplib
import urllib
import json
#服务地址,请咨询客服
sms_host = “xxxxxxxxxx”
#端口号
port = 80
#发送uri,请咨询客服
send_uri = “xxxxxxxxxxx”
def send(account,pswd, content, mobile):
“””
发送短信
“””
params = urllib.urlencode({‘account’: account,‘pswd’: pswd, ‘msg’: msg, ‘mobile’:mobile, ‘needstatus’:‘true’, ‘product’:”})
headers = {“Content-type”: “application/x-www-form-urlencoded”, “Accept”: “text/plain”}
conn = httplib.HTTPSConnection(sms_host, port=port, timeout=30)
conn.request(“POST”, send_uri, params, headers)
response = conn.getresponse()
response_str = response.read()
conn.close()
return response_str
if __name__ == ‘__main__’:
#账号
account = “***************”;
#密码
pswd = “***************”;
#修改为您要发送的手机号
mobile = “***************”;
# 发送短信
# 修改为您要发送的短信内容
msg=“【秒赛科技】您的验证码是:1234”;
#print send(account,pswd,msg,mobile)