使用twilio庫實現在特定條件下進行簡訊或電話提醒
阿新 • • 發佈:2018-12-30
官網( https://www.twilio.com)進行註冊和手機驗證,會獲得屬於你的SID和Token
設定中申請一個電話號碼,簡訊和電話就會從這個電話號碼傳送或撥打到你的手機上來
程式碼如下
from twilio.rest import Client # Your Account SID from twilio.com/console account_sid = "ACc6097f7**********bb08892d05a34c" # Your Auth Token from twilio.com/console auth_token = "209dfd44*********f8ba49e" def sendMessage(): client = Client(account_sid, auth_token) message = client.messages.create( from_='+157****2212', body='hello world', to='+86187****7569' ) print(message.sid) def callphone(): client = Client(account_sid, auth_token) call = client.calls.create( to = "+86187****7569", from_ = "+157****2212", url = "http://demo.twilio.com/docs/voice.xml", method = "GET", status_callback="https://www.myapp.com/events", status_callback_method="POST", status_callback_event=["initiated", "ringing", "answered", "completed"] ) print(call.sid) # sendMessage() callphone()