2

I was just trying to send SMS using java as I require it in my Web App.But for testing purpose I am the code that is described in this site And the code is as follows

package logic;

import com.harshadura.gsm.smsdura.GsmModem;

/**
 * @author     : Harsha Siriwardena  <harshadura@gmail.com>
 * @copyrights : www.Durapix.org     <http://www.durapix.org>
 * @license    : GNU GPL v3          <http://www.gnu.org/licenses/>
 *
 * Example on how to simply send a SMS using the smsdura API Wrapper.
 */
public class TestSMS {

    private static String port = "COM3"; //Modem Port.
    private static int bitRate = 115200; //this is also optional. leave as it is.
    private static String modemName = "ZTE"; //this is optional.
    private static String modemPin = "0000"; //Pin code if any have assigned to the modem.
    private static String SMSC = "+9477000003"; //Message Center Number ex. Mobitel

    public static void main(String[] args) throws Exception {
        GsmModem gsmModem = new GsmModem();
        GsmModem.configModem(port, bitRate, modemName, modemPin, SMSC);
        gsmModem.Sender("+94712244555", "Test Message"); // (tp, msg)
    }
}

When I tried to run this,I am getting this error

-----------------------------
*** SMS-DURA - GSM MODEM SMS API WRAPPER ***
www.harshadura.com
-----------------------------
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
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 "main" org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException
    at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102)
    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:276)

Please anybody tell me how to fix this issue

4

4 回答 4

2

基本上你的程序无法找到端口,使用

org.smslib.helper.CommPortIdentifier

从端口列表中找到正确的 COM 端口。

于 2013-10-15T06:43:40.930 回答
1

我知道这不是您对 SO 期望的那种答案,但考虑到替代方案,我认为总比没有好。

a) 您的图书馆报告您的调制解调器未连接。
b) 您不知道如何检查您的调制解调器是否已连接。

虽然与公司没有任何关系,但我过去使用nexmo取得了巨大成功。

如果这是您的应用程序的必需品,我强烈建议您通过 API 路线解决问题,这将为您节省大量工作。

有几家公司提供此服务,并且使用或多或少是直截了当的,您只需格式化 URL 以将参数传递回公司。Nexmo 示例:

// by calling a crafted url you are requesting the company to send the sms for you 
urlString = "https://rest.nexmo.com/sms/json?api_key={api_key}&api_secret={api_secret}&from=MyCompany20&to=447525856424&text=helloworld";
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream()

Nexmo 并不是唯一提供此服务的公司。他们是我唯一亲身体验过的人。

于 2013-10-15T06:44:44.633 回答
0

将 API(comm.jar),dll(win32com),properties 文件(javax.comm) 复制到

1)如果您使用的是 Net Beans 工具

C:\Program Files\Java\jdk1.7.0\jre\lib\ext

C:\Program Files\Java\jdk1.7.0\jre\bin

2)如果您使用的是 Eclipse 工具

C:\Program Files\Java\jre7\lib\ext

C:\Program Files\Java\jre7\bin

根据您下载此项目的 Code projects.com 中给出的说明。

另一种方式如果你可以配置你的工具然后去做,逻辑是API应该在你的运行时JVM(jre)下。并确保您提供的端口应该是免费的,其他应用程序不应在其上运行。

于 2014-01-24T05:27:02.500 回答
0

是的,我在 Harshadura 的 SMS 包装器中也遇到了这个例外。它们可能是你没有做的两件事

  • 您没有在代码中声明任何附加程序,因此在代码的开头只需键入这个简单的代码来声明附加程序。

    package logic;
    
    import com.harshadura.gsm.smsdura.GsmModem;
    
    /**
     * @author     : Harsha Siriwardena  <harshadura@gmail.com>
     * @copyrights : www.Durapix.org     <http://www.durapix.org>
     * @license    : GNU GPL v3          <http://www.gnu.org/licenses/>
     *
     * Example on how to simply send a SMS using the smsdura API Wrapper.
     */
    public class TestSMS {
    
    private static String port = "COM3"; //Modem Port.
    private static int bitRate = 115200; //this is also optional. leave as it is.
    private static String modemName = "ZTE"; //this is optional.
    private static String modemPin = "0000"; //Pin code if any have assigned to the modem.
    private static String SMSC = "+9477000003"; //Message Center Number ex. Mobitel
    
    public static void main(String[] args) throws Exception {
        BasicConfigurator.configure();//Declares appenders
        GsmModem gsmModem = new GsmModem();
        GsmModem.configModem(port, bitRate, modemName, modemPin, SMSC);
        gsmModem.Sender("+94712244555", "Test Message"); // (tp, msg)
    }    }
    
  • 识别 GSM 调制解调器的端口。您可以通过转到“我的电脑”图标单击“管理”>“设备管理器”>“调制解调器”并识别调制解调器的端口来解决此问题。

您识别的端口然后将其写在您的代码上。String port="MyPort";

于 2018-10-26T04:18:18.547 回答