1. 程式人生 > 其它 >利用互億介面實現傳送驗證碼

利用互億介面實現傳送驗證碼

技術標籤:pythonpython

利用互億介面實現傳送驗證碼

# -*- coding:utf-8 -*-
# @File  :test.py
# @Author:yx yao
# @Date  :2020/12/17  9:06
# @Desc  :
# 介面型別:互億無線觸發簡訊介面,支援傳送驗證碼簡訊、訂單通知簡訊等。
# 賬戶註冊:請通過該地址開通賬戶http://user.ihuyi.com/register.html
# 注意事項:
# (1)除錯期間,請使用用系統預設的簡訊內容:您的驗證碼是:【變數】。請不要把驗證碼洩露給其他人。
# (2)請使用 APIID 及 APIKEY來呼叫介面,可在會員中心獲取;
# (3)該程式碼僅供接入互億無線簡訊介面參考使用,客戶可根據實際需要自行編寫; # !/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 = "######"
# 檢視密碼 登入使用者中心->驗證碼通知簡訊>產品總覽->API介面資訊->APIKEY password = "########" 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 = "180^^^^^^^^^" code = random.randint(100000, 999999) # 生成大於等於100000小於等於999999的一個數 text = "您的驗證碼是:{}。請不要把驗證碼洩露給其他人。".format(str(code)) print(send_sms(text, mobile))