手机python3_python3 简单手机验证码的实现
import http.client
import urllib
def send_sms(mobile):
host = "106.ihuyi.com"
sms_send_uri = "/webservice/sms.php?method=Submit"
# 用戶名是登錄用戶中心->驗證碼短信->產品總覽->APIID
account = "C12345678"
# 密碼 查看密碼請登錄用戶中心->驗證碼短信->產品總覽->APIKEY
password = " ******************************************* "
message_code = str(random.randint(100000, 999999)) # 生成大于等于100000小于等于999999的一個數
print(message_code)
text = "您的驗證碼是:" + message_code + "。請不要把驗證碼泄露給其他人。" # 將整型x轉為字符串型并且發送
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()
# 把驗證碼放進session中 問題是驗證完之后就沒有作用了
request.session['message_code'] = message_code
# 驗證之后刪除? 還不知道具體放哪刪除最好? ?暫且放置在驗證環節最后
# del request.session['message_code']
return response_str.decode()
if __name__ == '__main__':
mobile = "183********"
print(send_sms(mobile))
總結
以上是生活随笔為你收集整理的手机python3_python3 简单手机验证码的实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python制作自动抢票_python自
- 下一篇: 用python中django创建网页终端