#!/usr/local/bin/python
#-*- coding:utf-8 -*-
import http.client
import urllib
import random
host = "106.ihuyi.com"
sms_send_uri = "/webservice/sms.php?method=Submit"
#查看用户名 登录用户中心->验证码通知短信>产品总览->API接口信息->APIID
account = "C23025920"
#查看密码 登录用户中心->验证码通知短信>产品总览->API接口信息->APIKEY
password = "8e08dadbaf7655eab985649d22bfad41"
def send_sms(text, mobile):
params = urllib.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__':
num=random.randint(100000,999999) #随机生成字符串
mobile = "18500702404"
text = "您的验证码是:%s。请不要把验证码泄露给其他人。"%num
print(num)
print(send_sms(text, mobile))