利用python库twilio来免费发送短信

转自:https://cuiqingcai.com/5696.html

个人验证短信发送成功,但是电话拨打未成功(待进一步探索),代码如下(前期安装注册见上述链接):

from twilio.rest import Client


def Send_Message(): 
    account_sid = '..................'   # 注册后得到
    auth_token = '...................'   # 注册后得到
    client = Client(account_sid, auth_token)
    message = client.messages.create(
        to="+86***********",  # 缺点是收信人必须要先认证
        from_="***********",  #官网注册后得到的一个手机号码
        body="来了老弟")  #短息内容
    #print(message.sid)


def Phone_Call():
    account_sid = '..........................'  
    auth_token = '...........................'
    client = Client(account_sid, auth_token)
    call = client.calls.create(
        to="+***********",
        from_='***********',  # 官网注册后得到的一个手机号码
        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)

if __name__ == "__main__":
    Send_Message()
    #Phone_Call()

短信如下发送成功

猜你喜欢

转载自blog.csdn.net/feiyang5260/article/details/86616539