81,094
社区成员
发帖
与我相关
我的任务
分享
package cn.springmvc.tools;
import java.util.List;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.Message.MessageEncodings;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
public class sms
{
public void doIt(String tixing,List<String> list) throws Exception
{
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());
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM3", 9600, "wavecom", "");
gateway.setInbound(false); //设置true,表示该网关可以接收短信,根据需求修改
gateway.setOutbound(true);//设置true,表示该网关可以发送短信,根据需求修改
gateway.setSimPin("0000");//sim卡锁,一般默认为0000或1234
gateway.setSmscNumber("+8613000531500");//短信服务中心号码
Service.getInstance().setOutboundMessageNotification(outboundNotification); //发送短信成功后的回调函方法
Service.getInstance().addGateway(gateway); //将网关添加到短信猫服务中
Service.getInstance().startService(); //启动服务,进入短信发送就绪状态
System.out.println();
//打印设备信息
System.out.println("Modem Information:");
System.out.println(" Manufacturer: " + gateway.getManufacturer());
System.out.println(" Model: " + gateway.getModel());
System.out.println(" Serial No: " + gateway.getSerialNo());
System.out.println(" SIM IMSI: " + gateway.getImsi());
System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
// Send a message synchronously.
OutboundMessage msg=null;
for (int i = 0; i < list.size(); i++) {
msg = new OutboundMessage("+86"+list.get(i),tixing); //参数1:手机号码 参数2:短信内容
msg.setEncoding(MessageEncodings.ENCUCS2);
Service.getInstance().sendMessage(msg);
}
System.out.println(msg);
gateway.stopGateway();
Service.getInstance().removeGateway(gateway);
Service.getInstance().stopService();
}
/*
短信发送成功后,调用该接口。并将发送短信的网关和短信内容对象传给process接口
*/
public class OutboundNotification implements IOutboundMessageNotification
{
public void process(AGateway gateway, OutboundMessage msg)
{
System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
System.out.println(msg);
}
}
}