// SendMessage.java - Sample application. // // This application shows you the basic procedure for sending messages. // You will find how to send synchronous and asynchronous messages. // // For asynchronous dispatch, the example application sets a callback // notification, to see what's happened with messages. package examples.modem;
import org.smslib.*; import org.smslib.modem.*;
public class SendMessage { public void doIt() throws Exception { Service srv; OutboundMessage msg;
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Example: Send message from a serial gsm modem."); System.out.println(Library.getLibraryDescription()); System.out.println("Version: " + Library.getLibraryVersion());
srv = new Service(); SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 9600, "SIEMENS", "TC35"); gateway.setInbound(true); gateway.setOutbound(true); gateway.setSimPin("0000"); gateway.setOutboundNotification(outboundNotification); srv.addGateway(gateway);
// Send a message synchronously.支持长短信 msg = new OutboundMessage("13798361236", "消息称,这一系列户籍管理制度改革措施,集中解决了三线艰苦地区和部分特殊行业干部职工长期两地分居问题,实行了农民自理口粮进入集镇落户,改革了暂住人口登记管理办法,启动并全面推进了小城镇户籍管理制度改革;调整了大中城市和西部地区的户口迁移政策,强化了农村户口城市化管理。同时,按照“公平对待,搞好服务,合理引导,完善管理”的原则,不断强化流动人口治安管理、权益保护和服务工作。这改变了长期以来颁发场所治安许可证和特种行业许可证的工作模式,把管理的重点从事前审批调整为事中监督和事后查处并重"); msg.setEncoding(MessageEncodings.ENCUCS2); srv.sendMessage(msg); System.out.println(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); } }