send_SMS

import http.client

import urllib

# 定义主机
host = "106.ihuyi.com"
sms_send_uri = "/webservice/sms.php?method=Submit"

# 查看用户名 登录用户中心->验证码通知短信>产品总览->API接口信息->APIID
account = "C45031386"
# 查看密码 登录用户中心->验证码通知短信>产品总览->API接口信息->APIKEY
password = "533123"


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

    print(send_sms(text, mobile))

你可能感兴趣的:(send_SMS)