import http.client
from urllib import parse
host = "106.ihuyi.com"
sms_send_uri = "/webservice/sms.php?method=Submit"
#用户名是登录用户中心->验证码短信->产品总览->APIID
account = APIID # 登陆自己的账号获取
#密码 查看密码请登录用户中心->验证码短信->产品总览->APIKEY
password = APIKEY # 登陆自己的账户获取
def send_sms(text, mobile):
params = parse.urlencode({'account': account, 'password' : password, 'content': text, 'mobile':mobile,'format':'json' })
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = http.client.HTTPConnection(host, port=80, 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__':
mobile = "173****7825" # 要发送验证码的手机号
text = "您的验证码是:"+ mobile[7:] +"。请不要把验证码泄露给其他人。"
# 短信内容的模板必须和后台定义的一样,可以吧随机生成的验证码通过眸中和方式返回前端页面
print(send_sms(text, mobile))