使用twilio库实现在特定条件下进行短信或电话提醒

官网( 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()

猜你喜欢

转载自blog.csdn.net/zh54b5n64vn64654/article/details/85113898