硬件是短信猫一个,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
------解决方案--------------------
不懂..关注..
------解决方案--------------------
------解决方案--------------------