首頁  >  文章  >  後端開發  >  Python實作發送簡訊的方法介紹(附程式碼)

Python實作發送簡訊的方法介紹(附程式碼)

不言
不言轉載
2019-03-09 14:15:385909瀏覽

這篇文章帶給大家的內容是關於Python發短信的方法介紹(附代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。

#先註冊互億無線,然後複製發送簡訊介面右上角的apiid和apikey更換程式碼中的account和password
#APIID:1

#APIKEY: a9
#介面類型:互億無線觸發簡訊接口,支援發送驗證碼簡訊、訂單通知簡訊等。
#帳戶註冊:請透過該位址開啟帳戶http://sms.ihuyi.com/register.html
#注意事項:
#(1)調試期間,請以預設的範本進行測試,預設範本詳見介面文件;
#(2)請使用API​​ID(查看APIID請登入使用者中心->驗證碼簡訊->產品總覽->APIID)及APIkey來呼叫介面;
#(3)程式碼僅供接入互億無線簡訊介面參考使用,客戶可依實際需求自行編寫;

#!/usr/local/bin/python
#-
- coding:utf-8 -
-
import http.client
import urllib
host  = “106.ihuyi.com”
sms_send_uri = “/webservice/sms.php?method=Submit”
#用户名是登录用户中心->验证码短信->产品总览->APIID
account  = “1”
#密码 查看密码请登录用户中心->验证码短信->产品总览->APIKEY
password = “a9”
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 = "1879431006*"
text = "您的验证码是:110110。请不要把验证码泄露给其他人。"

print(send_sms(text, mobile))

以上是Python實作發送簡訊的方法介紹(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除