硬件是短信猫一个,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下,具体代码如下:
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();
}
}
}报如下错误: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)
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();
}
}
}报如下错误: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)
解决方案 »
- 点击查询按钮,如何清掉输入框的查询内容.
- 这样的功能怎么实现?
- tomcat&iis整合之后,上传附件出错
- 高手请帮忙,Http请求的post方法出现异常
- 如何返回一个inputstream???跟BLOB字段有关!!
- JSP中如何将request对象传到bean中
- javascript的问题。
- 急!!在线等待:在页面中怎样调用google或yahoo的搜索引擎??
- tomcat浏览权限设置问题!!!
- 代码优化 运行时间太长 求指出问题!
- ʹ��jeecms����վǰ̨���������������ϴ�struts2 Action��������ȡ�ϴ��ļ�
- 求助。。Hibernate 3.3.2 与3.5有什么区别,对于学习和工作影响大吗
短信猫便宜点 的 几百块, 贵一点的 几千都有, 配置在网站服务器上即可用, 猫只是一个 GSM Modem , 具体还是要通过移动来发送, 里面需要插入 sim 卡。 成本跟你手机发送短信一样。 发送成功在返回对象中有个 send ,为 true 则表示成功, false 则表示失败。
楼主 , 你的问题解决没? 我已经也遇到过这样的问题。
这个貌似和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 这个包试试。
在用里面的ReadMessages的例子时,运行到this.srv = new Service();时就跳过去了,我跟踪了一下,SRV没有创建成功,
请客各位高手是为什么?代码如下: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 , 没有出现那样的问题了。
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)
在你的 工程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!!
文件javax.comm. properties拷贝到%JAVA_HOME%\jre\lib;
文件win32comm.dll拷贝到%JAVA_HOME%\bin。
注意%JAVA_HOME%是jdk的路径,而非jre。
2010-2-8 10:51:15 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Digest-Algorithms.
Ensure that the manifest does not have duplicate entries, and
that blank lines separate individual sections in both your
manifest and in the META-INF/MANIFEST.MF entry in the jar file.
但可以成功发送短信
如果消除这些东西呢?
2010-2-8 10:51:15 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Digest-Algorithms.
Ensure that the manifest does not have duplicate entries, and
that blank lines separate individual sections in both your
manifest and in the META-INF/MANIFEST.MF entry in the jar file.
但可以成功发送短信
如果消除这些东西呢?
另外,在CDM命令窗口中,java -jar ***.jar运行可以运行,也出现了很多类如以上的警告,但双击则无没办法运行,郁闷,继续研究中。。
千万分感谢我的QQ号码是317144444
初始化成功,准备开启服务
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:92)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:110)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:126)
at org.smslib.Service$1Starter.run(Service.java:222)
发送完毕!!楼主还能帮忙看看什么问题啊?