日期:2014-05-17 浏览次数:20768 次
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)