【问题标题】:smslib not sending sms why?smslib 不发送短信为什么?
【发布时间】:2015-08-11 00:09:33
【问题描述】:

我正在尝试使用 smslib 发送短信,但它没有发送消息,有人可以指导我吗?

这是我的代码:

import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

public class SendMessage
{
    public void doIt() throws Exception
    {
        OutboundNotification outboundNotification = new OutboundNotification();
        System.out.println("Example: Send message from a serial gsm modem.");
        System.out.println(Library.getLibraryDescription());
        System.out.println("Version: " + Library.getLibraryVersion());
        SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM4", 115200, "Huawei", "");
        gateway.setInbound(true);
        gateway.setOutbound(true);
        gateway.setSimPin("0000");
        // Explicit SMSC address set is required for some modems.
        // Below is for VODAFONE GREECE - be sure to set your own!
        gateway.setSmscNumber("+919825068000");
        Service.getInstance().setOutboundMessageNotification(outboundNotification);
        Service.getInstance().addGateway(gateway);
        Service.getInstance().startService();
        System.out.println();
        System.out.println("Modem Information:");
        System.out.println("  Manufacturer: " + gateway.getManufacturer());
        System.out.println("  Model: " + gateway.getModel());
        System.out.println("  Serial No: " + gateway.getSerialNo());
        System.out.println("  SIM IMSI: " + gateway.getImsi());
        System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
        System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
        System.out.println();
        // Send a message synchronously.
        OutboundMessage msg = new OutboundMessage("+524747388616", "que onda como andas!");
        Service.getInstance().sendMessage(msg);
        System.out.println(msg);
        // Or, send out a WAP SI message.
        //OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000",  new URL("http://www.smslib.org/"), "Visit SMSLib now!");
        //Service.getInstance().sendMessage(wapMsg);
        //System.out.println(wapMsg);
        // You can also queue some asynchronous messages to see how the callbacks
        // are called...
        //msg = new OutboundMessage("309999999999", "Wrong number!");
        //srv.queueMessage(msg, gateway.getGatewayId());
        //msg = new OutboundMessage("308888888888", "Wrong number!");
        //srv.queueMessage(msg, gateway.getGatewayId());
        System.out.println("Now Sleeping - Hit <enter> to terminate.");
        System.in.read();
        Service.getInstance().stopService();
    }

    public class OutboundNotification implements IOutboundMessageNotification
    {
        public void process(AGateway gateway, OutboundMessage msg)
        {
            System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
            System.out.println(msg);
        }
    }

    public static void main(String args[])
    {
        SendMessage app = new SendMessage();
        try
        {
            app.doIt();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

我的结果:

Example: Send message from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem or other supported gateways.
This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
Version: 3.5.1

Modem Information:
  Manufacturer: Nokia Corporation
  Model: Nokia Internet Stick CS-10
  Serial No: 359340022861915
  SIM IMSI: ** MASKED **
  Signal Level: -53 dBm
  Battery Level: 0%


===============================================================================
<< OutboundMessage >>
-------------------------------------------------------------------------------
 Gateway Id: *
 Message Id: 0
 Message UUID: e30f84ad-b083-4956-85ef-16dc89020769
 Encoding: 7-bit
 Date: Fri Mar 09 13:15:52 CST 2012
 SMSC Ref No: null
 Recipient: 524747388616
 Dispatch Date: null
 Message Status: FAILED
 Failure Cause: UNKNOWN
 Validity Period (Hours): -1
 Status Report: false
 Source / Destination Ports: -1 / -1
 Flash SMS: false
 Text: que onda como andas!
 PDU data: F17A19F47693C3A0F1BBFD0685DDE4F03C04
 Scheduled Delivery: null
===============================================================================

Now Sleeping - Hit <enter> to terminate.

【问题讨论】:

  • +52 似乎表明您正在将该消息发送给墨西哥号码。您是否按照来源中的评论告诉您更改了 SMSC 号码,或者您实际上有希腊沃达丰 SIM 卡? (虽然 +91 似乎暗示印度......)
  • 其实我根据一个有我的调制解调器gsm的程序更改了smsc,程序打印模型名称和所有内容,只是不发送sms
  • 您是否已经通过提供的软件成功地使用该棒发送了一条短信 - 以防硬件或该 SIM 卡上的该功能被禁用?
  • 您应该为 smslib 启用 log4j 调试级别。日志中可能有线索...
  • 我已经用诺基亚软件发送消息,并且我尝试过其他软件 gsm com 演示并且我已经用那个程序发送消息

标签: java sms smslib


【解决方案1】:

这个例子有额外的关于 SMSC 号码的代码行。我玩过同一个库,在我的代码中没有任何 SMSC - 在我的代码的任何一行。

这是一个建议,“如果需要”,我当然相信摆脱它可以解决您的问题。你很可能不知道你到底要穿什么,所以最好把它排除在外。然后调制解调器不会尝试手动执行此路由到给定号码,但它可以通过 SIM 卡上的 SIM 设置知道的正确路由。

我要检查的另一件事是调制解调器确实从 COM4 端口应答。虽然现在它似乎这样做了,因为读取了信号强度。但请始终检查这一点,因为服务器的每次启动都可以将设备映射到不同的端口。我至少在 Linux 端遇到过这种问题。

【讨论】:

    【解决方案2】:

    也许您(还)没有足够注意SerialModemGateway 构造函数参数,因为您在使用诺基亚设备时将“华为”作为供应商。该参数并不重要,但波特率很重要。根据SMSlib documentation 的说法,大多数设备只能在预设/uniq 波特率下正常工作。

    建议你打开其他软件设置来获取或确认你使用过的参数:

    • 波特率
    • 网关 SMSC 号码 - 根据诺基亚用户指南,可能来自连接历史记录菜单

    当您从华为示例中获取代码时,此示例设置网关 SMSC 号码,但此参数对于大多数设备应该是可选的,只有华为设备可能需要它。在没有gateway.setSmscNumber 的情况下尝试运行!

    我还邀请您使用 Portmon 监控串行端口流量,并在此处和 SMSlib 论坛上报告以获得支持。

    最后,您应该向 SMSlib 维护者询问有关您设备的选项,因为它在 compatibility list 中(尚未)

    【讨论】:

      【解决方案3】:

      以下是我使用和测试的示例代码。您可以重复使用它。

      package com.stackoverflow.smstest;
      
      import java.net.URL;
      
      import org.smslib.AGateway;
      import org.smslib.IOutboundMessageNotification;
      import org.smslib.Library;
      import org.smslib.OutboundMessage;
      import org.smslib.OutboundWapSIMessage;
      import org.smslib.Service;
      import org.smslib.modem.SerialModemGateway;
      
      public class Main {
      
          public void sendMessage() throws Exception {
              OutboundNotification outboundNotification = new OutboundNotification();
              System.out.println("Sample of Send message from a serial gsm modem.");
              System.out.println(Library.getLibraryDescription());
              System.out.println("Version: " + Library.getLibraryVersion());
              SerialModemGateway gateway = new SerialModemGateway("modem.com4",
                      "COM4", 57600, "Huawei", "E160");
              gateway.setInbound(false);
              gateway.setOutbound(true);
              // gateway.setSimPin("");
              Service.getInstance().setOutboundMessageNotification(
                      outboundNotification);
              Service.getInstance().addGateway(gateway);
              Service.getInstance().startService();
              System.out.println();
              System.out.println("Modem Information:");
              System.out.println("  Manufacturer: " + gateway.getManufacturer());
              System.out.println("  Model: " + gateway.getModel());
              System.out.println("  Serial No: " + gateway.getSerialNo());
              System.out.println("  SIM IMSI: " + gateway.getImsi());
              System.out.println("  Signal Level: " + gateway.getSignalLevel()
                      + " dBm");
              System.out.println("  Battery Level: " + gateway.getBatteryLevel()
                      + "%");
      
              // Send a message synchronously.
              OutboundMessage msg = new OutboundMessage("+94123456789",
                      "SMS test: sample message from StackOverflow");
      
              Service srvice = Service.getInstance();
              // Service.getInstance().sendMessage(msg);
              System.out.println(msg);
              // Or, send out a WAP SI message.
              OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("+94123456789",
                      new URL("http://stackoverflow.com/"),
                      "WAP test: sample message from StackOverflow!");
              // gateway.setFrom("chandpriyankara");
              // wapMsg.setFrom("chandpriyankara");
              srvice.queueMessage(wapMsg);
      
              Service.getInstance().stopService();
          }
      
          /**
           * Outbound Message informations handler
           * 
           * @author chandpriyankara
           * 
           */
          public class OutboundNotification implements IOutboundMessageNotification {
              public void process(AGateway gateway, OutboundMessage msg) {
                  System.out.println("Outbound handler called from Gateway: "
                          + gateway.getGatewayId());
                  System.out.println(msg);
              }
          }
      
          public static void main(String args[]) {
              Main app = new Main();
              try {
                  app.sendMessage();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      

      【讨论】:

      • 我试试你的代码,我得到了这个异常 java.lang.UnsupportedClassVersionError: org/smslib/IOutboundMessageNotification : Unsupported major.minor version 51.0
      • 好像有些组件版本不匹配,具体我说不清楚,请重新检查是否使用了相同jar和dll的源代码。
      猜你喜欢
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多