python发送短信

2023-01-31 05:01:35 python 发送短信

import Http.client
import urllib

host = "106.ihuyi.com"
sms_send_uri = "/WEBservice/sms.PHP?method=Submit"

account = "xxxx"

passWord = "xxx"

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':
mobile = "17740173360"
text = "您的验证码是:121254。请不要把验证码泄露给其他人。"

print(send_sms(text, mobile))

相关文章