使用Django向手机发送短信 [英] Sending an SMS to a Cellphone using Django

查看:365
本文介绍了使用Django向手机发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,我有这个小调查模块,它发送一个简单的短信给我给的电话号码,并且必须收集响应(如果用户激活它)并显示给我。我正在使用django构建我的项目。我已经尝试了django-sms谷歌代码项目,但我无法将信息从我的手机发回到我的服务器。我浏览了许多关于短信网关/运营商的教程。但我迷失了。任何人都可以帮助我建议一个关于从我的应用程序(django)发送短信到任何手机的教程?关于向手机发送短信,会花费我(就像我从一个手机发送短信到另一个手机)吗?

解决方案

我的名字是Jarod,我为Twilio.com工作,所以我有点偏见。但是,就是说,使用 Twilio Rest Api 。以下是一个简单的例子:

 #从twilio.com/docs/python/install下载Python助手库
来自twilio.rest import TwilioRestClient

#您的帐户Sid和Auth令牌来自twilio.com/user/account
account_sid ={{account_sid}}
auth_token ={ {auth_token}}
client = TwilioRestClient(account_sid,auth_token)

message = client.messages.create(
body =Jenny please ?!我爱你< 3 ,
to =+ 15558675309,
from _ =+ 14158141829,
media_url =http://www.example.com/hearts.png)
打印message.sid


I am building an application, where I have this little survey module, which sends out a simple sms to the phone number I give and has to collect the response(if the user fires it) and show it to me. I am using to django build my project. I have tried django-sms google code project, but I couldn't post messages back from my mobile to my server. I have browsed through many tutorials on sms-gateways/carriers. But I am lost. Can anyone help me in suggesting a tutorial about sending sms from my application(django) to any cellphone? And regarding sending sms to cellphone, would it cost me(just as how i send sms from one cellphone to another)?

解决方案

Hi my name is Jarod and I work for Twilio.com so I am a little biased. But with that said, it is super easy to send an SMS from your Python web application using the Twilio Rest Api. Here is a simple example:

# Download the Python helper library from twilio.com/docs/python/install 
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "{{ account_sid }}"
auth_token  = "{{ auth_token }}"
client = TwilioRestClient(account_sid, auth_token)

message = client.messages.create(
    body="Jenny please?! I love you <3",
    to="+15558675309",
    from_="+14158141829",
    media_url="http://www.example.com/hearts.png")
print message.sid

这篇关于使用Django向手机发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆