您的位置:首页 > 编程语言 > Python开发

python使用第三方模块实现给注册用户发送验证码

2018-05-14 12:03 411 查看

互亿通信网址  http://user.ihuyi.com/nav/sms.html (打开本网址进行注册)

import http.client  #(注意python3中没有httplib模块 使用 http.client模块)
import urllib

host = "106.ihuyi.com"  #(无需改动)
sms_send_uri = "/webservice/sms.php?method=Submit"  #(无需改动)

# 用户名是登录用户中心->验证码短信->产品总览->APIID
account = "xxxxxx"
# 密码 查看密码请登录用户中心->验证码短信->产品总览->APIKEY
password = "xxxxxxxxxx"

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 = "135xxxxxxxx"
    text = "您的验证码是:131421。请不要把验证码泄露给其他人。"
    print(send_sms(text, mobile))




阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐