如何使用SMSLib发送短信

时间:2014-01-13 11:31:20

标签: java maven sms sms-gateway smslib

我正在尝试使用SMSLib和USB GSM调制解调器发送短信。我在Maven项目中这样做,我在pom.xml中有以下依赖项:

        <dependency>
            <groupId>org.smslib</groupId>
            <artifactId>smslib</artifactId>
            <version>dev-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.rxtx</groupId>
            <artifactId>rxtx</artifactId>
            <version>2.1.7</version>
        </dependency>

        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.1</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.jsmpp</groupId>
            <artifactId>jsmpp</artifactId>
            <version>2.1.0</version>
        </dependency>

我的java代码如下:

Service.getInstance().start();
        Modem gateway = new Modem("ZTE", "COM5", "19200", "0000", "0000", "9800005000");        
        MsIsdn msIsdn = new MsIsdn("9841252521");
        gateway.setSmscNumber(msIsdn);
        try {
           Service.getInstance().registerGateway(gateway);
           OutboundMessage outboundMsg = new OutboundMessage(msIsdn.getAddress(), "Hello there!");
           Service.getInstance().send(outboundMsg);
        } finally {
            gateway.stop();
            Service.getInstance().stop();
        }

SMSlib的文档说明我需要定义一个像

这样的网关
XYZ g = new XYZ("my-username", "my-password");

根据我的理解,我相信这应该是连接的调制解调器。我对此非常陌生,所以我无法真正理解“调制解调器”构造函数的参数在

中的用途
Modem gateway = new Modem(gatewayId, address, port, simPin, simPin2, smscNumber,memoryLocations)

OR

Modem gateway = new Modem(gatewayId, parms)

我如何知道参数gatewayId,address,simPin,simPin2和memroyLocations?

目前,我在运行代码时遇到以下错误:

exception

java.lang.reflect.InvocationTargetException
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
......

root cause

java.lang.NoClassDefFoundError: Could not initialize class org.smslib.Service
    com.mail.utility.SendSmsUtility.sendSMS(SendSmsUtility.java:11)
    com.mail.action.SendSmsAction.sendSms(SendSmsAction.java:11)
......

0 个答案:

没有答案