当前位置: 首页 > 工具软件 > SMSLib > 使用案例 >

java smslib,smslib短信猫发短信解决办法

顾恺
2023-12-01

Java codeimport 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 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();

}

}

}

 类似资料: