首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

smslib短信猫发短信解决办法

2012-01-05 
smslib短信猫发短信硬件是短信猫一个,COM口用超级终端可以发送成功及用相关软件也能发送成功。可在放在myEc

smslib短信猫发短信
硬件是短信猫一个,COM口用超级终端可以发送成功及用相关软件也能发送成功。可在放在myEclipse中出错。已做了环境的配置,在smslib\dist\lib目录下找到smslib-3.3.0b2.jar,放入工程lib中,再把javacomm20-win32.zip解开,里面的comm.jar需要放到工程lib下,javax.comm.properties放到%JAVA_HOME%/jre/lib下,win32com.dll放到%JAVA_HOME%/jre/bin下,具体代码如下:

Java code
import org.smslib.IOutboundMessageNotification;import org.smslib.Library;import org.smslib.OutboundMessage;import org.smslib.Service;import org.smslib.Message.MessageEncodings;import org.smslib.modem.SerialModemGateway;public class SendMessage{    public void doIt() throws Exception    {        Service srv;        OutboundMessage msg;        OutboundNotification outboundNotification = new OutboundNotification();        srv = new Service();        SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM1", 9600, "wavecom", "17254");//115200是波特率,一般为9600。可以通过超级终端测试出来        gateway.setInbound(true);        gateway.setOutbound(true);        gateway.setSimPin("0000");        gateway.setOutboundNotification(outboundNotification);        srv.addGateway(gateway);        srv.startService();        msg = new OutboundMessage("13418687205", "这个是用java发的中文短信!");        msg.setEncoding(MessageEncodings.ENCUCS2);//这句话是发中文短信必须的        srv.sendMessage(msg);        System.out.println("Now Sleeping - Hit <enter> to terminate.");        System.in.read();        srv.stopService();    }    public class OutboundNotification implements IOutboundMessageNotification    {        public void process(String gatewayId, OutboundMessage msg)        {            System.out.println("Outbound handler called from Gateway: " + gatewayId);            System.out.println(msg);        }    }    public static void main(String args[])    {        SendMessage app = new SendMessage();        try        {            app.doIt();        }        catch (Exception e)        {            e.printStackTrace();        }    }}

报如下错误:
Java code
org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException    at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)    at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)    at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)    at org.smslib.Service$1Starter.run(Service.java:227)


[解决办法]
ding yi xia
[解决办法]
学习中,等待高人出现
[解决办法]
jdk换1.6再试试看,感觉你java环境变量设置很乱,呵
[解决办法]
看情况像是comm.jar的问题,看看是不是JAR损坏或者是版本不对.
[解决办法]
哥们想知道你这个短信猫多少钱呀,怎么用,能在网站上用吗,比如说再网站上加个发短信的功能,他发送的成本有多高.收到信息的号码显示的是什么?
[解决办法]
会不会是你的myeclipse里的路径配置问题?你用myeclipse里面自带的配置试试~~~
[解决办法]
UP
[解决办法]
不懂..关注..
[解决办法]
探讨
哥们想知道你这个短信猫多少钱呀,怎么用,能在网站上用吗,比如说再网站上加个发短信的功能,他发送的成本有多高.收到信息的号码显示的是什么?

------解决方案--------------------



这个貌似和Eclipse 的配置没关系, 我忘了以前是怎么解决的, 让我想下啊 , 嘿嘿。。
[解决办法]

  你检查下javax.comm.properties放到%JAVA_HOME%/jre/lib下,win32com.dll放到%JAVA_HOME%/jre/bin下。smslib-3.3.0b2.jar和comm.jar,是

  否放入工程lib中。

  commons-net-1.4.1.jar 包你已经加到工程中去了。 再在你的工程中加入 commons-lang-2.4.jar 这个包试试。
[解决办法]
学习。。。。
[解决办法]
学习一下
[解决办法]
我也遇到了问题。我用的是JRE1.6,下载的smslib是3.3.3,
在用里面的ReadMessages的例子时,运行到this.srv = new Service();时就跳过去了,我跟踪了一下,SRV没有创建成功,
请客各位高手是为什么?代码如下:
[code=Java][/code]
package MainPackage;

import java.util.ArrayList;
import java.util.List;
import org.smslib.ICallNotification;
import org.smslib.IGatewayStatusNotification;
import org.smslib.IInboundMessageNotification;
import org.smslib.InboundMessage;
import org.smslib.Library;
import org.smslib.Service;
import org.smslib.AGateway.GatewayStatuses;
import org.smslib.AGateway.Protocols;
import org.smslib.InboundMessage.MessageClasses;
import org.smslib.Message.MessageTypes;
import org.smslib.modem.SerialModemGateway;

public class ReadMessages
{
Service srv;

public void doIt() throws Exception
{
// Define a list which will hold the read messages.
List<InboundMessage> msgList;

// Create the notification callback method for inbound & status report
// messages.
InboundNotification inboundNotification = new InboundNotification();

// Create the notification callback method for inbound voice calls.
CallNotification callNotification = new CallNotification();

//Create the notification callback method for gateway statuses.
GatewayStatusNotification statusNotification = new GatewayStatusNotification();

try
{
//System.out.println("Example: Read messages from a serial gsm modem.");
//System.out.println(Library.getLibraryDescription());
//System.out.println("Version: " + Library.getLibraryVersion());

// Create new Service object - the parent of all and the main interface
// to you.
this.srv = new Service();

// Create the Gateway representing the serial GSM modem.
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM1", 57600, "Nokia", "");

// Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
gateway.setProtocol(Protocols.PDU);

// Do we want the Gateway to be used for Inbound messages?
gateway.setInbound(true);

// Do we want the Gateway to be used for Outbound messages?
gateway.setOutbound(true);

// Let SMSLib know which is the SIM PIN.
gateway.setSimPin("0000");

// Set up the notification methods.
this.srv.setInboundNotification(inboundNotification);
this.srv.setCallNotification(callNotification);
this.srv.setGatewayStatusNotification(statusNotification);

// Add the Gateway to the Service object.
this.srv.addGateway(gateway);

// Similarly, you may define as many Gateway objects, representing
// various GSM modems, add them in the Service object and control all of them.

// Start! (i.e. connect to all defined Gateways)
this.srv.startService();

// Printout some general information about the modem.
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() + "%");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();

// Read Messages. The reading is done via the Service object and
// affects all Gateway objects defined. This can also be more directed to a specific
// Gateway - look the JavaDocs for information on the Service method calls.
msgList = new ArrayList<InboundMessage>();
this.srv.readMessages(msgList, MessageClasses.ALL);
for (InboundMessage msg : msgList)
System.out.println(msg);

// Sleep now. Emulate real world situation and give a chance to the notifications
// methods to be called in the event of message or voice call reception.
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
this.srv.stopService();
}
}

public class InboundNotification implements IInboundMessageNotification
{
public void process(String gatewayId, MessageTypes msgType, InboundMessage msg)
{
if (msgType == MessageTypes.INBOUND) System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId);
else if (msgType == MessageTypes.STATUSREPORT) System.out.println(">>> New Inbound Status Report message detected from Gateway: " + gatewayId);
System.out.println(msg);
try
{
// Uncomment following line if you wish to delete the message upon arrival.
// ReadMessages.this.srv.deleteMessage(msg);
}
catch (Exception e)
{
System.out.println("Oops!!! Something gone bad...");
e.printStackTrace();
}
}
}

public class CallNotification implements ICallNotification
{
public void process(String gatewayId, String callerId)
{
System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId);
}
}

public class GatewayStatusNotification implements IGatewayStatusNotification
{
public void process(String gatewayId, GatewayStatuses oldStatus, GatewayStatuses newStatus)
{
System.out.println(">>> Gateway Status change for " + gatewayId + ", OLD: " + oldStatus + " -> NEW: " + newStatus);
}
}

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

[解决办法]

这个问题需要注意下 jdk 的版本, 我使用的是 jdk 1.5.0.6 , 没有出现那样的问题了。
[解决办法]
支持楼主!
[解决办法]

你本机和服务器上的系统是不是一样的撒?
[解决办法]

在你的 工程lib 下加入 commons-net-1.4.1.jar , 你是加在 D:\Program Files\Java\jdk1.5.0_04\lib\commons-net-1.4.1.jar ,你是加在 

jdk 目录下的, 如果还是不行话参照下列条件:

To use SMSLib, you should install the following components:

SUN JDK 1.5 or newer. 
Java Communications Library. 
Apache ANT for building the sources. 
Simple logging facade for Java (slf4j). 


Apache Jakarta Commons - NET. 


官方用法路径:http://code.google.com/p/smslib/wiki/Installation

 相信楼主应该很快就可以解决, 注意几个重要 jar 包的用法, 在上面路径上已经说的很详细了, 其实只需要注意 Apache Jakarta Commons - NET. 的用法就可以了, 我没按照官方的做法来做。 呵呵..... Good Luck!!
[解决办法]
估计90%是comm.jar所对应的动态链节库win32comm.dll和properties文件没放对,
文件javax.comm. properties拷贝到%JAVA_HOME%\jre\lib; 
文件win32comm.dll拷贝到%JAVA_HOME%\bin。
注意%JAVA_HOME%是jdk的路径,而非jre。

热点排行