【问题标题】:send sms in java在java中发送短信
【发布时间】:2012-04-09 08:22:51
【问题描述】:

我有一个 java 类,用于通过 java web 应用程序向移动设备发送 SMS。但我没有得到以下条款,我怎样才能得到这些?

      String username = "MySMSUsername";// how to know MySMSUsername?
      String password = "MyPassword";//how to know password?
      String smtphost = "MySMSHost.com";//how to know SMSHost?
      String compression = "My SMS Compression Information";
      String from = "mySMSUsername@MySMSHost.com";
      String to = "PhoneNumberToText@sms.MySMSHost.com";
      String body = "Hello SMS World!";

完整的源代码:How to send SMS using Java

【问题讨论】:

    标签: java web-applications sms sms-gateway


    【解决方案1】:

    您指的代码只是使用 java 程序发送电子邮件。而不是使用 java 发送短信。

    String username = "saroj"; for example
    String password = "saroj123";
    String smtphost = "your e-mail server host name"; you can IP address of the mail server
    String compression = "this is the subject of your e-mail"; 
    String from = "saroj@saroj.com";
    String to = "yourfreind@abc.com";
    String body = "This is the actual message content";
    

    使用java发送邮件时需要所有这些信息,而不是发送短信。为了发送短信,您需要配置短信网关。

    【讨论】:

    • 但是如何配置 SMS 网关?请给我一个链接,我可以在其中找到所有这些东西,尤其是 SMS 网关
    【解决方案2】:

    要从您的应用程序(网络/桌面)发送短信,您需要以下任一解决方案 1.编写代码并附加GSM设备(电话/调制解调器) 2. 购买 api 并将其集成到您的应用程序中 3. 购买和Email2SMS api然后集成

    上面的代码似乎使用了任何 APi,因此您可以从任何供应商处购买 api,您可以 google 搜索 bulksms,您会找到您所在地区的 api 供应商,根据您的需要关注特定的 api 并广告,

    以上所有细节将由他们提供。

    【讨论】:

    • 好的,所以这是一个漫长的过程,而且我必须为这项服务花钱
    • 是的,您可能会获得 10-20 等演示消息的试用 api,但对于商业用途,您可能需要付费 :)
    【解决方案3】:

    您必须使用某些 SMS 提供商 API,否则您将无法获取这些信息。 SMS 提供商将为您提供您的订阅用户名=MySMSUsername、密码、url 或 api 以通过 Web 服务、HTTP 等进行调用,From to 和 body 将由用户通过 Web 应用程序提供。

    【讨论】:

      【解决方案4】:

      如前所述,您必须使用提供程序。 SMPP 协议需要一个 SMS 网关,并且没有免费的 SMS 网关(据我所知)。然而,一旦你找到了像SmsGlobal 这样的短信网关(有很多提供商),你可以使用Ogham 库为例。发送 SMS 的代码很容易编写(它会自动处理字符编码和消息拆分)。真正的 SMS 使用 SMPP 协议(​​标准 SMS 协议)或通过提供商发送。 您甚至可以使用 SMPP 服务器在本地测试您的代码,以在支付真正的 SMS 发送费用之前检查您的 SMS 的结果。

      package fr.sii.ogham.sample.standard.sms;
      
      import java.util.Properties;
      
      import fr.sii.ogham.core.builder.MessagingBuilder;
      import fr.sii.ogham.core.exception.MessagingException;
      import fr.sii.ogham.core.service.MessagingService;
      import fr.sii.ogham.sms.message.Sms;
      
      public class BasicSample {
          public static void main(String[] args) throws MessagingException {
              // [PREPARATION] Just do it once at startup of your application
              
              // configure properties (could be stored in a properties file or defined
              // in System properties)
              Properties properties = new Properties();
              properties.setProperty("ogham.sms.smpp.host", "<your server host given by the provider>");                                 // <1>
              properties.setProperty("ogham.sms.smpp.port", "<your server port given by the provider>");                                 // <2>
              properties.setProperty("ogham.sms.smpp.system-id", "<your server system ID given by the provider>");                       // <3>
              properties.setProperty("ogham.sms.smpp.password", "<your server password given by the provider>");                         // <4>
              properties.setProperty("ogham.sms.from.default-value", "<phone number to display for the sender>");  // <5>
              // Instantiate the messaging service using default behavior and
              // provided properties
              MessagingService service = MessagingBuilder.standard()                                               // <6>
                      .environment()
                          .properties(properties)                                                                  // <7>
                          .and()
                      .build();                                                                                    // <8>
              // [/PREPARATION]
              
              // [SEND A SMS]
              // send the sms using fluent API
              service.send(new Sms()                                                                               // <9>
                              .message().string("sms content")
                              .to("+33752962193"));
              // [/SEND A SMS]
          }
      }
      

      还有很多其他的featuressamples / spring samples

      【讨论】:

        猜你喜欢
        • 2011-02-03
        • 2020-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-04
        • 2016-11-27
        相关资源
        最近更新 更多