使用 Django 向手机发送短信

发布于 2024-07-11 08:50:14 字数 271 浏览 6 评论 0原文

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

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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

夜巴黎 2024-07-18 08:50:14

大家好,我叫 Jarod,在 Twilio.com 工作,所以我有点偏见。 但话虽如此,使用 Twilio Rest Api。 这是一个简单的例子:

# 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

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
怪我太投入 2024-07-18 08:50:14

从技术角度来看,使用任何网络应用程序完成短信发送的最简单方法是通过电子邮件。 大多数手机提供商通常会向其用户提供电子邮件帐户,并且向所述帐户发送邮件很可能会通过短信将邮件重定向到他们的手机。 然而,并非所有运营商都这样做,有些运营商会对此类服务收取额外费用。 在这种情况下,您可以通过查看以下 Django 文档页面 来处理此

问题如上所述,这并不是一个真正完整的解决方案,因此最简单的方法是使用 SMS 网关。 大多数情况下,它们提供简单的基于 REST 的 API,用于向手机发送短信。 不同运营商的 API 明显不同。 如果您正在寻找免费的开源解决方案(假设您想要在您的服务器上安装实际的网关)。

不管怎样,我会开始尝试让它与电子邮件场景一起工作,然后如果您确实需要的话,继续使用运营商。 希望这会有所帮助。

From a technical standpoint, the easiest way to accomplish SMS sending with any web-app is through e-mails. Most cell providers usually give out email accounts to their users, and sending a mail to said account will more likely than not redirect the mail to their cell via SMS. However, not all carriers do this and some charge extra for this type of service. In this case, you could handle this checking out the following Django documentation page

However, as mentioned, this isn't a really complete solution, so the easiest way would be to use a SMS-gateway. Mostly, they provide simple REST based API's for sending text messages to cell phones. The API would vary obviously from carrier to carrier. I would recommend checking out Kannel in case you're looking for a free and open source solution (that is assuming you want to install the actual gateway on your server).

Anyway, I would start out trying to get it to work with the e-mail scenario, and then moving on to using a carrier if you actually require it. Hopefully this helps somewhat.

夏花。依旧 2024-07-18 08:50:14

我在另一篇文章中回答了类似的问题,但有点晚了。 这是为了获取更多信息。 希望它有所帮助:

我为此苦苦挣扎了一段时间,并且非常喜欢 Twilio 选项。 但后来我更深入地挖掘,发现有一个名为 pygooglevoice 的 Google Voice API 可以工作。 干净、简单...无需查找运营商...例如,设置 virtualenv并使用 pip 安装:

pip install pygooglevoice

然后使用类似这样的内容:

from googlevoice import Voice
from googlevoice.util import input

def send(number, message):
    user = '[email protected]'
    password = 'password'

    voice = Voice()
    voice.login(user, password)

    #number = input('Number to send message to: ') # use these for command method
    #message = input('Message text: ')

    voice.send_sms(number, message)

请注意,我对此进行了有限的测试,所以我不确定所有的优点和缺点。 很可能存在我尚未发现的局限性。 但在我玩它的时候,我很高兴。

I answered a similar question, a bit late to the game, in another post. Here it is for additional information. Hope it helps:

I was struggling with this for some time and really liked the Twilio option. But then I dug deeper and found that there is a Google Voice API called pygooglevoice that works. Clean, easy... No carrier lookup... For example, set up a virtualenv and install with pip:

pip install pygooglevoice

Then use something like this:

from googlevoice import Voice
from googlevoice.util import input

def send(number, message):
    user = '[email protected]'
    password = 'password'

    voice = Voice()
    voice.login(user, password)

    #number = input('Number to send message to: ') # use these for command method
    #message = input('Message text: ')

    voice.send_sms(number, message)

Please note that I have done limited testing with this so I'm not sure all the pros and cons. It's quite possible that there are limitations I haven't discovered yet. But in the time I've played around with it, I've been happy.

半世晨晓 2024-07-18 08:50:14

看看 django-sms

take a look at django-sms

昔日梦未散 2024-07-18 08:50:14

请访问 twilio.com。 它们提供易于使用的 API(几行 Python 代码)以及在用户响应时接收 SMS 消息并在应用程序中触发回调的可能性。

Check out twilio.com. They provide easy to use API (couple of lines of code in Python) and possibility to receive SMS messages and firing callbacks in your application when users respond.

没企图 2024-07-18 08:50:14

http://bitbucket.org/vgavro/django-smsgate 显然是您正在寻找的,但是您必须为您的短信网关编写自定义后端。

http://bitbucket.org/vgavro/django-smsgate is obviously what you are looking for, but you have to write custom backend for your sms-gateway.

陌生 2024-07-18 08:50:14

我还找到了 TextMagic。 它看起来很有前途,尽管对于我居住的国家/地区来说有点贵。对于您感兴趣的国家/地区来说,它的价格可能具有竞争力,因此请在充电之前检查定价。

使用似乎很简单足够了:

通过 pip 快速安装:

pip install textmagic

并且发送短信似乎很简单,如下所示:

from textmagic.rest import TextmagicRestClient

username = "your_textmagic_username"
token = "your_apiv2_key"
client = TextmagicRestClient(username, token)

message = client.messages.create(phones="9990001001", text="Hello TextMagic")

I have also found TextMagic. It looks promising although it is a bit pricey for the country I live in. It may have competitive prices for the country you are interested in, so please check pricing before you charge ahead.

Usage seems to be easy enough:

Quick installation via pip:

pip install textmagic

And sending an SMS seems to be trivial as follows:

from textmagic.rest import TextmagicRestClient

username = "your_textmagic_username"
token = "your_apiv2_key"
client = TextmagicRestClient(username, token)

message = client.messages.create(phones="9990001001", text="Hello TextMagic")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文