具体的操作步骤如下:
1、把smslib-3.3.0b2.jar、comm.jar与log4j-1.2.11.jar,放入到工程的lib中;
2、把javax.comm.properties放到%java_home%/jre/lib下;
3、把win32com.dll放到%java_home%/jre/bin下;
4 把comm.jar放到%java_home%/jre/ext下
注意:路径放错,调用起来就会报错;jdk的版本,用的版本是jdk-1_5_0_04。
public class sendmessage {
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);
}
}
@suppresswarnings("deprecation")
public void sendsms(string mobilephones, string content) {
service srv;
outboundmessage msg;
outboundnotification outboundnotification = new outboundnotification();
srv = new service();
serialmodemgateway gateway = new serialmodemgateway("modem.com3",
"com3", 9600, "wavecom", ""); //设置端口与波特率
gateway.setinbound(true);
gateway.setoutbound(true);
gateway.setsimpin("0000");
gateway.setoutboundnotification(outboundnotification);
srv.addgateway(gateway);
system.out.println("初始化成功,准备开启服务");
try {
srv.startservice();
system.out.println("服务启动成功");
string[] phones = mobilephones.split(",");
for (int i = 0; i < phones.length; i++) {
msg = new outboundmessage(phones[i], content);
msg.setencoding(messageencodings.encucs2); // 中文
srv.sendmessage(msg);
}
srv.stopservice();
} catch (exception e) {
e.printstacktrace();
}
}
public static void main(string[] args) {
sendmessage sendmessage = new sendmessage();
sendmessage.sendsms("您要发送的手机号", "您要发送的内容!");
}
}
如对本文有疑问, 点击进行留言回复!!
《Java后端知识体系》系列之看完这篇你就懂了Dubbo为何物?它要干什么?
网友评论