如何用Java发送短信
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2570410/
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
How to send SMS in Java
提问by Jigar Joshi
What are the possible ways to send and receive sms from Java application?
从 Java 应用程序发送和接收短信的可能方式有哪些?
How?
如何?
回答by Steven A. Lowe
if all you want is simple notifications, many carriers support SMS via email; see SMS through E-Mail
回答by John Sheehan
(Disclaimer: I work at Twilio)
(免责声明:我在 Twilio 工作)
Twilio offers a Java SDKfor sending SMS via the Twilio REST API.
Twilio 提供了一个 Java SDK,用于通过 Twilio REST API 发送短信。
回答by Marouane Gazanayi
There is an API called SMSLib, it's really awesome. http://smslib.org/
有一个叫做 SMSLib 的 API,它真的很棒。 http://smslib.org/
Now you have a lot of Saas providers that can give you this service using their APIs
现在你有很多 Saas 提供商可以使用他们的 API 为你提供这项服务
Ex: mailchimp, esendex, Twilio, ...
例如:mailchimp、esendex、Twilio、...
回答by Ravi Parekh
回答by dkamins
TextMarks gives you access to its shared shortcode to send and receive text messages from your app via their API. Messages come from/to 41411 (instead of e.g. a random phone# and unlike e-mail gateways you have the full 160 chars to work with).
TextMarks 允许您访问其共享短代码,以通过其 API 从您的应用程序发送和接收文本消息。消息来自/发送到 41411(而不是例如随机电话#,并且与电子邮件网关不同,您可以使用完整的 160 个字符)。
You can also tell people to text in your keyword(s) to 41411 to invoke various functionality in your app. There is a JAVA API client along with several other popular languages and very comprehensive documentation and technical support.
您还可以告诉人们将您的关键字中的文本发送到 41411 以调用您应用中的各种功能。有一个 JAVA API 客户端以及其他几种流行语言以及非常全面的文档和技术支持。
The 14 day free trial can be easily extended for developers who are still testing it out and building their apps.
对于仍在测试和构建应用程序的开发人员,可以轻松延长 14 天免费试用期。
Check it out here: TextMarks API Info
在这里查看: TextMarks API 信息
回答by Alpesh Gediya
You can you LOGICA SMPP Java API for sending and Recieving SMS in Java application. LOGICA SMPP is well proven api in telecom application. Logica API also provide you with signalling capicity on TCP/IP connection.
您可以使用 LOGICA SMPP Java API 在 Java 应用程序中发送和接收 SMS。LOGICA SMPP 在电信应用中是经过充分验证的 api。Logica API 还为您提供 TCP/IP 连接的信令容量。
You can directly integrate with various telecom operator accross the world.
您可以直接与世界各地的各种电信运营商进行整合。
回答by Eng.Fouad
The best SMS API I've seen in Java is JSMPP. It is powerful, easy to use, and I used it myself for an enterprise-level application (sending over 20K SMS messages daily).
我在 Java 中见过的最好的 SMS API 是 JSMPP。它功能强大,易于使用,我自己将它用于企业级应用程序(每天发送超过 20K 条短信)。
This API created to reduce the verbosity of the existing SMPP API. It's very simple and easy to use because it hides the complexity of the low level protocol communication such as automatically enquire link request-response.
创建此 API 是为了减少现有 SMPP API 的冗长。它非常简单易用,因为它隐藏了低级协议通信的复杂性,例如自动查询链接请求-响应。
I've tried some other APIs such as Ozeki, but most of them either is commercial or has limitation in its throughput (i.e can't send more than 3 SMS messages in a second, for example).
我尝试过其他一些 API,例如 Ozeki,但它们中的大多数要么是商业化的,要么在其吞吐量方面有限制(例如,例如,一秒钟内不能发送超过 3 条 SMS 消息)。
回答by Choulli ILyass
There are two ways : First : Use a SMS API Gateway which you need to pay for it , maybe you find some trial even free ones but it's scarce . Second : To use AT command with a modem GSM connected to your laptop . that's all
有两种方法: 第一:使用需要付费的SMS API Gateway,也许您会找到一些试用甚至免费的但很少。第二:使用 AT 命令与调制解调器 GSM 连接到您的笔记本电脑。就这样
回答by DenisD
It depends on how you're going to work and who your provider is.
这取决于您将如何工作以及您的提供者是谁。
If you work with a sms-gateway company you'll probably work through SMPP protocol (3.4 is still the most common), then have a look on OpenSMPP and jSMPP. These are powerful libs to work with SMPP.
如果您与 sms-gateway 公司合作,您可能会使用 SMPP 协议(3.4 仍然是最常见的),然后查看 OpenSMPP 和 jSMPP。这些是与 SMPP 一起使用的强大库。
If you're going to work with your own hardware (f.e. a gsm-modem) the easiest way to send messages is through AT commands, they differ depends on the model, so, you should find out what AT commands is supported by your modem. Next, if your modem has an IP and open to connection, you can send commands through java socket
如果您要使用自己的硬件(例如 gsm-modem)发送消息的最简单方法是通过 AT 命令,它们因型号而异,因此,您应该了解您的调制解调器支持哪些 AT 命令. 接下来,如果您的调制解调器有 IP 并且可以连接,您可以通过 java socket 发送命令
Socket smppSocket = new Socket("YOUR_MODEM_IP", YOUR_MODEM_PORT);
DataOutputStream os = new DataOutputStream(smppSocket.getOutputStream());
DataInputStream is = new DataInputStream(smppSocket.getInputStream());
os.write(some_byte_array[]);
is.readLine();
Otherwise you'll work through a COM port, but the method is the same (sending AT commands), you can find more information how to work with serial ports here.
否则,您将通过 COM 端口工作,但方法是相同的(发送 AT 命令),您可以在此处找到有关如何使用串行端口的更多信息。