python3短信接口使用


import http.client
from urllib import parse

host  = "106.ihuyi.com"
sms_send_uri = "/webservice/sms.php?method=Submit"

#用戶名是登錄用戶中心->驗證碼短信->產品總覽->APIID
account  = APIID           # 登陸自己的賬號獲取
#密碼 查看密碼請登錄用戶中心->驗證碼短信->產品總覽->APIKEY
password = APIKEY          # 登陸自己的賬戶獲取

def send_sms(text, mobile):
    params = 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 = "173****7825"          # 要發送驗證碼的手機號
    text = "您的驗證碼是:"+ mobile[7:] +"。請不要把驗證碼泄露給其他人。"     
  # 短信內容的模板必須和后台定義的一樣,可以吧隨機生成的驗證碼通過眸中和方式返回前端頁面
print(send_sms(text, mobile))

測試平台:http://user.ihuyi.com/

更詳細的文檔可以找短信公司獲取。。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM