php 来自网络应用程序的短信
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/432944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SMS from web application
提问by Shyju
I just want to send SMS from my web application in PHP. Can anyone tell me how to do this? What all things I need to do for this?
我只想用 PHP 从我的 Web 应用程序发送 SMS。谁能告诉我如何做到这一点?我需要为此做些什么?
采纳答案by Paolo Bergantino
I don't know if this applies to you, but what I have done many times to save myself the money is ask the user in his profile what his carrier is, then tried matching it with this list. Essentially, many/most carriers have an email address connected to a phone number that will easily let you send texts to the number. For example, if you have ATT and your phone number is 786-262-8344, an email to [email protected] will send you a text message with the subject/body of the email, free of charge. This technique will pretty much cover all of your US users for free. Obviously, depending on the needs of your application this may not be possible/adequate/desired, but it is an option to be aware of.
我不知道这是否适用于您,但是我多次为自己省钱是在他的个人资料中询问用户他的运营商是什么,然后尝试将其与this list. 从本质上讲,许多/大多数运营商都有一个与电话号码相连的电子邮件地址,可以让您轻松地向该号码发送文本。例如,如果您有 ATT 并且您的电话号码是 786-262-8344,则发送至 [email protected] 的电子邮件将免费向您发送带有电子邮件主题/正文的短信。这种技术几乎可以免费覆盖所有美国用户。显然,根据您的应用程序的需要,这可能是不可能/足够/不希望的,但这是一个需要注意的选项。
回答by James B
Your main option for sending SMS messages is using an existing SMS provider. In my experience (which is extensive with SMS messaging web applications), you will often find that negotiating with different providers is the best way to get the best deal for your application.
发送 SMS 消息的主要选项是使用现有的 SMS 提供商。根据我的经验(在 SMS 消息 Web 应用程序方面非常广泛),您经常会发现与不同的提供商协商是为您的应用程序获得最佳交易的最佳方式。
Different providers often offer different services, and different features. My favourite provider, and indeed, the one that has happily negotiated with me for lower rates in the past, is TM4B (http://www.tm4b.com). These guys have excellent rates, cover a huge proportion of the globe, and have excellent customer service.
不同的提供商通常提供不同的服务和不同的功能。我最喜欢的提供商,事实上,过去曾与我愉快地协商降低费率的提供商是 TM4B ( http://www.tm4b.com)。这些人的价格非常优惠,覆盖全球的大部分地区,并提供出色的客户服务。
Below is some code extracted (and some parts obfuscated) from one of my live web applications, for sending a simple message via their API:
下面是从我的一个实时 Web 应用程序中提取的一些代码(以及一些被混淆的部分),用于通过它们的 API 发送一条简单的消息:
require_once("tm4b.lib.php");
$smsEngine = new tm4b();
// Prepare the array for sending
$smsRequest["username"] = "YOURUNAME";
$smsRequest["password"] = "YOURPWORD";
$smsRequest["to"] = "+441234554443";
$smsRequest["from"] = "ME!";
$smsRequest["msg"] = "Hello, test message!";
// Do the actual sending
$smsResult = $smsEngine->ClientAPI($smsRequest);
// Check the result
if( $smsResult['status'] == "ok" ) {
print "Message sent!";
} else {
print "Message not sent.";
}
Many other providers that I've used in the past, have very similar interfaces, and all are really competitive when it comes to pricing. You simply have to look around for a provider that suits your needs.
我过去使用过的许多其他供应商都有非常相似的界面,而且在定价方面都非常具有竞争力。您只需四处寻找适合您需求的提供商。
In regard to cost, you're looking at prices ranging from a few pence/cents for most Western countries (prices are a little bit higher for most third-world countries, though, so beware). Most providers you will have to pay in bulk, if you want decent rates from them, but they'll often negotiate with you for 'smaller-than-usual' batches. Most providers do offer a post-pay option, but only when you've successfully completed a few transactions with them... others offer it from the start, but the prices are extortionate.
在成本方面,大多数西方国家的价格从几便士/美分不等(不过,大多数第三世界国家的价格略高,所以要当心)。如果您想从他们那里获得不错的价格,您将不得不批量支付大多数供应商,但他们通常会与您协商“比平时少”的批次。大多数供应商确实提供后付款选项,但只有当您与他们成功完成一些交易时……其他供应商从一开始就提供它,但价格过高。
回答by sblom
Send only, but cheap and easy
只发送,但便宜又容易
The simplest way is definitely using the email hack that @Paolo Bergantinomentioned above. It's easy to ask your users to type in their phone number and select their carrier from a list. It's also easy, on absolutely any development platform, to send email once you have the user's info.
最简单的方法肯定是使用@ Paolo Bergantino上面提到的电子邮件黑客。让您的用户输入他们的电话号码并从列表中选择他们的运营商很容易。在获得用户信息后,在任何开发平台上发送电子邮件也很容易。
There are two very important limitations that I've discovered with that approach, however:
但是,我发现这种方法有两个非常重要的限制:
- The first is that the cellular carriers all prioritize SMS messages sent through their email gateways below other SMS traffic. Probably because they aren't getting paid by the sender for these. Don't use this method if minimizing latency is important to you.
- The second is that especially in this modern era of portable phone numbers, users will switch carriers from time to time, and will almost certainly forget to tell you. If you need to be able to reliably deliver SMS messages to the same people a year or two from now, this method will begin to fail.
- 第一个是蜂窝运营商都将通过其电子邮件网关发送的 SMS 消息优先于其他 SMS 流量。可能是因为他们没有收到发件人的报酬。如果最小化延迟对您很重要,请不要使用此方法。
- 第二,特别是在这个手机号码的现代时代,用户会时不时地切换运营商,而且几乎肯定会忘记告诉你。如果您需要能够在一两年后可靠地向同一个人发送 SMS 消息,这种方法将开始失败。
Send and receive for cheap
以便宜的价格发送和接收
If you're trying to set your site up to send and receiveSMS messages on a budget, you can use a service such as TextMarks. TextMarks lets you pick a keyword for your service that allows users to route messages to you through TextMarks' shared short code, 41411. The catch here is that they reserve 20 characters in each message for short advertisements to pay for their services.
如果您尝试将站点设置为在预算范围内发送和接收SMS 消息,您可以使用诸如TextMarks 之类的服务。TextMarks 允许您为您的服务选择一个关键字,允许用户通过 TextMarks 的共享短代码 41411 将消息路由给您。这里的问题是他们在每条消息中保留 20 个字符用于短广告以支付他们的服务费用。
Professional quality
专业品质
If you require low latency, high reliability, and no advertising, you'll pretty much have to go through an SMS aggregator unless you're big enough to negotiate with each carrier individually.
如果您需要低延迟、高可靠性和无广告,除非您足够大,可以单独与每个运营商协商,否则您几乎必须通过 SMS 聚合器。
The biggest thing I've found to watch out for with SMS aggregators is that many of them are really set up to be marketing companies, not application hosts--they don't really understand using SMS as a channel through which users can interact with service providers. I've found that the aggregators that use the phrase "your campaign" rather than "your application" are the worst offenders. Stay away from them, and find an aggregator that understands your needs as an application developer.
我发现使用 SMS 聚合器需要注意的最重要的事情是,它们中的许多实际上是设置为营销公司,而不是应用程序主机——他们并不真正理解使用 SMS 作为用户可以与之交互的渠道服务供应商。我发现使用“您的活动”而不是“您的应用程序”这一短语的聚合器是最严重的违规者。远离它们,并找到一个了解您作为应用程序开发人员需求的聚合器。
回答by Tim Lytle
Twiliorecently released an API to send SMS messages. The api is rather simple, basic REST interface to send SMS, and a post returning document to respond.
Twilio最近发布了一个 API 来发送SMS 消息。api 是相当简单的,基本的REST 接口来发送 SMS和一个post 返回文档来响应。
回答by Jarod Reyes
Hi my name is Jarod and I work for Twilio.com so I am a little biased. But with that said, it is incredibly easy to send an SMS from your PHP web application using the Twilio REST API. Here is a simple example:
大家好,我叫 Jarod,我在 Twilio.com 工作,所以我有点偏见。但话虽如此,使用Twilio REST API从 PHP Web 应用程序发送 SMS 非常容易。这是一个简单的例子:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "{{ account_sid }}";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
$client->account->messages->sendMessage("+14158141829", "+14159352345", "Hi Shyju, Sorry it took me so long to get back to you. <3 The Internet.");
回答by Tony
If you know the carrier, you are golden. Most have email gateways. If not you can use Clickatell API which costs about $0.04 per message. I am looking into a hack now where you would use a GSM modem and your individual cell phone plan with unlimited SMS. This could save a lot of money if it works.
如果您了解运营商,那么您就是黄金。大多数都有电子邮件网关。如果没有,您可以使用 Clickatell API,每条消息的成本约为 0.04 美元。我现在正在研究一个黑客,你可以使用 GSM 调制解调器和你的个人手机计划,并提供无限制的短信。如果它有效,这可以节省很多钱。
回答by Dylan Beattie
We use a commercial solution called TextAnywherefor this.
为此,我们使用名为TextAnywhere的商业解决方案。
For a small fee (a few pence per SMS), they give you a Web service (plus APIs for .NET, ASP, Java, C++, etc.). It's easy and it works, although it's not free.
只需支付少量费用(每条短信几便士),他们就会为您提供 Web 服务(以及用于 .NET、ASP、Java、C++ 等的 API)。虽然它不是免费的,但它很容易并且有效。
At its most basic, it's as simple as making a URL request with the number and the message text in the QueryString, and their server does the rest for you.
在最基本的情况下,它就像使用 QueryString 中的数字和消息文本发出 URL 请求一样简单,他们的服务器会为您完成剩下的工作。
回答by user3144832
If you are willing to invest in a android smart phone you can set up your own SMS gateway that comes out cheaper in the end.
如果您愿意投资安卓智能手机,您可以设置自己的短信网关,最终价格会更便宜。
I use SMS GATEWAY MEwhich is a free android app you can send a message like this:
我使用SMS GATEWAY ME,这是一个免费的 Android 应用程序,您可以发送这样的消息:
$URL = "http://v2.smsgateway.me/API/Send/Single.php";
$postdata = http_build_query(
array(
'Username' => "[email protected]",
'Password' => "password",
'Number' => "+447791064782",
'Message' => "Hello World!",
)
);
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$context = stream_context_create($opts);
$result = file_get_contents($URL, false, $context);
There is a documentation on their site that tells you how to accept incoming messages as well.
他们网站上有一个文档,告诉您如何接受传入的消息。
回答by Michael
dktext not only allows you to send bult text messages to requesting customers but the will soon be providing google voice integration to use the same system with your google voice account
dktext 不仅允许您向提出请求的客户发送 bult 文本消息,而且很快将提供谷歌语音集成以使用与您的谷歌语音帐户相同的系统
回答by george
To send SMS from a web application you need to connect your application to SMS Gateway. Most SMS gateways provide external API which can be used to do that. They usually have documentation which you can use to find out how to integrate SMS notification in your PHP code. Unfortunately there are no reliable free sms service provides so you have to pay for this sms service. You can check http://www.phpjabbers.com/web-sms/which seems to work a lot easy. Their integration code is pretty simple:
要从 Web 应用程序发送 SMS,您需要将应用程序连接到 SMS Gateway。大多数 SMS 网关提供可用于执行此操作的外部 API。他们通常有文档,您可以使用这些文档来了解如何将 SMS 通知集成到您的 PHP 代码中。不幸的是,没有可靠的免费短信服务提供,因此您必须为此短信服务付费。您可以查看http://www.phpjabbers.com/web-sms/,这似乎很容易。他们的集成代码非常简单:
<?php
$SMSLIB["phone"] = '44111222333'; // your phone number
$SMSLIB["key"] = 'abcdefghijklmnopqrs'; // your personal API code
include("smslib.php"); // we will provide you with smslib.php file
sendSMS("test message", $SMSLIB["phone"]); // function which sends the message
?>

