没有网关定义SMSlib

时间:2014-01-19 07:21:12

标签: java sms-gateway smslib

我正在尝试使用SMSlib使用中兴MF631 usb调制解调器发送短信。这是我的代码:

        Service.getInstance().startService();
        SerialModemGateway gateway = new SerialModemGateway("modem.com5","COM5", 115200, "ZTE", "MF631");

        gateway.setInbound(true);
        gateway.setOutbound(true);
        gateway.setSimPin("0000");
        gateway.setSmscNumber("+9779800009000");

        try {

           Service.getInstance().addGateway(gateway);
           OutboundMessage outboundMsg = new OutboundMessage("+9779843669921", "Hello there!");
           Service.getInstance().sendMessage(outboundMsg);
        } finally {
            gateway.stopGateway();
            Service.getInstance().removeGateway(gateway);
            Service.getInstance().stopService();
        }

当我运行我的代码时,我收到以下错误:

org.smslib.SMSLibException: No gateways are defined.
    at org.smslib.Service.startService_Internal(Service.java:295)
    at org.smslib.Service.startService(Service.java:229)
    at org.smslib.Service.startService(Service.java:196)
    at com.mail.utility.SendSmsUtility.sendSMS(SendSmsUtility.java:10)
    at com.mail.action.SendSmsAction.sendSms(SendSmsAction.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

1 个答案:

答案 0 :(得分:0)

我认为在你开始服务之前你错过了这样的东西:

Service.getInstance().addGateway(gateway);

这是SMSlib example.