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

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

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值