smilb的问题,求大神帮助

hszhihtp 2017-05-21 01:25:19
做一个基于Java的短信通信平台,控制台报错如下,导的包如下
代码如下:
package util;

//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.
import org.apache.log4j.Logger;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

public class SendMessage2 {
public void doIt() 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());
/*
* modem.com1:网关ID(即短信猫端口编号)
* COM4:串口名称(在window中以COMXX表示端口名称,在linux,unix平台下以ttyS0
* -N或ttyUSB0-N表示端口名称),通过端口检测程序得到可用的端口
* 115200:串口每秒发送数据的bit位数,必须设置正确才可以正常发送短信,可通过程序进行检测。常用的有115200、9600
* Huawei
* :短信猫生产厂商,不同的短信猫生产厂商smslib所封装的AT指令接口会不一致,必须设置正确.常见的有Huawei、wavecom等厂商
* 最后一个参数表示设备的型号,可选
*/
SerialModemGateway gateway = new SerialModemGateway("modem.com1",
"COM4", 9600, "Huawei", "GTM900B");
gateway.setInbound(true); // 设置true,表示该网关可以接收短信,根据需求修改
gateway.setOutbound(true);// 设置true,表示该网关可以发送短信,根据需求修改
gateway.setSimPin("0000");// sim卡锁,一般默认为0000或1234
// Explicit SMSC address set is required for some modems.
// Below is for VODAFONE GREECE - be sure to set your own!
gateway.setSmscNumber("+306942190000");// 短信服务中心号码
Service.getInstance().setOutboundMessageNotification(
outboundNotification); // 发送短信成功后的回调函方法
Service.getInstance().addGateway(gateway); // 将网关添加到短信猫服务中
Service.getInstance().S.SERIAL_POLLING = true;
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 = new OutboundMessage("18363999256",
"Hello from SMSLib!"); // 参数1:手机号码 参数2:短信内容
Service.getInstance().sendMessage(msg); // 执行发送短信
System.out.println(msg);
// Or, send out a WAP SI message.
// OutboundWapSIMessage wapMsg = new
// OutboundWapSIMessage("306974000000",
// new URL("http://www.smslib.org/"), "Visit SMSLib now!");
// Service.getInstance().sendMessage(wapMsg);
// System.out.println(wapMsg);
// You can also queue some asynchronous messages to see how the
// callbacks
// are called...
// msg = new OutboundMessage("309999999999", "Wrong number!");
// srv.queueMessage(msg, gateway.getGatewayId());
// msg = new OutboundMessage("308888888888", "Wrong number!");
// srv.queueMessage(msg, gateway.getGatewayId());
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
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);
}
}

public static void main(String args[]) {
SendMessage2 app = new SendMessage2();
try {
app.doIt();
} catch (Exception e) {
e.printStackTrace();
}
}
}
...全文
174 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧