如何使用smslib通过USB调制解调器发送短信

时间:2013-12-02 10:26:56

标签: java sms

我想通过我的java应用程序使用usb调制解调器发送短信。我尝试过smslib但我无法完成任务。 我尝试使用以下代码.. 我也提到了所提到的外部配置.. 那么请你帮我在64位机器上使用smslib。

package sms;

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 Sms{
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", "COM39", 115200, "Huawei", "");
    gateway.setInbound(true);
    gateway.setOutbound(true);
    gateway.setSimPin("0000");
    gateway.setSmscNumber("+947100003");
    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("+94755466860", "Hello from SMSLib!");
    Service.getInstance().sendMessage(msg);
    System.out.println(msg);
    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[]){
    Sms app = new Sms();
    try{
        app.doIt();
    }
    catch (Exception e){
        e.printStackTrace();
    }
}
}

我收到以下错误

log4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "Thread-3" java.lang.ExceptionInInitializerError
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:69)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:277)
Caused by: java.lang.RuntimeException: CommPortIdentifier class not found
at org.smslib.helper.CommPortIdentifier.<clinit>(CommPortIdentifier.java:76)
... 4 more

0 个答案:

没有答案