Twilio
1.访问http://twilio.com/并注册。注册了新账户后,你需要验证一个手机
号码,短信将发给该号码。
2.Twilio 提供的试用账户包括一个电话号码,它将作为短信的发送者。你将需要
两个信息:你的账户SID 和AUTH(认证)标志。在登录Twilio 账户时,可以在
Dashboard 页面上找到这些信息。从Python 程序登录时,这些值将作为你的Twilio
用户名和密码。
短信
from twilio.rest import Client # 下面认证信息的值在你的 twilio 账户里可以找到
account_sid = "AC4406ed09xxxxxefaabe660eb004d736"
auth_token = "54c166ab064xxxxx5193269e268de"
client = Client(account_sid, auth_token)
def send_SMS(sms_message):
message = client.messages.create(to="+861xxxx776",
from_="+1540xxxx3935",
body=sms_message)
send_SMS('这是短信内容')
电话
from twilio.rest import Client def call_message():
account_sid = "AC4406ed0903xxxefaabe660eb004d736"
auth_token = "54c166ab0xxxe22d95193269e268de"
client = Client(account_sid, auth_token)
call = client.calls.create(
to="+8615xxxx776",
from_="+15403xxxx935",
url="http://demo.twilio.com/docs/voice.xml"
)
部分报错:
报错:Unable to create record: Permission to send an SMS has not been enabled for the region indicated by the 'To' number:
需要添加发消息信任国家,查看具体报错:https://www.twilio.com/docs/errors/21408